gotranx

gotranx: General ODE translator - Published in JOSS (2024)

https://github.com/finsberg/gotranx

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

code-generation gotran ode parser parsing

Keywords from Contributors

mesh hydrology energy-system pde standardization turing-machine exoplanet benchmarking physics-simulation optimisation

Scientific Fields

Mathematics Computer Science - 37% confidence
Last synced: 6 months ago · JSON representation ·

Repository

Next generation ODE translator

Basic Info
Statistics
  • Stars: 12
  • Watchers: 1
  • Forks: 2
  • Open Issues: 7
  • Releases: 15
Topics
code-generation gotran ode parser parsing
Created over 3 years ago · Last pushed 6 months ago
Metadata Files
Readme Contributing License Code of conduct Citation Roadmap

README.md

_

pre-commit CI Publish documentation License: MIT Code style: black CodSpeed Badge status DOI

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

  1. You want to solve your model using different programming languages (e.g python and C)
  2. You want to create a custom numerical scheme that can utilize the symbolic representation of the ODE
  3. 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

Senior Research Engineer working with Scientific Computing and Computational Physiology

JOSS Publication

gotranx: General ODE translator
Published
October 17, 2024
Volume 9, Issue 102, Page 7063
Authors
Henrik Finsberg ORCID
Simula Research Laboratory, Oslo, Norway
Johan Hake
Oslo Katedralskole, Oslo, Norway
Editor
Rohit Goswami ORCID
Tags
code generation ordinary differential equations parser

Citation (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

All Time
  • Total Commits: 503
  • Total Committers: 6
  • Avg Commits per committer: 83.833
  • Development Distribution Score (DDS): 0.205
Past Year
  • Commits: 209
  • Committers: 4
  • Avg Commits per committer: 52.25
  • Development Distribution Score (DDS): 0.316
Top Committers
Name Email 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
dependencies (16) github_actions (2) enhancement (1)

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

  • Versions: 30
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 278 Last month
Rankings
Dependent packages count: 10.0%
Average: 38.2%
Dependent repos count: 66.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/main.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • codecov/codecov-action v3 composite
  • pypa/gh-action-pypi-publish master composite
.github/workflows/pages.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v4 composite
  • peaceiris/actions-gh-pages v3 composite
.github/workflows/pre-commit.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pre-commit/action v3.0.0 composite
.github/workflows/pypi.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/upload-artifact v3 composite
  • pypa/gh-action-pypi-publish release/v1 composite
pyproject.toml pypi
  • attrs *
  • clang-format-docs *
  • graphlib-backport python_version < "3.9"
  • lark *
  • pint *
  • rich-click *
  • structlog *
  • sympy *
  • typer *