{"id":19811726,"url":"https://github.com/finsberg/gotranx","last_synced_at":"2025-05-01T08:33:13.454Z","repository":{"id":45457439,"uuid":"512191435","full_name":"finsberg/gotranx","owner":"finsberg","description":"Next generation ODE translator","archived":false,"fork":false,"pushed_at":"2024-11-11T22:10:42.000Z","size":2507,"stargazers_count":8,"open_issues_count":13,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-11T23:20:05.905Z","etag":null,"topics":["code-generation","gotran","ode","parser","parsing"],"latest_commit_sha":null,"homepage":"https://finsberg.github.io/gotranx","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/finsberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"docs/roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-09T13:22:15.000Z","updated_at":"2024-11-05T20:03:59.000Z","dependencies_parsed_at":"2024-01-19T09:53:56.341Z","dependency_job_id":"9891c2b4-4aad-49c1-8a3f-5a31a3690e02","html_url":"https://github.com/finsberg/gotranx","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":"finsberg/lib-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finsberg%2Fgotranx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finsberg%2Fgotranx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finsberg%2Fgotranx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finsberg%2Fgotranx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/finsberg","download_url":"https://codeload.github.com/finsberg/gotranx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224249035,"owners_count":17280272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","gotran","ode","parser","parsing"],"created_at":"2024-11-12T09:27:36.575Z","updated_at":"2025-05-01T08:33:13.448Z","avatar_url":"https://github.com/finsberg.png","language":"Python","funding_links":[],"categories":["Simulation software"],"sub_categories":["Cellular modeling"],"readme":"![_](https://raw.githubusercontent.com/finsberg/gotranx/main/docs/_static/logo.png)\n\n[![pre-commit](https://github.com/finsberg/gotranx/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/finsberg/gotranx/actions/workflows/pre-commit.yml)\n[![CI](https://github.com/finsberg/gotranx/actions/workflows/main.yml/badge.svg)](https://github.com/finsberg/gotranx/actions/workflows/main.yml)\n[![Publish documentation](https://github.com/finsberg/gotranx/actions/workflows/deploy_docs.yml/badge.svg)](https://finsberg.github.io/gotranx)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/finsberg/gotranx)\n[![status](https://joss.theoj.org/papers/40dc8d8287c6188eaab8149ed3bfe60b/status.svg)](https://joss.theoj.org/papers/40dc8d8287c6188eaab8149ed3bfe60b)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.13940990.svg)](https://doi.org/10.5281/zenodo.13940990)\n\n# gotranx\n\n`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`](https://www.sympy.org/en/index.html) to create a symbolic representation of the ODE which is used to generate the jacobian and numerical schemes.\n\n- Source code: https://github.com/finsberg/gotranx\n- Documentation: https://finsberg.github.io/gotranx/\n\n\n## Install\nInstall with pip\n```\npython3 -m pip install gotranx\n```\nor for the development version\n```\npython3 -m pip install git+https://github.com/finsberg/gotranx\n```\n\nYou can also install `gotranx` using conda\n```\nconda install -c conda-forge gotranx\n```\n\n## Quick start\nDefine your ODE in a `.ode` file, e.g `file.ode` with the content\n```\nstates(x=1, y=0)\nparameters(a=1.0)\n\ndx_dt = a * y\ndy_dt = -x\n```\nwhich defines the ODE system\n\n$$\n\\begin{align}\n\\frac{dx}{dt} \u0026= ay \\\\\n\\frac{dy}{dt} \u0026= -x\n\\end{align}\n$$\n\nwith 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\n```\ngotranx ode2py file.ode --scheme explicit_euler -o file.py\n```\nwhich will create a file `file.py` containing functions for solving the ODE. Now you can solve the ode using the following code snippet\n\n```python\nimport file as model\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ns = model.init_state_values()\np = model.init_parameter_values()\ndt = 1e-4  # 0.1 ms\nT = 2 * np.pi\nt = np.arange(0, T, dt)\n\nx_index = model.state_index(\"x\")\nx = [s[x_index]]\ny_index = model.state_index(\"y\")\ny = [s[y_index]]\n\nfor ti in t[1:]:\n    s = model.explicit_euler(s, ti, dt, p)\n    x.append(s[x_index])\n    y.append(s[y_index])\n\nplt.plot(t, x, label=\"x\")\nplt.plot(t, y, label=\"y\")\nplt.legend()\nplt.show()\n```\n![_](docs/_static/quick_start.png)\n\nAlternatively, you can use a third-party ODE solver, e.g [`scipy.integrate.solve_ivp`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html) to solve the ODE by passing in the right-hand side function\n\n```python\nimport file as model\nfrom scipy.integrate import solve_ivp\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ns = model.init_state_values()\np = model.init_parameter_values()\ndt = 1e-4  # 0.1 ms\nT = 2 * np.pi\nt = np.arange(0, T, dt)\n\nres = solve_ivp(\n    model.rhs,\n    (0, T),\n    s,\n    method=\"RK45\",\n    t_eval=t,\n    args=(p,),\n)\n\nplt.plot(res.t, res.y.T)\nplt.legend()\nplt.show()\n```\n\nNote that this is a rather artificial example, so check out the demos in the [documentation](https://finsberg.github.io/gotranx/) for more elaborate examples.\n\n## FAQ\n\n**Why should I use `gotranx`?**\nThe main reasons to use `gotranx` are\n\n1. You want to solve your model using different programming languages (e.g python and C)\n2. You want to create a custom numerical scheme that can utilize the symbolic representation of the ODE\n3. You would like to share your model in a high level representation (i.e a markup language)\n\n\n**How does it differ from `scipy.integrate.solve_ivp`?**\n`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.\n\n\n## Automated tests\n\n### Unit tests\nAutomated tests can be found in the [`test`](https://github.com/finsberg/gotranx/tree/main/tests) folder. To the run the tests please install the test dependencies\n```\npython3 -m pip install \"gotranx[test]\"\n```\nor if you have cloned the repo locally you can do\n```\npython3 -m pip install \".[test]\"\n```\nTo run the tests you should execute the following command\n```\npython3 -m pytest\n```\nAlso note that the tests are run on every push and pull request to `main` using [GitHub actions](https://github.com/finsberg/gotranx/actions).\n\n### Linting and formatting\nWe use [`pre-commit`](https://pre-commit.com) to run the a set of linters and formatters in order to ensure consistent code style. Developers should install the [pre-commit hooks](https://github.com/finsberg/gotranx/blob/main/.pre-commit-config.yaml) by first installing `pre-commit`\n```\npython3 -m pip install pre-commit\n```\nand then install the pre-commit hooks\n```\npre-commit install\n```\nTo run the hooks on all the files you can do\n```\npre-commit run --all\n```\nFor further instructions see the [contributing guide](https://finsberg.github.io/gotranx/CONTRIBUTING.html).\n\nNote also the we run all hooks as a part of our [continuous integration](https://github.com/finsberg/gotranx/actions/workflows/pre-commit.yml), and we are also using [pre-commit.ci](https://pre-commit.ci) to update branches automatically that can fix issues automatically.\n\n### Performance monitoring\nWe have defined a set of benchmarks that run on every push to the `main` branch using [codspeed](https://codspeed.io). To monitor the performance over time you can check out the [performance report](https://codspeed.io/finsberg/gotranx).\n\nTo run the benchmarks locally you can install the `pytest-codspeed` plugin\n```\npython3 -m pip install pytest-codspeed\n```\nand run\n```\npython3 -m pytest tests/ --codspeed\n```\nYou can find more info at https://docs.codspeed.io/benchmarks/python\n\n\n## License\nMIT\n\n## Contributing\nContributions are very welcomed, but please read the [contributing guide](https://finsberg.github.io/gotranx/CONTRIBUTING.html) first\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinsberg%2Fgotranx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinsberg%2Fgotranx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinsberg%2Fgotranx/lists"}