gotranx 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gotranx-0.1.0/PKG-INFO +276 -0
- gotranx-0.1.0/README.md +234 -0
- gotranx-0.1.0/pyproject.toml +154 -0
- gotranx-0.1.0/setup.cfg +4 -0
- gotranx-0.1.0/src/gotranx/__init__.py +51 -0
- gotranx-0.1.0/src/gotranx/__main__.py +4 -0
- gotranx-0.1.0/src/gotranx/atoms.py +215 -0
- gotranx-0.1.0/src/gotranx/cellml/__init__.py +23 -0
- gotranx-0.1.0/src/gotranx/cellml/cellml.py +1709 -0
- gotranx-0.1.0/src/gotranx/cellml/mathml.py +341 -0
- gotranx-0.1.0/src/gotranx/cli/__init__.py +94 -0
- gotranx-0.1.0/src/gotranx/cli/cellml2ode.py +20 -0
- gotranx-0.1.0/src/gotranx/cli/gotran2c.py +34 -0
- gotranx-0.1.0/src/gotranx/cli/gotran2py.py +39 -0
- gotranx-0.1.0/src/gotranx/codecomponent.py +44 -0
- gotranx-0.1.0/src/gotranx/codegen/__init__.py +18 -0
- gotranx-0.1.0/src/gotranx/codegen/base.py +289 -0
- gotranx-0.1.0/src/gotranx/codegen/c.py +102 -0
- gotranx-0.1.0/src/gotranx/codegen/python.py +130 -0
- gotranx-0.1.0/src/gotranx/exceptions.py +80 -0
- gotranx-0.1.0/src/gotranx/expressions.py +137 -0
- gotranx-0.1.0/src/gotranx/load.py +36 -0
- gotranx-0.1.0/src/gotranx/ode.lark +122 -0
- gotranx-0.1.0/src/gotranx/ode.py +300 -0
- gotranx-0.1.0/src/gotranx/ode_component.py +160 -0
- gotranx-0.1.0/src/gotranx/parser.py +17 -0
- gotranx-0.1.0/src/gotranx/save.py +138 -0
- gotranx-0.1.0/src/gotranx/schemes.py +175 -0
- gotranx-0.1.0/src/gotranx/sympytools.py +98 -0
- gotranx-0.1.0/src/gotranx/templates/__init__.py +42 -0
- gotranx-0.1.0/src/gotranx/templates/c.py +62 -0
- gotranx-0.1.0/src/gotranx/templates/python.py +139 -0
- gotranx-0.1.0/src/gotranx/transformer.py +212 -0
- gotranx-0.1.0/src/gotranx/units.py +3 -0
- gotranx-0.1.0/src/gotranx.egg-info/PKG-INFO +276 -0
- gotranx-0.1.0/src/gotranx.egg-info/SOURCES.txt +54 -0
- gotranx-0.1.0/src/gotranx.egg-info/dependency_links.txt +1 -0
- gotranx-0.1.0/src/gotranx.egg-info/entry_points.txt +2 -0
- gotranx-0.1.0/src/gotranx.egg-info/not-zip-safe +1 -0
- gotranx-0.1.0/src/gotranx.egg-info/requires.txt +30 -0
- gotranx-0.1.0/src/gotranx.egg-info/top_level.txt +1 -0
- gotranx-0.1.0/tests/test_atoms.py +172 -0
- gotranx-0.1.0/tests/test_c_codegen.py +195 -0
- gotranx-0.1.0/tests/test_cellml.py +20 -0
- gotranx-0.1.0/tests/test_cli.py +75 -0
- gotranx-0.1.0/tests/test_expressions.py +99 -0
- gotranx-0.1.0/tests/test_load.py +62 -0
- gotranx-0.1.0/tests/test_ode.py +143 -0
- gotranx-0.1.0/tests/test_ode_component.py +193 -0
- gotranx-0.1.0/tests/test_python_codegen.py +295 -0
- gotranx-0.1.0/tests/test_save.py +65 -0
- gotranx-0.1.0/tests/test_schemes.py +68 -0
- gotranx-0.1.0/tests/test_sympytools.py +78 -0
- gotranx-0.1.0/tests/test_transformer_assignments.py +523 -0
- gotranx-0.1.0/tests/test_transformer_parameters.py +141 -0
- gotranx-0.1.0/tests/test_transformer_states.py +185 -0
gotranx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gotranx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sync local directories with dropbox
|
|
5
|
+
Author-email: Henrik Finsberg <henriknf@simula.no>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/finsberg/gotranx
|
|
8
|
+
Keywords: parser,lark,gotran,ode
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: attrs
|
|
18
|
+
Requires-Dist: clang-format-docs
|
|
19
|
+
Requires-Dist: black
|
|
20
|
+
Requires-Dist: lark
|
|
21
|
+
Requires-Dist: pint
|
|
22
|
+
Requires-Dist: rich-click
|
|
23
|
+
Requires-Dist: structlog
|
|
24
|
+
Requires-Dist: sympy
|
|
25
|
+
Requires-Dist: typer
|
|
26
|
+
Requires-Dist: graphlib-backport; python_version < "3.9"
|
|
27
|
+
Requires-Dist: typing_extensions; python_version < "3.9"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: bump-my-version; extra == "dev"
|
|
30
|
+
Requires-Dist: ipython; extra == "dev"
|
|
31
|
+
Requires-Dist: pdbpp; extra == "dev"
|
|
32
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
33
|
+
Requires-Dist: twine; extra == "dev"
|
|
34
|
+
Requires-Dist: wheel; extra == "dev"
|
|
35
|
+
Provides-Extra: docs
|
|
36
|
+
Requires-Dist: mkdocs; extra == "docs"
|
|
37
|
+
Requires-Dist: mkdocs-material; extra == "docs"
|
|
38
|
+
Provides-Extra: test
|
|
39
|
+
Requires-Dist: pre-commit; extra == "test"
|
|
40
|
+
Requires-Dist: pytest; extra == "test"
|
|
41
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
42
|
+
|
|
43
|
+
[](https://github.com/finsberg/gotranx/actions/workflows/pre-commit.yml)
|
|
44
|
+
[](https://github.com/finsberg/gotranx/actions/workflows/main.yml)
|
|
45
|
+
[](https://finsberg.github.io/gotranx)
|
|
46
|
+
[](https://opensource.org/licenses/MIT)
|
|
47
|
+
[](https://github.com/psf/black)
|
|
48
|
+
# gotranx
|
|
49
|
+
|
|
50
|
+
`gotranx` is the next generation General ODE translator and is an attempt to a full rewrite of [gotran](https://github.com/ComputationalPhysiology/gotran).
|
|
51
|
+
|
|
52
|
+
The general idea is that you write your ODE in a high level markup language and use `gotranx` to generate code for solving the ODE in different programming languages.
|
|
53
|
+
|
|
54
|
+
`gotranx` uses [`sympy`](https://www.sympy.org/en/index.html) to generate the numerical schemes.
|
|
55
|
+
|
|
56
|
+
**Note: `gotranx` is still under active development, so do not expect it to be complete.**
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
Install with pip
|
|
60
|
+
```
|
|
61
|
+
python3 -m pip install gotranx
|
|
62
|
+
```
|
|
63
|
+
or for the development version
|
|
64
|
+
```
|
|
65
|
+
python3 -m pip install git+https://github.com/finsberg/gotranx
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
Define you ode in an `.ode` file, for example for the Lorentz attractor you can write the following file (called `lorentz.ode`)
|
|
70
|
+
```
|
|
71
|
+
parameters(
|
|
72
|
+
sigma=12.0,
|
|
73
|
+
rho=21.0,
|
|
74
|
+
beta=2.4
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
states(x=1.0, y=2.0,z=3.05)
|
|
78
|
+
|
|
79
|
+
dx_dt = sigma * (y - x)
|
|
80
|
+
dy_dt = x * (rho - z) - y
|
|
81
|
+
dz_dt = x * y - beta * z
|
|
82
|
+
```
|
|
83
|
+
which defines the parameters and states with default initial conditions. For each state-variable we also define the derivatives using `dx_dt` for the state with name `x`.
|
|
84
|
+
|
|
85
|
+
Now we can generate code that can be used to solve the equation, e.g
|
|
86
|
+
```
|
|
87
|
+
python3 -m gotranx lorentz.ode --to .py --scheme forward_explicit_euler
|
|
88
|
+
```
|
|
89
|
+
which will generate a python file `lorentz.py` containing the following functions
|
|
90
|
+
```python
|
|
91
|
+
import numpy
|
|
92
|
+
|
|
93
|
+
def parameter_index(name: str) -> float:
|
|
94
|
+
"""Return the index of the parameter with the given name
|
|
95
|
+
|
|
96
|
+
Arguments
|
|
97
|
+
---------
|
|
98
|
+
name : str
|
|
99
|
+
The name of the parameter
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
103
|
+
float
|
|
104
|
+
The index of the parameter
|
|
105
|
+
|
|
106
|
+
Raises
|
|
107
|
+
------
|
|
108
|
+
KeyError
|
|
109
|
+
If the name is not a valid parameter
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
data = {"beta": 0, "rho": 1, "sigma": 2}
|
|
113
|
+
return data[name]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def state_index(name: str) -> float:
|
|
117
|
+
"""Return the index of the state with the given name
|
|
118
|
+
|
|
119
|
+
Arguments
|
|
120
|
+
---------
|
|
121
|
+
name : str
|
|
122
|
+
The name of the state
|
|
123
|
+
|
|
124
|
+
Returns
|
|
125
|
+
-------
|
|
126
|
+
float
|
|
127
|
+
The index of the state
|
|
128
|
+
|
|
129
|
+
Raises
|
|
130
|
+
------
|
|
131
|
+
KeyError
|
|
132
|
+
If the name is not a valid state
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
data = {"x": 0, "y": 1, "z": 2}
|
|
136
|
+
return data[name]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def init_parameter_values(**values):
|
|
140
|
+
"""Initialize parameter values"""
|
|
141
|
+
# beta=2.4, rho=21.0, sigma=12.0
|
|
142
|
+
|
|
143
|
+
parameters = numpy.array([2.4, 21.0, 12.0])
|
|
144
|
+
|
|
145
|
+
for key, value in values.items():
|
|
146
|
+
parameters[parameter_index(key)] = value
|
|
147
|
+
|
|
148
|
+
return parameters
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def init_state_values(**values):
|
|
152
|
+
"""Initialize state values"""
|
|
153
|
+
# x=1.0, y=2.0, z=3.05
|
|
154
|
+
|
|
155
|
+
states = numpy.array([1.0, 2.0, 3.05])
|
|
156
|
+
|
|
157
|
+
for key, value in values.items():
|
|
158
|
+
states[state_index(key)] = value
|
|
159
|
+
|
|
160
|
+
return states
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def rhs(t, states, parameters):
|
|
164
|
+
# Assign states
|
|
165
|
+
x = states[0]
|
|
166
|
+
y = states[1]
|
|
167
|
+
z = states[2]
|
|
168
|
+
|
|
169
|
+
# Assign parameters
|
|
170
|
+
beta = parameters[0]
|
|
171
|
+
rho = parameters[1]
|
|
172
|
+
sigma = parameters[2]
|
|
173
|
+
|
|
174
|
+
# Assign expressions
|
|
175
|
+
values = numpy.zeros(3)
|
|
176
|
+
values[0] = sigma * (-x + y)
|
|
177
|
+
values[1] = x * (rho - z) - y
|
|
178
|
+
values[2] = -beta * z + x * y
|
|
179
|
+
|
|
180
|
+
return values
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def forward_explicit_euler(states, t, dt, parameters):
|
|
184
|
+
# Assign states
|
|
185
|
+
x = states[0]
|
|
186
|
+
y = states[1]
|
|
187
|
+
z = states[2]
|
|
188
|
+
|
|
189
|
+
# Assign parameters
|
|
190
|
+
beta = parameters[0]
|
|
191
|
+
rho = parameters[1]
|
|
192
|
+
sigma = parameters[2]
|
|
193
|
+
|
|
194
|
+
# Assign expressions
|
|
195
|
+
values = numpy.zeros(3)
|
|
196
|
+
dx_dt = sigma * (-x + y)
|
|
197
|
+
values[0] = dt * dx_dt + x
|
|
198
|
+
dy_dt = x * (rho - z) - y
|
|
199
|
+
values[1] = dt * dy_dt + y
|
|
200
|
+
dz_dt = -beta * z + x * y
|
|
201
|
+
values[2] = dt * dz_dt + z
|
|
202
|
+
|
|
203
|
+
return values
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Similarly, you can use the following command
|
|
208
|
+
```
|
|
209
|
+
python3 -m gotranx lorentz.ode --to .h --scheme forward_explicit_euler
|
|
210
|
+
```
|
|
211
|
+
to generate a C-header file with the following content
|
|
212
|
+
```C
|
|
213
|
+
#include <math.h>
|
|
214
|
+
|
|
215
|
+
void init_parameter_values(double *parameters)
|
|
216
|
+
{
|
|
217
|
+
/*
|
|
218
|
+
beta=2.4, rho=21.0, sigma=12.0
|
|
219
|
+
*/
|
|
220
|
+
parameters[0] = 2.4;
|
|
221
|
+
parameters[1] = 21.0;
|
|
222
|
+
parameters[2] = 12.0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
void init_state_values(double *states)
|
|
226
|
+
{
|
|
227
|
+
/*
|
|
228
|
+
x=1.0, y=2.0, z=3.05
|
|
229
|
+
*/
|
|
230
|
+
states[0] = 1.0;
|
|
231
|
+
states[1] = 2.0;
|
|
232
|
+
states[2] = 3.05;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
void rhs(const double t, const double *__restrict states, const double *__restrict parameters, double *values)
|
|
236
|
+
{
|
|
237
|
+
|
|
238
|
+
// Assign states
|
|
239
|
+
const double x = states[0];
|
|
240
|
+
const double y = states[1];
|
|
241
|
+
const double z = states[2];
|
|
242
|
+
|
|
243
|
+
// Assign parameters
|
|
244
|
+
const double beta = parameters[0];
|
|
245
|
+
const double rho = parameters[1];
|
|
246
|
+
const double sigma = parameters[2];
|
|
247
|
+
|
|
248
|
+
// Assign expressions
|
|
249
|
+
values[0] = sigma * (-x + y);
|
|
250
|
+
values[1] = x * (rho - z) - y;
|
|
251
|
+
values[2] = -beta * z + x * y;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
void forward_explicit_euler(const double *__restrict states, const double t, const double dt,
|
|
255
|
+
const double *__restrict parameters, double *values)
|
|
256
|
+
{
|
|
257
|
+
|
|
258
|
+
// Assign states
|
|
259
|
+
const double x = states[0];
|
|
260
|
+
const double y = states[1];
|
|
261
|
+
const double z = states[2];
|
|
262
|
+
|
|
263
|
+
// Assign parameters
|
|
264
|
+
const double beta = parameters[0];
|
|
265
|
+
const double rho = parameters[1];
|
|
266
|
+
const double sigma = parameters[2];
|
|
267
|
+
|
|
268
|
+
// Assign expressions
|
|
269
|
+
const double dx_dt = sigma * (-x + y);
|
|
270
|
+
values[0] = dt * dx_dt + x;
|
|
271
|
+
const double dy_dt = x * (rho - z) - y;
|
|
272
|
+
values[1] = dt * dy_dt + y;
|
|
273
|
+
const double dz_dt = -beta * z + x * y;
|
|
274
|
+
values[2] = dt * dz_dt + z;
|
|
275
|
+
}
|
|
276
|
+
```
|
gotranx-0.1.0/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
[](https://github.com/finsberg/gotranx/actions/workflows/pre-commit.yml)
|
|
2
|
+
[](https://github.com/finsberg/gotranx/actions/workflows/main.yml)
|
|
3
|
+
[](https://finsberg.github.io/gotranx)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/psf/black)
|
|
6
|
+
# gotranx
|
|
7
|
+
|
|
8
|
+
`gotranx` is the next generation General ODE translator and is an attempt to a full rewrite of [gotran](https://github.com/ComputationalPhysiology/gotran).
|
|
9
|
+
|
|
10
|
+
The general idea is that you write your ODE in a high level markup language and use `gotranx` to generate code for solving the ODE in different programming languages.
|
|
11
|
+
|
|
12
|
+
`gotranx` uses [`sympy`](https://www.sympy.org/en/index.html) to generate the numerical schemes.
|
|
13
|
+
|
|
14
|
+
**Note: `gotranx` is still under active development, so do not expect it to be complete.**
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
Install with pip
|
|
18
|
+
```
|
|
19
|
+
python3 -m pip install gotranx
|
|
20
|
+
```
|
|
21
|
+
or for the development version
|
|
22
|
+
```
|
|
23
|
+
python3 -m pip install git+https://github.com/finsberg/gotranx
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
Define you ode in an `.ode` file, for example for the Lorentz attractor you can write the following file (called `lorentz.ode`)
|
|
28
|
+
```
|
|
29
|
+
parameters(
|
|
30
|
+
sigma=12.0,
|
|
31
|
+
rho=21.0,
|
|
32
|
+
beta=2.4
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
states(x=1.0, y=2.0,z=3.05)
|
|
36
|
+
|
|
37
|
+
dx_dt = sigma * (y - x)
|
|
38
|
+
dy_dt = x * (rho - z) - y
|
|
39
|
+
dz_dt = x * y - beta * z
|
|
40
|
+
```
|
|
41
|
+
which defines the parameters and states with default initial conditions. For each state-variable we also define the derivatives using `dx_dt` for the state with name `x`.
|
|
42
|
+
|
|
43
|
+
Now we can generate code that can be used to solve the equation, e.g
|
|
44
|
+
```
|
|
45
|
+
python3 -m gotranx lorentz.ode --to .py --scheme forward_explicit_euler
|
|
46
|
+
```
|
|
47
|
+
which will generate a python file `lorentz.py` containing the following functions
|
|
48
|
+
```python
|
|
49
|
+
import numpy
|
|
50
|
+
|
|
51
|
+
def parameter_index(name: str) -> float:
|
|
52
|
+
"""Return the index of the parameter with the given name
|
|
53
|
+
|
|
54
|
+
Arguments
|
|
55
|
+
---------
|
|
56
|
+
name : str
|
|
57
|
+
The name of the parameter
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
float
|
|
62
|
+
The index of the parameter
|
|
63
|
+
|
|
64
|
+
Raises
|
|
65
|
+
------
|
|
66
|
+
KeyError
|
|
67
|
+
If the name is not a valid parameter
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
data = {"beta": 0, "rho": 1, "sigma": 2}
|
|
71
|
+
return data[name]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def state_index(name: str) -> float:
|
|
75
|
+
"""Return the index of the state with the given name
|
|
76
|
+
|
|
77
|
+
Arguments
|
|
78
|
+
---------
|
|
79
|
+
name : str
|
|
80
|
+
The name of the state
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
-------
|
|
84
|
+
float
|
|
85
|
+
The index of the state
|
|
86
|
+
|
|
87
|
+
Raises
|
|
88
|
+
------
|
|
89
|
+
KeyError
|
|
90
|
+
If the name is not a valid state
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
data = {"x": 0, "y": 1, "z": 2}
|
|
94
|
+
return data[name]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def init_parameter_values(**values):
|
|
98
|
+
"""Initialize parameter values"""
|
|
99
|
+
# beta=2.4, rho=21.0, sigma=12.0
|
|
100
|
+
|
|
101
|
+
parameters = numpy.array([2.4, 21.0, 12.0])
|
|
102
|
+
|
|
103
|
+
for key, value in values.items():
|
|
104
|
+
parameters[parameter_index(key)] = value
|
|
105
|
+
|
|
106
|
+
return parameters
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def init_state_values(**values):
|
|
110
|
+
"""Initialize state values"""
|
|
111
|
+
# x=1.0, y=2.0, z=3.05
|
|
112
|
+
|
|
113
|
+
states = numpy.array([1.0, 2.0, 3.05])
|
|
114
|
+
|
|
115
|
+
for key, value in values.items():
|
|
116
|
+
states[state_index(key)] = value
|
|
117
|
+
|
|
118
|
+
return states
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def rhs(t, states, parameters):
|
|
122
|
+
# Assign states
|
|
123
|
+
x = states[0]
|
|
124
|
+
y = states[1]
|
|
125
|
+
z = states[2]
|
|
126
|
+
|
|
127
|
+
# Assign parameters
|
|
128
|
+
beta = parameters[0]
|
|
129
|
+
rho = parameters[1]
|
|
130
|
+
sigma = parameters[2]
|
|
131
|
+
|
|
132
|
+
# Assign expressions
|
|
133
|
+
values = numpy.zeros(3)
|
|
134
|
+
values[0] = sigma * (-x + y)
|
|
135
|
+
values[1] = x * (rho - z) - y
|
|
136
|
+
values[2] = -beta * z + x * y
|
|
137
|
+
|
|
138
|
+
return values
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def forward_explicit_euler(states, t, dt, parameters):
|
|
142
|
+
# Assign states
|
|
143
|
+
x = states[0]
|
|
144
|
+
y = states[1]
|
|
145
|
+
z = states[2]
|
|
146
|
+
|
|
147
|
+
# Assign parameters
|
|
148
|
+
beta = parameters[0]
|
|
149
|
+
rho = parameters[1]
|
|
150
|
+
sigma = parameters[2]
|
|
151
|
+
|
|
152
|
+
# Assign expressions
|
|
153
|
+
values = numpy.zeros(3)
|
|
154
|
+
dx_dt = sigma * (-x + y)
|
|
155
|
+
values[0] = dt * dx_dt + x
|
|
156
|
+
dy_dt = x * (rho - z) - y
|
|
157
|
+
values[1] = dt * dy_dt + y
|
|
158
|
+
dz_dt = -beta * z + x * y
|
|
159
|
+
values[2] = dt * dz_dt + z
|
|
160
|
+
|
|
161
|
+
return values
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Similarly, you can use the following command
|
|
166
|
+
```
|
|
167
|
+
python3 -m gotranx lorentz.ode --to .h --scheme forward_explicit_euler
|
|
168
|
+
```
|
|
169
|
+
to generate a C-header file with the following content
|
|
170
|
+
```C
|
|
171
|
+
#include <math.h>
|
|
172
|
+
|
|
173
|
+
void init_parameter_values(double *parameters)
|
|
174
|
+
{
|
|
175
|
+
/*
|
|
176
|
+
beta=2.4, rho=21.0, sigma=12.0
|
|
177
|
+
*/
|
|
178
|
+
parameters[0] = 2.4;
|
|
179
|
+
parameters[1] = 21.0;
|
|
180
|
+
parameters[2] = 12.0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void init_state_values(double *states)
|
|
184
|
+
{
|
|
185
|
+
/*
|
|
186
|
+
x=1.0, y=2.0, z=3.05
|
|
187
|
+
*/
|
|
188
|
+
states[0] = 1.0;
|
|
189
|
+
states[1] = 2.0;
|
|
190
|
+
states[2] = 3.05;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
void rhs(const double t, const double *__restrict states, const double *__restrict parameters, double *values)
|
|
194
|
+
{
|
|
195
|
+
|
|
196
|
+
// Assign states
|
|
197
|
+
const double x = states[0];
|
|
198
|
+
const double y = states[1];
|
|
199
|
+
const double z = states[2];
|
|
200
|
+
|
|
201
|
+
// Assign parameters
|
|
202
|
+
const double beta = parameters[0];
|
|
203
|
+
const double rho = parameters[1];
|
|
204
|
+
const double sigma = parameters[2];
|
|
205
|
+
|
|
206
|
+
// Assign expressions
|
|
207
|
+
values[0] = sigma * (-x + y);
|
|
208
|
+
values[1] = x * (rho - z) - y;
|
|
209
|
+
values[2] = -beta * z + x * y;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
void forward_explicit_euler(const double *__restrict states, const double t, const double dt,
|
|
213
|
+
const double *__restrict parameters, double *values)
|
|
214
|
+
{
|
|
215
|
+
|
|
216
|
+
// Assign states
|
|
217
|
+
const double x = states[0];
|
|
218
|
+
const double y = states[1];
|
|
219
|
+
const double z = states[2];
|
|
220
|
+
|
|
221
|
+
// Assign parameters
|
|
222
|
+
const double beta = parameters[0];
|
|
223
|
+
const double rho = parameters[1];
|
|
224
|
+
const double sigma = parameters[2];
|
|
225
|
+
|
|
226
|
+
// Assign expressions
|
|
227
|
+
const double dx_dt = sigma * (-x + y);
|
|
228
|
+
values[0] = dt * dx_dt + x;
|
|
229
|
+
const double dy_dt = x * (rho - z) - y;
|
|
230
|
+
values[1] = dt * dy_dt + y;
|
|
231
|
+
const double dz_dt = -beta * z + x * y;
|
|
232
|
+
values[2] = dt * dz_dt + z;
|
|
233
|
+
}
|
|
234
|
+
```
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.2"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gotranx"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Sync local directories with dropbox"
|
|
9
|
+
authors = [{name = "Henrik Finsberg", email = "henriknf@simula.no"}]
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
classifiers = [
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.8",
|
|
16
|
+
"Programming Language :: Python :: 3.9",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
]
|
|
19
|
+
keywords = ["parser", "lark", "gotran", "ode"]
|
|
20
|
+
urls = {Homepage = "https://github.com/finsberg/gotranx"}
|
|
21
|
+
requires-python = ">=3.8"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"attrs",
|
|
24
|
+
"clang-format-docs",
|
|
25
|
+
"black",
|
|
26
|
+
"lark",
|
|
27
|
+
"pint",
|
|
28
|
+
"rich-click",
|
|
29
|
+
"structlog",
|
|
30
|
+
"sympy",
|
|
31
|
+
"typer",
|
|
32
|
+
'graphlib-backport;python_version < "3.9"',
|
|
33
|
+
'typing_extensions;python_version < "3.9"',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.readme]
|
|
37
|
+
file = "README.md"
|
|
38
|
+
content-type = "text/markdown"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = [
|
|
42
|
+
"bump-my-version",
|
|
43
|
+
"ipython",
|
|
44
|
+
"pdbpp",
|
|
45
|
+
"pre-commit",
|
|
46
|
+
"twine",
|
|
47
|
+
"wheel",
|
|
48
|
+
]
|
|
49
|
+
docs = [
|
|
50
|
+
"mkdocs",
|
|
51
|
+
"mkdocs-material",
|
|
52
|
+
]
|
|
53
|
+
test = [
|
|
54
|
+
"pre-commit",
|
|
55
|
+
"pytest",
|
|
56
|
+
"pytest-cov",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[project.scripts]
|
|
60
|
+
gotranx = "gotranx.cli:app"
|
|
61
|
+
|
|
62
|
+
[tool.setuptools]
|
|
63
|
+
include-package-data = true
|
|
64
|
+
package-dir = {"" = "src"}
|
|
65
|
+
zip-safe = false
|
|
66
|
+
|
|
67
|
+
[tool.setuptools.packages.find]
|
|
68
|
+
where = ["src"]
|
|
69
|
+
namespaces = false
|
|
70
|
+
|
|
71
|
+
[tool.setuptools.package-data]
|
|
72
|
+
"*" = ["*.lark"]
|
|
73
|
+
|
|
74
|
+
[tool.aliases]
|
|
75
|
+
test = "pytest"
|
|
76
|
+
|
|
77
|
+
[tool.pytest.ini_options]
|
|
78
|
+
addopts = "--cov=gotranx --cov-report html --cov-report xml --cov-report term-missing -v"
|
|
79
|
+
testpaths = ["tests"]
|
|
80
|
+
|
|
81
|
+
[tool.isort]
|
|
82
|
+
profile = "black"
|
|
83
|
+
|
|
84
|
+
[tool.mypy]
|
|
85
|
+
files = ["src/gotranx", "tests"]
|
|
86
|
+
ignore_missing_imports = true
|
|
87
|
+
exclude = "docs"
|
|
88
|
+
|
|
89
|
+
[tool.coverage.run]
|
|
90
|
+
omit = ["src/gotranx/__main__.py", "src/gotranx/templates/__init__.py"]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
[tool.ruff]
|
|
94
|
+
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
|
|
95
|
+
select = ["E", "F"]
|
|
96
|
+
ignore = ["E402", "E741", "E743", "E731"]
|
|
97
|
+
|
|
98
|
+
# Allow autofix for all enabled rules (when `--fix`) is provided.
|
|
99
|
+
fixable = ["A", "B", "C", "D", "E", "F"]
|
|
100
|
+
unfixable = []
|
|
101
|
+
|
|
102
|
+
# Exclude a variety of commonly ignored directories.
|
|
103
|
+
exclude = [
|
|
104
|
+
".bzr",
|
|
105
|
+
".direnv",
|
|
106
|
+
".eggs",
|
|
107
|
+
".git",
|
|
108
|
+
".hg",
|
|
109
|
+
".mypy_cache",
|
|
110
|
+
".nox",
|
|
111
|
+
".pants.d",
|
|
112
|
+
".pytype",
|
|
113
|
+
".ruff_cache",
|
|
114
|
+
".svn",
|
|
115
|
+
".tox",
|
|
116
|
+
".venv",
|
|
117
|
+
"__pypackages__",
|
|
118
|
+
"_build",
|
|
119
|
+
"buck-out",
|
|
120
|
+
"build",
|
|
121
|
+
"dist",
|
|
122
|
+
"node_modules",
|
|
123
|
+
"venv",
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
# Same as Black.
|
|
127
|
+
line-length = 100
|
|
128
|
+
|
|
129
|
+
# Allow unused variables when underscore-prefixed.
|
|
130
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
131
|
+
|
|
132
|
+
# Assume Python 3.10.
|
|
133
|
+
target-version = "py310"
|
|
134
|
+
|
|
135
|
+
[tool.ruff.mccabe]
|
|
136
|
+
# Unlike Flake8, default to a complexity level of 10.
|
|
137
|
+
max-complexity = 10
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
[tool.bumpversion]
|
|
141
|
+
allow_dirty = false
|
|
142
|
+
commit = true
|
|
143
|
+
message = "Bump version: {current_version} → {new_version}"
|
|
144
|
+
tag = true
|
|
145
|
+
sign_tags = false
|
|
146
|
+
tag_name = "v{new_version}"
|
|
147
|
+
tag_message = "Bump version: {current_version} → {new_version}"
|
|
148
|
+
current_version = "0.1.0"
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
[[tool.bumpversion.files]]
|
|
152
|
+
filename = "pyproject.toml"
|
|
153
|
+
search = 'version = "{current_version}"'
|
|
154
|
+
replace = 'version = "{new_version}"'
|
gotranx-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from importlib.metadata import metadata
|
|
2
|
+
|
|
3
|
+
from . import cli
|
|
4
|
+
from . import codecomponent
|
|
5
|
+
from . import exceptions
|
|
6
|
+
from . import load
|
|
7
|
+
from . import ode
|
|
8
|
+
from . import ode_component
|
|
9
|
+
from . import parser
|
|
10
|
+
from . import codegen
|
|
11
|
+
from . import transformer
|
|
12
|
+
from . import units
|
|
13
|
+
from . import sympytools
|
|
14
|
+
from . import schemes
|
|
15
|
+
from . import templates
|
|
16
|
+
from . import cellml
|
|
17
|
+
from .load import load_ode
|
|
18
|
+
from .ode import ODE
|
|
19
|
+
from .ode_component import Component
|
|
20
|
+
from .parser import Parser
|
|
21
|
+
from .transformer import TreeToODE
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
meta = metadata("gotranx")
|
|
25
|
+
__version__ = meta["Version"]
|
|
26
|
+
__author__ = meta["Author"]
|
|
27
|
+
__license__ = meta["License"]
|
|
28
|
+
__email__ = meta["Author-email"]
|
|
29
|
+
__program_name__ = meta["Name"]
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"cli",
|
|
33
|
+
"parser",
|
|
34
|
+
"Parser",
|
|
35
|
+
"codegen",
|
|
36
|
+
"transformer",
|
|
37
|
+
"TreeToODE",
|
|
38
|
+
"exceptions",
|
|
39
|
+
"load",
|
|
40
|
+
"load_ode",
|
|
41
|
+
"ode_component",
|
|
42
|
+
"Component",
|
|
43
|
+
"ode",
|
|
44
|
+
"ODE",
|
|
45
|
+
"units",
|
|
46
|
+
"codecomponent",
|
|
47
|
+
"sympytools",
|
|
48
|
+
"schemes",
|
|
49
|
+
"templates",
|
|
50
|
+
"cellml",
|
|
51
|
+
]
|