Name | pymoca JSON |
Version |
0.11.0
JSON |
| download |
home_page | None |
Summary | A Modelica to computer algebra system (CAS) translator. |
upload_time | 2025-01-07 17:37:06 |
maintainer | None |
docs_url | None |
author | Pymoca Contributors |
requires_python | >=3.9 |
license | Copyright (c) 2016-2021, James Goppert and the Pymoca contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of pymoca nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
keywords |
modelica
simulation
compiler
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
# <img alt="Pymoca" src="https://raw.githubusercontent.com/pymoca/pymoca/refs/heads/master/branding/icons/pymocalogo.svg" height="60">
A Modelica to computer algebra system (CAS) translator written in Python.
[![CI](https://github.com/pymoca/pymoca/workflows/CI/badge.svg)](https://github.com/pymoca/pymoca/actions?query=workflow%3ACI)
[![Coverage](https://codecov.io/gh/pymoca/pymoca/branch/master/graph/badge.svg)](https://codecov.io/gh/pymoca/pymoca)
[![DOI](https://zenodo.org/badge/20664755.svg)](https://zenodo.org/badge/latestdoi/20664755)
## Overview
Pymoca can be used in applications that need to translate [Modelica](https://modelica.org) mathematical models into other forms. Pymoca can "flatten" a model containing a connected set of components defined by object-oriented Modelica classes into a set of variables and simultaneous equations that are easier to further process for analysis or simulation. It is particularly suited to provide Modelica models in symbolic form to [computer algebra systems](https://en.wikipedia.org/wiki/Computer_algebra_system). A common use in this context is to provide differential and algebraic equations for use in [optimal control problems](https://en.wikipedia.org/wiki/Optimal_control). Pymoca can translate Modelica to [CasADi](https://web.casadi.org), [SymPy](https://www.sympy.org), and [ModelicaXML](https://github.com/modelica-association/ModelicaXML), but most development and usage has been with CasADi.
## Install
For parser support without backend dependencies:
```bash
pip install pymoca
```
Other options are:
```bash
pip install "pymoca[casadi]" # CasADi backend dependencies
pip install "pymoca[sympy]" # SymPy backend dependencies
pip install "pymoca[lxml]" # ModelicaXML backend dependencies
pip install "pymoca[examples]" # To run Jupyter notebook examples in the repo
pip install "pymoca[all]" # All of the above
```
## Usage
Pymoca reads and understands Modelica code (`pymoca.parser`) and provides access to an internal representation of the code called an Abstract Syntax Tree or AST (`pymoca.ast`). The AST is further processed to generate output in various formats (`pymoca.backends`). The `pymoca.tree` module provides functionality to transform the AST into a form that can be more easily used by the backends to generate the target output. In particular, `pymoca.tree` provides classes and functions to convert a hierarchical, object-oriented Modelica model of connected components into a "flat" system of equations and associated variables, parameters, and constants. Pymoca error checking is not always complete or easy to understand, so it is better to develop the Modelica code with other tools and then use Pymoca for translation.
The [test suite](https://github.com/pymoca/pymoca/tree/master/test) contains examples showing how to use Pymoca and the subset of Modelica that it currently supports.
Here is an example using a simple spring and damper model from the test suite:
```Python
from pprint import pprint
import pymoca.parser
import pymoca.backends.casadi.generator as casadi_backend
MODELICA_MODEL = """
model Spring
Real x, v_x;
parameter Real c = 0.1;
parameter Real k = 2;
equation
der(x) = v_x;
der(v_x) = -k*x - c*v_x;
end Spring;
"""
print("Modelica Model:\n", MODELICA_MODEL)
print("\nEquations from the parsed AST in a JSON representation:")
ast = pymoca.parser.parse(MODELICA_MODEL)
pprint(ast.to_json(ast.classes["Spring"].equations))
print("\nGenerated CasADi model:")
casadi_model = casadi_backend.generate(ast, "Spring")
print(casadi_model)
```
Some more interesting examples are in Jupyter notebooks:
* [Casadi Example](https://github.com/pymoca/pymoca/blob/master/test/notebooks/Casadi.ipynb)
* [Sympy Example](https://github.com/pymoca/pymoca/blob/master/test/notebooks/Spring.ipynb)
## Roadmap
See the [GitHub Projects](https://github.com/orgs/pymoca/projects) for plans. In particular, see the [Info Panel in the Modelica Flattening project](https://github.com/orgs/pymoca/projects/1/views/1?pane=info) for an overview of a project getting some current focus. Breaking API changes are expected.
<!--- vim:ts=4:sw=4:expandtab:
!-->
Raw data
{
"_id": null,
"home_page": null,
"name": "pymoca",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "Jack Vreeken <jack@vreeken.me>, Kent Rutan <gs1150e@icloud.com>",
"keywords": "modelica, simulation, compiler",
"author": "Pymoca Contributors",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/44/aa/02833d53a56a0cdf0170542af7464b4743005425f2c16e46de3a09a9ef21/pymoca-0.11.0.tar.gz",
"platform": null,
"description": "# <img alt=\"Pymoca\" src=\"https://raw.githubusercontent.com/pymoca/pymoca/refs/heads/master/branding/icons/pymocalogo.svg\" height=\"60\">\nA Modelica to computer algebra system (CAS) translator written in Python.\n\n[![CI](https://github.com/pymoca/pymoca/workflows/CI/badge.svg)](https://github.com/pymoca/pymoca/actions?query=workflow%3ACI)\n[![Coverage](https://codecov.io/gh/pymoca/pymoca/branch/master/graph/badge.svg)](https://codecov.io/gh/pymoca/pymoca)\n[![DOI](https://zenodo.org/badge/20664755.svg)](https://zenodo.org/badge/latestdoi/20664755)\n\n## Overview\nPymoca can be used in applications that need to translate [Modelica](https://modelica.org) mathematical models into other forms. Pymoca can \"flatten\" a model containing a connected set of components defined by object-oriented Modelica classes into a set of variables and simultaneous equations that are easier to further process for analysis or simulation. It is particularly suited to provide Modelica models in symbolic form to [computer algebra systems](https://en.wikipedia.org/wiki/Computer_algebra_system). A common use in this context is to provide differential and algebraic equations for use in [optimal control problems](https://en.wikipedia.org/wiki/Optimal_control). Pymoca can translate Modelica to [CasADi](https://web.casadi.org), [SymPy](https://www.sympy.org), and [ModelicaXML](https://github.com/modelica-association/ModelicaXML), but most development and usage has been with CasADi.\n\n## Install\n\nFor parser support without backend dependencies:\n```bash\npip install pymoca\n```\n\nOther options are:\n```bash\npip install \"pymoca[casadi]\" # CasADi backend dependencies\npip install \"pymoca[sympy]\" # SymPy backend dependencies\npip install \"pymoca[lxml]\" # ModelicaXML backend dependencies\n\npip install \"pymoca[examples]\" # To run Jupyter notebook examples in the repo\n\npip install \"pymoca[all]\" # All of the above\n```\n\n## Usage\n\nPymoca reads and understands Modelica code (`pymoca.parser`) and provides access to an internal representation of the code called an Abstract Syntax Tree or AST (`pymoca.ast`). The AST is further processed to generate output in various formats (`pymoca.backends`). The `pymoca.tree` module provides functionality to transform the AST into a form that can be more easily used by the backends to generate the target output. In particular, `pymoca.tree` provides classes and functions to convert a hierarchical, object-oriented Modelica model of connected components into a \"flat\" system of equations and associated variables, parameters, and constants. Pymoca error checking is not always complete or easy to understand, so it is better to develop the Modelica code with other tools and then use Pymoca for translation.\n\nThe [test suite](https://github.com/pymoca/pymoca/tree/master/test) contains examples showing how to use Pymoca and the subset of Modelica that it currently supports.\n\nHere is an example using a simple spring and damper model from the test suite:\n\n```Python\nfrom pprint import pprint\n\nimport pymoca.parser\nimport pymoca.backends.casadi.generator as casadi_backend\n\n\nMODELICA_MODEL = \"\"\"\nmodel Spring\n Real x, v_x;\n parameter Real c = 0.1;\n parameter Real k = 2;\nequation\n der(x) = v_x;\n der(v_x) = -k*x - c*v_x;\nend Spring;\n\"\"\"\n\nprint(\"Modelica Model:\\n\", MODELICA_MODEL)\n\nprint(\"\\nEquations from the parsed AST in a JSON representation:\")\nast = pymoca.parser.parse(MODELICA_MODEL)\npprint(ast.to_json(ast.classes[\"Spring\"].equations))\n\nprint(\"\\nGenerated CasADi model:\")\ncasadi_model = casadi_backend.generate(ast, \"Spring\")\nprint(casadi_model)\n```\n\nSome more interesting examples are in Jupyter notebooks:\n\n* [Casadi Example](https://github.com/pymoca/pymoca/blob/master/test/notebooks/Casadi.ipynb)\n* [Sympy Example](https://github.com/pymoca/pymoca/blob/master/test/notebooks/Spring.ipynb)\n\n## Roadmap\n\nSee the [GitHub Projects](https://github.com/orgs/pymoca/projects) for plans. In particular, see the [Info Panel in the Modelica Flattening project](https://github.com/orgs/pymoca/projects/1/views/1?pane=info) for an overview of a project getting some current focus. Breaking API changes are expected.\n\n<!--- vim:ts=4:sw=4:expandtab:\n!-->\n",
"bugtrack_url": null,
"license": "Copyright (c) 2016-2021, James Goppert and the Pymoca contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of pymoca nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
"summary": "A Modelica to computer algebra system (CAS) translator.",
"version": "0.11.0",
"project_urls": {
"homepage": "https://github.com/pymoca/pymoca"
},
"split_keywords": [
"modelica",
" simulation",
" compiler"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee8eb0a181e9ea831467d136a49ff8bbe3c14a053fe79e5e62e03e04bb482e12",
"md5": "a510331d372ff364cb78a11dfff763b7",
"sha256": "c7f07bbd863cdcc6ca706cfb5b0af53621e066f67471a560a1bc6cdeb485b16d"
},
"downloads": -1,
"filename": "pymoca-0.11.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a510331d372ff364cb78a11dfff763b7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 132968,
"upload_time": "2025-01-07T17:37:04",
"upload_time_iso_8601": "2025-01-07T17:37:04.162320Z",
"url": "https://files.pythonhosted.org/packages/ee/8e/b0a181e9ea831467d136a49ff8bbe3c14a053fe79e5e62e03e04bb482e12/pymoca-0.11.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "44aa02833d53a56a0cdf0170542af7464b4743005425f2c16e46de3a09a9ef21",
"md5": "a84f06e7b329291b0765c5da3fbe8db0",
"sha256": "b0da570ff854865564b4ec82c741774f2cf9dcaac2017d5a98a3e131474f44b0"
},
"downloads": -1,
"filename": "pymoca-0.11.0.tar.gz",
"has_sig": false,
"md5_digest": "a84f06e7b329291b0765c5da3fbe8db0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 129874,
"upload_time": "2025-01-07T17:37:06",
"upload_time_iso_8601": "2025-01-07T17:37:06.731199Z",
"url": "https://files.pythonhosted.org/packages/44/aa/02833d53a56a0cdf0170542af7464b4743005425f2c16e46de3a09a9ef21/pymoca-0.11.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-07 17:37:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pymoca",
"github_project": "pymoca",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "pymoca"
}