Skip to content

Commit e38ab3a

Browse files
authored
Merge pull request #60 from alexfikl/ruff
Enable linting with ruff
2 parents 27d7177 + 86b4a94 commit e38ab3a

33 files changed

+474
-361
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ root = true
77
[*]
88
end_of_line = lf
99
insert_final_newline = true
10+
trim_trailing_whitespace = false
1011

1112
# Matches multiple files with brace expansion notation
1213
# Set default charset

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ concurrency:
1414
cancel-in-progress: true
1515

1616
jobs:
17+
typos:
18+
name: Spelling (typos)
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: crate-ci/typos@master
23+
24+
ruff:
25+
name: Linting (ruff)
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: chartboost/ruff-action@v1
30+
1731
test:
1832
name: Unittest (${{ matrix.os }}-${{ matrix.compiler }}-py${{ matrix.python-version }})
1933
runs-on: ${{ matrix.os }}

docs/conf.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,62 @@
1-
import sys
21
import os
2+
import sys
33
from unittest.mock import MagicMock as Mock
4+
45
from setuptools_scm import get_version
56

7+
68
MOCK_MODULES = [
7-
'numpy', 'numpy.testing', 'numpy.random',
8-
'scipy',
9-
'symengine', 'symengine.printing', 'symengine.lib.symengine_wrapper',
10-
'jitcxde_common.helpers','jitcxde_common.numerical','jitcxde_common.symbolic','jitcxde_common.transversal'
9+
"numpy", "numpy.testing", "numpy.random",
10+
"scipy",
11+
"symengine", "symengine.printing", "symengine.lib.symengine_wrapper",
12+
"jitcxde_common.helpers", "jitcxde_common.numerical", "jitcxde_common.symbolic", "jitcxde_common.transversal"
1113
]
1214
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
1315

14-
class GroupHandler_mock(object): pass
15-
sys.modules['jitcxde_common.transversal'] = Mock(GroupHandler=GroupHandler_mock)
16+
class GroupHandler_mock:
17+
pass
18+
19+
sys.modules["jitcxde_common.transversal"] = Mock(GroupHandler=GroupHandler_mock)
1620

1721
sys.path.insert(0,os.path.abspath("../examples"))
1822
sys.path.insert(0,os.path.abspath("../jitcdde"))
1923

20-
needs_sphinx = '1.3'
24+
needs_sphinx = "1.3"
2125

2226
extensions = [
23-
'sphinx.ext.autodoc',
24-
'sphinx.ext.autosummary',
25-
'sphinx.ext.mathjax',
26-
'numpydoc',
27+
"sphinx.ext.autodoc",
28+
"sphinx.ext.autosummary",
29+
"sphinx.ext.mathjax",
30+
"numpydoc",
2731
]
2832

29-
source_suffix = '.rst'
33+
source_suffix = ".rst"
3034

31-
master_doc = 'index'
35+
master_doc = "index"
3236

33-
project = u'JiTCDDE'
34-
copyright = u'2016, Gerrit Ansmann'
37+
project = "JiTCDDE"
38+
copyright = "2016, Gerrit Ansmann"
3539

36-
release = version = get_version(root='..', relative_to=__file__)
40+
release = version = get_version(root="..", relative_to=__file__)
3741

3842
default_role = "any"
3943

4044
add_function_parentheses = True
4145

4246
add_module_names = False
4347

44-
html_theme = 'nature'
45-
pygments_style = 'colorful'
46-
htmlhelp_basename = 'JiTCDDEdoc'
48+
html_theme = "nature"
49+
pygments_style = "colorful"
50+
htmlhelp_basename = "JiTCDDEdoc"
4751

4852
numpydoc_show_class_members = False
49-
autodoc_member_order = 'bysource'
53+
autodoc_member_order = "bysource"
5054

5155
def on_missing_reference(app, env, node, contnode):
52-
if node['reftype'] == 'any':
56+
if node["reftype"] == "any":
5357
return contnode
5458
else:
5559
return None
5660

5761
def setup(app):
58-
app.connect('missing-reference', on_missing_reference)
62+
app.connect("missing-reference", on_missing_reference)

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ After every successful integration step, the state and derivative of the integra
4747
Whenever the derivative :math:`(f)` is evaluated, the required past states :math:`\left ( y(t-τ_1), y(t-τ_2), … \right )` are obtained through piece-wise cubic `Hermite interpolation <http://en.wikipedia.org/wiki/Hermite_interpolation>`_, using previously stored pairs of state and derivative (“anchor”).
4848
In some extreme cases, they may also be extrapolated.
4949

50-
Note that unlike most other DDE softwares, JiTCDDE stores and accesses the initial past in exactly this way, i.e., as anchor points.
50+
Note that unlike most other DDE software, JiTCDDE stores and accesses the initial past in exactly this way, i.e., as anchor points.
5151
Thus, if you want to have maximum control, you have to initiate the past in exactly this way, i.e., you have to give at least two such anchor points (via `add_past_point`).
5252
If you do not want or need this, there are utility function available that automatically determine the anchors from a given function (`past_from_function`) or just set it to a fixed value (`constant_past`).
5353
You can also use the `get_state` method to obtain a representation of the past that you can dissect and modify using `CubicHermiteSpline <https://chspy.readthedocs.io/en/latest/>`_.
@@ -78,7 +78,7 @@ To make this happen, you have four options:
7878

7979
* `integrate_blindly` integrates the system for some time with a fixed step size, ignoring the error estimate. You have to take care that all parameters are reasonable. This is a good choice if you have a lot of different delays or time- or state-dependent delays. The time you integrate with this should be larger than your largest delay.
8080

81-
* Carefully choose the initial past such that the derivative for the last anchor is identical to the value of :math:`f` as determined with the anchors, i.e., there is no initial discontinuity to begin with. To find such initial conditions, you usally have to solve a non-linear equation system. This is the ideal case for short integrations as elaborated in the next subsection.
81+
* Carefully choose the initial past such that the derivative for the last anchor is identical to the value of :math:`f` as determined with the anchors, i.e., there is no initial discontinuity to begin with. To find such initial conditions, you usually have to solve a non-linear equation system. This is the ideal case for short integrations as elaborated in the next subsection.
8282

8383

8484
.. _short_integrations:
@@ -173,7 +173,7 @@ Calculating Lyapunov exponents with `jitcdde_lyap`
173173
It works just like `jitcdde`, except that it generates and integrates additional differential equations for the separation functions.
174174
After every call of `integrate`, the separation functions are orthonormalised, and the “local” Lyapunov exponents for this integration step are returned alongside with the system’s state.
175175
These can then be further processed to obtain the Lyapunov exponents.
176-
The separation functions are intialised with random data, and you have to take care of the preiterations that the separation functions require to align themselves.
176+
The separation functions are initialised with random data, and you have to take care of the preiterations that the separation functions require to align themselves.
177177

178178
The method employed here is similar to Farmer’s [F82]_, which in turn is an adaption of the method described by Benettin et al. [BGGS80]_ to delayed systems.
179179
As the state of delayed systems is also defined by their recent past, one has to consider the past of tangent vectors (as used in Benettin et. al.) as well, which are called separation functions.

examples/data_input.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import numpy as np
2-
from jitcdde import y, t, jitcdde_input, input
3-
from chspy import CubicHermiteSpline
42
from matplotlib import pyplot as plt
53

4+
from chspy import CubicHermiteSpline
5+
6+
from jitcdde import input, jitcdde_input, t, y # noqa: A004
7+
8+
9+
rng = np.random.default_rng()
10+
611
# Defining Input
712
# --------------
813

@@ -11,7 +16,7 @@
1116
input_times = np.linspace(0, 70, 20)
1217
max_time = input_times[-1]
1318

14-
input_data = np.random.normal(size=(20,2))
19+
input_data = rng.normal(size=(20,2))
1520
input_spline = CubicHermiteSpline.from_data(input_times,input_data)
1621

1722
fig,axes = plt.subplots()

examples/kuramoto_network.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python3
2-
# -*- coding: utf-8 -*-
32

43
"""
54
Suppose, we want to implement a network of :math:`n=100` delay-coupled Kuramoto oscillators, governed by the following differential equations:
@@ -35,16 +34,19 @@
3534

3635
if __name__ == "__main__":
3736
# example-start
38-
from jitcdde import jitcdde, y, t
39-
from numpy import pi, arange, random, max
37+
import numpy as np
4038
from symengine import sin
39+
40+
from jitcdde import jitcdde, t, y
4141

42+
43+
rng = np.random.default_rng()
4244
n = 100
4345
ω = 1
4446
c = 42
4547
q = 0.05
46-
A = random.choice( [1,0], size=(n,n), p=[q,1-q] )
47-
τ = random.uniform( pi/5, 2*pi, size=(n,n) )
48+
A = rng.choice( [1,0], size=(n,n), p=[q,1-q] )
49+
τ = rng.uniform( np.pi/5, 2*np.pi, size=(n,n) )
4850

4951
def kuramotos():
5052
for i in range(n):
@@ -54,11 +56,11 @@ def kuramotos():
5456
if A[j,i]
5557
)
5658

57-
I = jitcdde(kuramotos,n=n,verbose=False,delays=τ.flatten())
58-
I.set_integration_parameters(rtol=0,atol=1e-5)
59+
solver = jitcdde(kuramotos,n=n,verbose=False,delays=τ.flatten())
60+
solver.set_integration_parameters(rtol=0,atol=1e-5)
5961

60-
I.constant_past( random.uniform(0,2*pi,n), time=0.0 )
61-
I.integrate_blindly( max(τ) , 0.1 )
62+
solver.constant_past( rng.uniform(0,2*np.pi,n), time=0.0 )
63+
solver.integrate_blindly( np.max(τ) , 0.1 )
6264

63-
for time in I.t + arange(0,400,0.2):
64-
print(*I.integrate(time) % (2*pi))
65+
for time in solver.t + np.arange(0,400,0.2):
66+
print(*solver.integrate(time) % (2*np.pi))

examples/laminar_chaos.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
This is an example implementing laminar chaos as discovered by: https://doi.org/10.1103/PhysRevLett.120.084102
33
"""
44

5-
from jitcdde import t, y, jitcdde
6-
from symengine import sin
75
import numpy as np
6+
from symengine import sin
7+
8+
from jitcdde import jitcdde, t, y
9+
810

911
T = 200
1012
A = 0.9/2/np.pi

examples/mackey_glass.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/python3
2-
# -*- coding: utf-8 -*-
32

43
"""
5-
Suppose we want to integrate the Mackey–Glass delay differential equation: :math:`\\dot{y} = f(y)` with :math:`y∈ℝ`,
4+
Suppose we want to integrate the Mackey–Glass delay differential equation: :math:`\\dot{y} = f(y)` with :math:`y∈ℝ`,
65
76
.. math::
87
@@ -17,7 +16,7 @@
1716
1817
Amongst our imports were the symbols for the state (`y`) and time (`t`), which have to be used to write down the differential equation such that JiTCDDE can process it.
1918
Using them, we can write down the right-hand side of the differential equation as a list of expressions.
20-
As it is one-dimensional, the list contains only one element.
19+
As it is one-dimensional, the list contains only one element.
2120
We can then initiate JiTCDDE:
2221
2322
.. literalinclude:: ../examples/mackey_glass.py
@@ -57,8 +56,9 @@
5756

5857

5958
if __name__ == "__main__":
60-
from jitcdde import jitcdde, y, t
6159
import numpy
60+
61+
from jitcdde import jitcdde, t, y
6262

6363
τ = 15
6464
n = 10

examples/mackey_glass_jump.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/python3
2-
# -*- coding: utf-8 -*-
32

43
"""
54
This is a very simple example implementing the Mackey–Glass system with an additional jump.
65
See https://github.com/neurophysik/jitcdde/issues/23 for details.
76
"""
87

9-
from jitcdde import jitcdde, y, t
108
import numpy
119

10+
from jitcdde import jitcdde, t, y
11+
12+
1213
τ = 15
1314
n = 10
1415
β = 0.25

examples/mackey_glass_lyap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python3
2-
# -*- coding: utf-8 -*-
32

43
"""
54
For instance, we can calculate and print the Lyapunov exponents for the Mackey–Glass system as follows (central changes to the example from `example` highlighted):
@@ -14,9 +13,10 @@
1413
"""
1514

1615
if __name__ == "__main__":
17-
from jitcdde import jitcdde_lyap, y, t
1816
import numpy
1917
from scipy.stats import sem
18+
19+
from jitcdde import jitcdde_lyap, t, y
2020

2121
τ = 15
2222
n = 10
@@ -46,4 +46,4 @@
4646
for i in range(n_lyap):
4747
Lyap = numpy.average(lyaps[400:,i], weights=weights[400:])
4848
stderr = sem(lyaps[400:,i]) # Note that this only an estimate
49-
print("%i. Lyapunov exponent: % .4f +/- %.4f" % (i+1,Lyap,stderr))
49+
print(f"{i+1}. Lyapunov exponent: {Lyap:.4f} +/- {stderr:.4f}")

0 commit comments

Comments
 (0)