Skip to content

Commit

Permalink
Merge pull request #4 from madrisan/linter
Browse files Browse the repository at this point in the history
ci: add linter to GitHub Workflows
  • Loading branch information
madrisan authored Oct 4, 2023
2 parents a575900 + df12b16 commit f1ced55
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 272 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: lint
on: [push, pull_request]
jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install Python dependencies
run: pip install black flake8

- name: Run linters
uses: wearerequired/lint-action@v2
with:
auto_fix: false
black: true
flake8: false
74 changes: 49 additions & 25 deletions dynamic-systems-and-chaos/bifurcations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,63 @@
from lelib import Bifurcation, Map
from utils import argparser, die


def parse_args():
"""This function parses and return arguments passed in """
descr = 'Plot the Bifurcation Diagram of Logistic, Cubic, and Sine Maps'
examples = '''
"""This function parses and return arguments passed in"""
descr = "Plot the Bifurcation Diagram of Logistic, Cubic, and Sine Maps"
examples = """
%(prog)s -r 1:4
%(prog)s -r 4:6.5 --map=cubic
%(prog)s --map=sine -s 200 -n 200
%(prog)s -r 3.:4. -s 500 -n 600
%(prog)s -r 3.5:3.6 -y .3:.6 -s 800 -n 1000'''
%(prog)s -r 3.5:3.6 -y .3:.6 -s 800 -n 1000"""

parser = argparser(descr, examples)

# By default, make 300 iterations (n) and do no plot the first 200 ones (s)
# By default select the Logistic Equation

parser.add_argument(
"-r", "--rate",
action="store", dest="r",
help="range of the growth rate parameter (default: the entire range)")
"-r",
"--rate",
action="store",
dest="r",
help="range of the growth rate parameter (default: the entire range)",
)
parser.add_argument(
"-y", "--people",
action="store", dest="y",
help="normalized range of the population (default: the entire range)")
"-y",
"--people",
action="store",
dest="y",
help="normalized range of the population (default: the entire range)",
)
parser.add_argument(
"-s", "--skip",
action="store", dest="s", type=int, default=200,
help="skip plotting the first 's' iterations (default: %(default)s)")
"-s",
"--skip",
action="store",
dest="s",
type=int,
default=200,
help="skip plotting the first 's' iterations (default: %(default)s)",
)
parser.add_argument(
"-n", "--steps",
action="store", dest="n", type=int, default=100,
help="number of iterations (default: %(default)s)")
"-n",
"--steps",
action="store",
dest="n",
type=int,
default=100,
help="number of iterations (default: %(default)s)",
)
parser.add_argument(
"-m", "--map",
action="store", dest="map_name", default="logistic",
"-m",
"--map",
action="store",
dest="map_name",
default="logistic",
choices=["logistic", "cubic", "sine"],
help="select the desired map (logistic, cubic, or sine)")
help="select the desired map (logistic, cubic, or sine)",
)

return parser.parse_args()

Expand All @@ -54,23 +75,26 @@ def main():
mapobj = Map(args.map_name)

# range to vector: "1:4" --> [1., 4.]
r2v = (lambda a, minval, maxval :
[float(i) for i in a.split(':')] if a else
[minval, maxval])
r2v = (
lambda a, minval, maxval: [float(i) for i in a.split(":")]
if a
else [minval, maxval]
)

# Plot the entire diagram by default
Bifurcation(
r2v(args.r, mapobj.map_rmin, mapobj.map_rmax),
r2v(args.y, mapobj.map_ymin, mapobj.map_ymax),
args.n,
args.s,
args.map_name
args.map_name,
).plot()

if __name__ == '__main__':

if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
die(3, 'Exiting on user request')
die(3, "Exiting on user request")

sys.exit()
77 changes: 49 additions & 28 deletions dynamic-systems-and-chaos/finalstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from lelib import FinalState
from utils import argparser, die


def parse_args():
"""This function parses and return arguments passed in """
descr = 'Plot of the Final State Diagram'
examples = '''
"""This function parses and return arguments passed in"""
descr = "Plot of the Final State Diagram"
examples = """
%(prog)s -r 3.492
%(prog)s -r 3.614 -s 200 -n 300
%(prog)s -0 0.4 -r 3.2 -s 10 -n 50
%(prog)s -0 0.8 -r 6.2 -n 20 --map=cubic'''
%(prog)s -0 0.8 -r 6.2 -n 20 --map=cubic"""

parser = argparser(descr, examples)

Expand All @@ -25,44 +26,64 @@ def parse_args():
# By default select the Logistic Equation

parser.add_argument(
"-0", "--x0",
action="store", dest="x0", type=float, default=.5,
help="initial condition (default: %(default)s)")
"-0",
"--x0",
action="store",
dest="x0",
type=float,
default=0.5,
help="initial condition (default: %(default)s)",
)
parser.add_argument(
"-r", "--rate",
action="store", dest="r", type=float, required=True,
help="growth rate parameter")
"-r",
"--rate",
action="store",
dest="r",
type=float,
required=True,
help="growth rate parameter",
)
parser.add_argument(
"-s", "--skip",
action="store", dest="s", type=int, default=2000,
help="skip plotting the first 's' iterations (default: %(default)s)")
"-s",
"--skip",
action="store",
dest="s",
type=int,
default=2000,
help="skip plotting the first 's' iterations (default: %(default)s)",
)
parser.add_argument(
"-n", "--steps", dest="n", type=int, default=1000, action="store",
help="number of iterations (default: %(default)s)")
"-n",
"--steps",
dest="n",
type=int,
default=1000,
action="store",
help="number of iterations (default: %(default)s)",
)
parser.add_argument(
"-m", "--map",
action="store", dest="map_name", default = "logistic",
choices = ["logistic", "cubic", "sine"],
help = "select the desired map (logistic, cubic, or sine)")
"-m",
"--map",
action="store",
dest="map_name",
default="logistic",
choices=["logistic", "cubic", "sine"],
help="select the desired map (logistic, cubic, or sine)",
)

return parser.parse_args()


def main():
args = parse_args()

FinalState(
args.r,
args.n,
args.x0,
args.s,
args.map_name
).plot()
FinalState(args.r, args.n, args.x0, args.s, args.map_name).plot()


if __name__ == '__main__':
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
die(3, 'Exiting on user request')
die(3, "Exiting on user request")

sys.exit()
98 changes: 66 additions & 32 deletions dynamic-systems-and-chaos/legraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,105 @@
from lelib import Logistic, LogisticDiff
from utils import argparser, die


def parse_args():
"""This function parses and return arguments passed in """
descr = 'Plot of Logistic Equation Time Series'
examples = '''
"""This function parses and return arguments passed in"""
descr = "Plot of Logistic Equation Time Series"
examples = """
# time series with a stable fixed point
%(prog)s -0 0.4 -r 3.2 -n 50
%(prog)s -0 0.4 -1 0.45 -r 3.2 -n 50
# chaotic results (randon output)
%(prog)s --x0 0.2 --x1 0.2000001 -r 4.0 -n 50
%(prog)s -0 0.2 -r 3.6 -n 5000 --dots-only
%(prog)s -0 0.9 -r 4.5 -n 50 --map=cubic
%(prog)s -0 0.4 -r 0.8 -n 50 --map=sine'''
%(prog)s -0 0.4 -r 0.8 -n 50 --map=sine"""

parser = argparser(descr, examples)

# By default select the Logistic Equation

parser.add_argument(
"-0", "--x0",
action="store", dest="x0", type=float, required=True,
help="1st initial condition")
"-0",
"--x0",
action="store",
dest="x0",
type=float,
required=True,
help="1st initial condition",
)
parser.add_argument(
"-1", "--x1",
action="store", dest="x1", type=float,
help="2nd initial condition (optional)")
"-1",
"--x1",
action="store",
dest="x1",
type=float,
help="2nd initial condition (optional)",
)
parser.add_argument(
"-d", "--dots-only",
action="store_true", dest="dotsonly",
help="do not connect the dots with lines (default: %(default)s)")
"-d",
"--dots-only",
action="store_true",
dest="dotsonly",
help="do not connect the dots with lines (default: %(default)s)",
)
parser.add_argument(
"-r", "--rate",
action="store", dest="r", type=float, required=True,
help="growth rate parameter")
"-r",
"--rate",
action="store",
dest="r",
type=float,
required=True,
help="growth rate parameter",
)
parser.add_argument(
"-s", "--skip",
action="store", dest="s", type=int, default=0,
help="skip plotting the first 's' iterations")
"-s",
"--skip",
action="store",
dest="s",
type=int,
default=0,
help="skip plotting the first 's' iterations",
)
parser.add_argument(
"-n", "--steps",
action="store", dest="n", type=int, required=True,
help="number of iterations")
"-n",
"--steps",
action="store",
dest="n",
type=int,
required=True,
help="number of iterations",
)
parser.add_argument(
"-m", "--map",
action="store", dest="map_name", default="logistic",
choices = ["logistic", "cubic", "sine"],
help = "select the desired map (logistic, cubic, or sine)")
"-m",
"--map",
action="store",
dest="map_name",
default="logistic",
choices=["logistic", "cubic", "sine"],
help="select the desired map (logistic, cubic, or sine)",
)

return parser.parse_args()


def main():
args = parse_args()

lemap = (
LogisticDiff(
args.r, args.n, args.x0, args.x1, args.s, args.map_name)
if args.x1 else Logistic(
args.r, args.n, args.x0, args.s, args.map_name))
LogisticDiff(args.r, args.n, args.x0, args.x1, args.s, args.map_name)
if args.x1
else Logistic(args.r, args.n, args.x0, args.s, args.map_name)
)

lemap.plotdots = not args.dotsonly
lemap.plot()

if __name__ == '__main__':

if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
die(3, 'Exiting on user request')
die(3, "Exiting on user request")

sys.exit()
Loading

0 comments on commit f1ced55

Please sign in to comment.