gotranx
gotranx: General ODE translator - Published in JOSS (2024)
Science Score: 100.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 7 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org, zenodo.org -
✓Committers with academic emails
1 of 6 committers (16.7%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Keywords from Contributors
Scientific Fields
Repository
Next generation ODE translator
Basic Info
- Host: GitHub
- Owner: finsberg
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://finsberg.github.io/gotranx
- Size: 2.57 MB
Statistics
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 7
- Releases: 15
Topics
Metadata Files
README.md

gotranx
gotranx is the next generation General ODE translator. 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. gotranx uses sympy to create a symbolic representation of the ODE which is used to generate the jacobian and numerical schemes.
gotranx makes it also possible generate code from e.g CellML models using conversion tools from myokit.
- Source code: https://github.com/finsberg/gotranx
- Documentation: https://finsberg.github.io/gotranx/
Install
Install with pip
python3 -m pip install gotranx
or for the development version
python3 -m pip install git+https://github.com/finsberg/gotranx
You can also install gotranx using conda
conda install -c conda-forge gotranx
Quick start
Define your ODE in a .ode file, e.g file.ode with the content
```
states(x=1, y=0)
parameters(a=1.0)
dxdt = a * y dydt = -x ``` which defines the ODE system
$$ \begin{align} \frac{dx}{dt} &= ay \ \frac{dy}{dt} &= -x \end{align} $$
with the initial conditions $x(0) = 1$ and $y(0) = 0$ and the parameter $a$ with a value of 1.0. Now generate code in python for solving this ODE with the explicit euler scheme using the command
gotranx ode2py file.ode --scheme explicit_euler -o file.py
which will create a file file.py containing functions for solving the ODE. Now you can solve the ode using the following code snippet
```python import file as model import numpy as np import matplotlib.pyplot as plt
s = model.initstatevalues() p = model.initparametervalues() dt = 1e-4 # 0.1 ms T = 2 * np.pi t = np.arange(0, T, dt)
xindex = model.stateindex("x") x = [s[xindex]] yindex = model.stateindex("y") y = [s[yindex]]
for ti in t[1:]: s = model.expliciteuler(s, ti, dt, p) x.append(s[xindex]) y.append(s[y_index])
plt.plot(t, x, label="x")
plt.plot(t, y, label="y")
plt.legend()
plt.show()
```

Alternatively, you can use a third-party ODE solver, e.g scipy.integrate.solve_ivp to solve the ODE by passing in the right-hand side function
```python import file as model from scipy.integrate import solve_ivp import numpy as np import matplotlib.pyplot as plt
s = model.initstatevalues() p = model.initparametervalues() dt = 1e-4 # 0.1 ms T = 2 * np.pi t = np.arange(0, T, dt)
res = solveivp( model.rhs, (0, T), s, method="RK45", teval=t, args=(p,), )
plt.plot(res.t, res.y.T) plt.legend() plt.show() ```
Note that this is a rather artificial example, so check out the demos in the documentation for more elaborate examples.
FAQ
Why should I use gotranx?
The main reasons to use gotranx are
- You want to solve your model using different programming languages (e.g python and C)
- You want to create a custom numerical scheme that can utilize the symbolic representation of the ODE
- You would like to share your model in a high level representation (i.e a markup language)
How does it differ from scipy.integrate.solve_ivp?
scipy.integrate.solve_ivp is an ODE solver which takes as input a function defining the right-hand. gotranx takes a high level representation of the ODE and can generate code for the right hand side. In other words, you can use scipy.integrate.solve_ivp to solve the ODE and use gotranx to generate the right hand side.
Automated tests
Unit tests
Automated tests can be found in the test folder. To the run the tests please install the test dependencies
python3 -m pip install "gotranx[test]"
or if you have cloned the repo locally you can do
python3 -m pip install ".[test]"
To run the tests you should execute the following command
python3 -m pytest
Also note that the tests are run on every push and pull request to main using GitHub actions.
Linting and formatting
We use pre-commit to run the a set of linters and formatters in order to ensure consistent code style. Developers should install the pre-commit hooks by first installing pre-commit
python3 -m pip install pre-commit
and then install the pre-commit hooks
pre-commit install
To run the hooks on all the files you can do
pre-commit run --all
For further instructions see the contributing guide.
Note also the we run all hooks as a part of our continuous integration, and we are also using pre-commit.ci to update branches automatically that can fix issues automatically.
Performance monitoring
We have defined a set of benchmarks that run on every push to the main branch using codspeed. To monitor the performance over time you can check out the performance report.
To run the benchmarks locally you can install the pytest-codspeed plugin
python3 -m pip install pytest-codspeed
and run
python3 -m pytest tests/ --codspeed
You can find more info at https://docs.codspeed.io/benchmarks/python
Citing
If you use gotranx in your research project we would appreciate if you could use the following citation
@article{Finsberg2024,
doi = {10.21105/joss.07063},
url = {https://doi.org/10.21105/joss.07063},
year = {2024},
publisher = {The Open Journal},
volume = {9},
number = {102},
pages = {7063},
author = {Henrik Finsberg and Johan Hake},
title = {gotranx: General ODE translator},
journal = {Journal of Open Source Software}
}
License
MIT
Contributing
Contributions are very welcomed, but please read the contributing guide first
Owner
- Name: Henrik Finsberg
- Login: finsberg
- Kind: user
- Location: Oslo, Norway
- Company: Simula Research Laboratoy
- Website: https://finsberg.github.io
- Repositories: 13
- Profile: https://github.com/finsberg
Senior Research Engineer working with Scientific Computing and Computational Physiology
JOSS Publication
gotranx: General ODE translator
Authors
Oslo Katedralskole, Oslo, Norway
Tags
code generation ordinary differential equations parserCitation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Fisberg"
given-names: "Henrik"
orcid: "https://orcid.org/0000-0003-3766-2393"
title: "gotranx"
url: "https://github.com/finsberg/gotranx"
preferred-citation:
type: article
doi: "10.21105/joss.07063"
journal: "Journal of Open Source Software"
title: "gotranx: General ODE translator"
year: 2024
volume: 9
issue: 102
authors:
- family-names: "Finsberg"
given-names: "Henrik"
orcid: "https://orcid.org/0000-0003-3766-2393"
- family-names: "Hake"
given-names: "Johan"
GitHub Events
Total
- Create event: 22
- Release event: 6
- Issues event: 11
- Watch event: 4
- Delete event: 14
- Issue comment event: 60
- Push event: 110
- Pull request event: 90
- Fork event: 2
Last Year
- Create event: 22
- Release event: 6
- Issues event: 11
- Watch event: 4
- Delete event: 14
- Issue comment event: 60
- Push event: 110
- Pull request event: 90
- Fork event: 2
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Henrik Finsberg | h****g@h****m | 400 |
| pre-commit-ci[bot] | 6****] | 84 |
| dependabot[bot] | 4****] | 7 |
| termi-official | t****l | 6 |
| Daniel S. Katz | d****z@i****g | 4 |
| Kyle Beggs | b****w@g****m | 2 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 26
- Total pull requests: 309
- Average time to close issues: 25 days
- Average time to close pull requests: 9 days
- Total issue authors: 8
- Total pull request authors: 6
- Average comments per issue: 0.85
- Average comments per pull request: 0.49
- Merged pull requests: 276
- Bot issues: 0
- Bot pull requests: 140
Past Year
- Issues: 6
- Pull requests: 103
- Average time to close issues: 4 days
- Average time to close pull requests: 2 days
- Issue authors: 5
- Pull request authors: 5
- Average comments per issue: 1.17
- Average comments per pull request: 0.98
- Merged pull requests: 92
- Bot issues: 0
- Bot pull requests: 79
Top Authors
Issue Authors
- finsberg (8)
- SunnyXu (8)
- benlansdell (3)
- ayush9pandey (3)
- HaoZeke (1)
- MichaelClerx (1)
- kylebeggs (1)
- hsauro (1)
Pull Request Authors
- finsberg (163)
- pre-commit-ci[bot] (124)
- dependabot[bot] (16)
- termi-official (2)
- kylebeggs (2)
- danielskatz (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 278 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 30
- Total maintainers: 1
pypi.org: gotranx
A declarative language describing ordinary differential equations
- Homepage: https://github.com/finsberg/gotranx
- Documentation: https://gotranx.readthedocs.io/
- License: MIT
-
Latest release: 1.3.5
published 9 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- codecov/codecov-action v3 composite
- pypa/gh-action-pypi-publish master composite
- actions/checkout v2 composite
- actions/setup-python v4 composite
- peaceiris/actions-gh-pages v3 composite
- actions/checkout v3 composite
- actions/setup-python v3 composite
- pre-commit/action v3.0.0 composite
- actions/checkout v3 composite
- actions/download-artifact v3 composite
- actions/upload-artifact v3 composite
- pypa/gh-action-pypi-publish release/v1 composite
- attrs *
- clang-format-docs *
- graphlib-backport python_version < "3.9"
- lark *
- pint *
- rich-click *
- structlog *
- sympy *
- typer *
