pythonfmu3 0.2.2__tar.gz → 0.2.2.2__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.
Potentially problematic release.
This version of pythonfmu3 might be problematic. Click here for more details.
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/LICENSE +23 -23
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/MANIFEST.in +8 -8
- pythonfmu3-0.2.2.2/PKG-INFO +168 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/README.md +144 -144
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/__init__.py +8 -8
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/__main__.py +52 -52
- pythonfmu3-0.2.2.2/pythonfmu3/_version.py +1 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/builder.py +260 -260
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/default_experiment.py +7 -7
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/deploy.py +118 -118
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/enums.py +48 -48
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/fmi3slave.py +438 -438
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/logmsg.py +14 -14
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/osutil.py +22 -22
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/.clang-format +35 -35
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/CMakeLists.txt +59 -59
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/build_unix.sh +4 -4
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/build_win.sh +4 -4
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/CMakeLists.txt +45 -45
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_common.hpp +161 -161
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.cpp +192 -192
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.hpp +185 -185
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/cppfmu/fmi_functions.cpp +937 -937
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/fmi/fmi3FunctionTypes.h +638 -638
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/fmi/fmi3Functions.h +343 -343
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/fmi/fmi3PlatformTypes.h +94 -94
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/pythonfmu/IPyState.hpp +17 -17
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.cpp +744 -744
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.hpp +111 -111
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/pythonfmu-export/src/pythonfmu/PyState.hpp +84 -84
- pythonfmu3-0.2.2.2/pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so +0 -0
- pythonfmu3-0.2.2.2/pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/conftest.py +5 -5
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/data/csvdemo.csv +7 -7
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/slaves/PythonSlaveWithException.py +18 -18
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/slaves/localmodule.py +8 -8
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/slaves/pythonslave.py +52 -52
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/slaves/pythonslave_read_file.py +23 -23
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/slaves/slavewithdep.py +21 -21
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_builder.py +195 -195
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_deploy.py +48 -48
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_fmi3slave.py +152 -152
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_integration.py +350 -350
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_logger.py +180 -180
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_multiple_fmus.py +141 -141
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/test_variables.py +334 -334
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/utils.py +13 -13
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/unit.py +62 -62
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/variable_types.py +101 -101
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/variables.py +400 -400
- pythonfmu3-0.2.2.2/pythonfmu3.egg-info/PKG-INFO +168 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3.egg-info/entry_points.txt +1 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3.egg-info/not-zip-safe +1 -1
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/setup.py +4 -4
- pythonfmu3-0.2.2/PKG-INFO +0 -170
- pythonfmu3-0.2.2/pythonfmu3/_version.py +0 -1
- pythonfmu3-0.2.2/pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so +0 -0
- pythonfmu3-0.2.2/pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll +0 -0
- pythonfmu3-0.2.2/pythonfmu3.egg-info/PKG-INFO +0 -170
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/__init__.py +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3/tests/data/hello.txt +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3.egg-info/SOURCES.txt +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3.egg-info/dependency_links.txt +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3.egg-info/requires.txt +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/pythonfmu3.egg-info/top_level.txt +0 -0
- {pythonfmu3-0.2.2 → pythonfmu3-0.2.2.2}/setup.cfg +0 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019-2020 NTNU - Department of Ocean Operations and Civil Engineering
|
|
4
|
-
Copyright (c) 2019-2020 Safran SA
|
|
5
|
-
Copyright (c) 2023 Stephen Smith
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2020 NTNU - Department of Ocean Operations and Civil Engineering
|
|
4
|
+
Copyright (c) 2019-2020 Safran SA
|
|
5
|
+
Copyright (c) 2023 Stephen Smith
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
include LICENSE
|
|
2
|
-
include README.md
|
|
3
|
-
|
|
4
|
-
recursive-include pythonfmu3/tests/data *
|
|
5
|
-
recursive-include pythonfmu3/tests/slaves *
|
|
6
|
-
|
|
7
|
-
recursive-include pythonfmu3/resources *
|
|
8
|
-
recursive-include pythonfmu3/pythonfmu-export *
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
|
|
4
|
+
recursive-include pythonfmu3/tests/data *
|
|
5
|
+
recursive-include pythonfmu3/tests/slaves *
|
|
6
|
+
|
|
7
|
+
recursive-include pythonfmu3/resources *
|
|
8
|
+
recursive-include pythonfmu3/pythonfmu-export *
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pythonfmu3
|
|
3
|
+
Version: 0.2.2.2
|
|
4
|
+
Summary: A lightweight framework that enables the packaging of Python3.x code as co-simulation FMUs.
|
|
5
|
+
Home-page: https://github.com/stephensmith25/PythonFMU3
|
|
6
|
+
Author: Stephen Smith
|
|
7
|
+
License: MIT
|
|
8
|
+
Description: # PythonFMU3
|
|
9
|
+
|
|
10
|
+
> A lightweight framework that enables the packaging of Python 3 code as co-simulation FMUs (following FMI version 3.0).
|
|
11
|
+
|
|
12
|
+
[](https://opensource.org/licenses/MIT)
|
|
13
|
+
[](https://github.com/StephenSmith25/PythonFMU3/issues)
|
|
14
|
+
|
|
15
|
+
[](https://github.com/StephenSmith25/PythonFMU3/actions?query=workflow%3ACI)
|
|
16
|
+
[](https://pypi.org/project/pythonfmu3/)
|
|
17
|
+
[](https://pythonfmu3.readthedocs.io/)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
This project is a fork of the original PythonFMU repository available at https://github.com/NTNU-IHB/PythonFMU, which was used as the basis for adding support for FMI 3.0. While we have made efforts to expand the functionality of this project, it currently has some limitations and does not support all the features of FMI 3.0. We would like to acknowledge and give credit to the original PythonFMU project for their contributions to this work.
|
|
21
|
+
|
|
22
|
+
### Support:
|
|
23
|
+
|
|
24
|
+
Please take a look at the examples to see the supported features.
|
|
25
|
+
|
|
26
|
+
### Future
|
|
27
|
+
|
|
28
|
+
In no particular order, we plan to add support for:
|
|
29
|
+
|
|
30
|
+
- Support more variable types from FMI3
|
|
31
|
+
- Improve array support
|
|
32
|
+
- Add event mode
|
|
33
|
+
|
|
34
|
+
### How do I build an FMU from python code?
|
|
35
|
+
|
|
36
|
+
1. Install `pythonfmu3` package:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install pythonfmu3
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
|
|
43
|
+
3. Run `pythonfmu3 build` to create the fmu.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
usage: pythonfmu3 build [-h] -f SCRIPT_FILE [-d DEST] [--doc DOCUMENTATION_FOLDER] [--terminals TERMINALS_FILE] [--no-external-tool]
|
|
47
|
+
[--no-variable-step] [--interpolate-inputs] [--only-one-per-process] [--handle-state]
|
|
48
|
+
[--serialize-state] [--use-memory-management]
|
|
49
|
+
[Project files [Project files ...]]
|
|
50
|
+
|
|
51
|
+
Build an FMU from a Python script.
|
|
52
|
+
|
|
53
|
+
positional arguments:
|
|
54
|
+
Project files Additional project files required by the Python script.
|
|
55
|
+
|
|
56
|
+
optional arguments:
|
|
57
|
+
-h, --help show this help message and exit
|
|
58
|
+
-f SCRIPT_FILE, --file SCRIPT_FILE
|
|
59
|
+
Path to the Python script.
|
|
60
|
+
-d DEST, --dest DEST Where to save the FMU.
|
|
61
|
+
--doc DOCUMENTATION_FOLDER
|
|
62
|
+
Documentation folder to include in the FMU.
|
|
63
|
+
--terminals TERMINALS_FILE
|
|
64
|
+
Terminals file (terminalsAndIcons.xml) to include in the FMU.
|
|
65
|
+
--no-external-tool If given, needsExecutionTool=false
|
|
66
|
+
--no-variable-step If given, canHandleVariableCommunicationStepSize=false
|
|
67
|
+
--interpolate-inputs If given, canInterpolateInputs=true
|
|
68
|
+
--only-one-per-process
|
|
69
|
+
If given, canBeInstantiatedOnlyOncePerProcess=true
|
|
70
|
+
--handle-state If given, canGetAndSetFMUstate=true
|
|
71
|
+
--serialize-state If given, canSerializeFMUstate=true
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### How do I build an FMU from python code with third-party dependencies?
|
|
75
|
+
|
|
76
|
+
Often, Python scripts depends on non-builtin libraries like `numpy`, `scipy`, etc.
|
|
77
|
+
_PythonFMU_ does not package a full environment within the FMU.
|
|
78
|
+
However, you can package a `requirements.txt` or `environment.yml` file within your FMU following these steps:
|
|
79
|
+
|
|
80
|
+
1. Install _pythonfmu_ package: `pip install pythonfmu3`
|
|
81
|
+
2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
|
|
82
|
+
3. Create a `requirements.txt` file (to use _pip_ manager) and/or a `environment.yml` file (to use _conda_ manager) that defines your dependencies.
|
|
83
|
+
4. Run `pythonfmu3 build -f myscript.py requirements.txt` to create the fmu including the dependencies file.
|
|
84
|
+
|
|
85
|
+
And using `pythonfmu3 deploy`, end users will be able to update their local Python environment. The steps to achieve that:
|
|
86
|
+
|
|
87
|
+
1. Install _pythonfmu_ package: `pip install pythonfmu3`
|
|
88
|
+
2. Be sure to be in the Python environment to be updated. Then execute `pythonfmu3 deploy -f my.fmu`
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
usage: pythonfmu3 deploy [-h] -f FMU [-e ENVIRONMENT] [{pip,conda}]
|
|
92
|
+
|
|
93
|
+
Deploy a Python FMU. The command will look in the `resources` folder for one of the following files:
|
|
94
|
+
`requirements.txt` or `environment.yml`. If you specify a environment file but no package manager, `conda` will be selected for `.yaml` and `.yml` otherwise `pip` will be used. The tool assume the Python environment in which the FMU should be executed is the current one.
|
|
95
|
+
|
|
96
|
+
positional arguments:
|
|
97
|
+
{pip,conda} Python packages manager
|
|
98
|
+
|
|
99
|
+
optional arguments:
|
|
100
|
+
-h, --help show this help message and exit
|
|
101
|
+
-f FMU, --file FMU Path to the Python FMU.
|
|
102
|
+
-e ENVIRONMENT, --env ENVIRONMENT
|
|
103
|
+
Requirements or environment file.
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Example:
|
|
107
|
+
|
|
108
|
+
#### Write the script
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
|
|
112
|
+
from pythonfmu3 import Fmi3Causality, Fmi3Slave, Boolean, Int32, Float64, String
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class PythonSlave(Fmi3Slave):
|
|
116
|
+
|
|
117
|
+
def __init__(self, **kwargs):
|
|
118
|
+
super().__init__(**kwargs)
|
|
119
|
+
|
|
120
|
+
self.author = "John Doe"
|
|
121
|
+
self.description = "A simple description"
|
|
122
|
+
|
|
123
|
+
self.time = 0.0
|
|
124
|
+
self.intOut = 1
|
|
125
|
+
self.realOut = 3.0
|
|
126
|
+
self.booleanVariable = True
|
|
127
|
+
self.stringVariable = "Hello World!"
|
|
128
|
+
self.register_variable(Float64("time", causality=Fmi3Causality.independent))
|
|
129
|
+
self.register_variable(Int32("intOut", causality=Fmi3Causality.output))
|
|
130
|
+
self.register_variable(Float64("realOut", causality=Fmi3Causality.output))
|
|
131
|
+
self.register_variable(Boolean("booleanVariable", causality=Fmi3Causality.local))
|
|
132
|
+
self.register_variable(String("stringVariable", causality=Fmi3Causality.local))
|
|
133
|
+
|
|
134
|
+
# Note:
|
|
135
|
+
# it is also possible to explicitly define getters and setters as lambdas in case the variable is not backed by a Python field.
|
|
136
|
+
# self.register_variable(Float64("myReal", causality=Fmi3Causality.output, getter=lambda: self.realOut, setter=lambda v: set_real_out(v))
|
|
137
|
+
|
|
138
|
+
def do_step(self, current_time, step_size):
|
|
139
|
+
return True
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Create the FMU
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
pythonfmu3 build -f pythonslave.py myproject
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
In this example a python class named `PythonSlave` that extends `Fmi3Slave` is declared in a file named `pythonslave.py`,
|
|
150
|
+
where `myproject` is an optional folder containing additional project files required by the python script.
|
|
151
|
+
Project folders such as this will be recursively copied into the FMU. Multiple project files/folders may be added.
|
|
152
|
+
|
|
153
|
+
Keywords: FMI
|
|
154
|
+
Platform: UNKNOWN
|
|
155
|
+
Classifier: Development Status :: 3 - Alpha
|
|
156
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
157
|
+
Classifier: Intended Audience :: Developers
|
|
158
|
+
Classifier: Intended Audience :: Science/Research
|
|
159
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
160
|
+
Classifier: Natural Language :: English
|
|
161
|
+
Classifier: Programming Language :: C++
|
|
162
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
163
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
164
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
165
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
166
|
+
Classifier: Topic :: Scientific/Engineering
|
|
167
|
+
Description-Content-Type: text/markdown
|
|
168
|
+
Provides-Extra: tests
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
# PythonFMU3
|
|
2
|
-
|
|
3
|
-
> A lightweight framework that enables the packaging of Python 3 code as co-simulation FMUs (following FMI version 3.0).
|
|
4
|
-
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://github.com/StephenSmith25/PythonFMU3/issues)
|
|
7
|
-
|
|
8
|
-
[](https://github.com/StephenSmith25/PythonFMU3/actions?query=workflow%3ACI)
|
|
9
|
-
[](https://pypi.org/project/pythonfmu3/)
|
|
10
|
-
[](https://pythonfmu3.readthedocs.io/)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
This project is a fork of the original PythonFMU repository available at https://github.com/NTNU-IHB/PythonFMU, which was used as the basis for adding support for FMI 3.0. While we have made efforts to expand the functionality of this project, it currently has some limitations and does not support all the features of FMI 3.0. We would like to acknowledge and give credit to the original PythonFMU project for their contributions to this work.
|
|
14
|
-
|
|
15
|
-
### Support:
|
|
16
|
-
|
|
17
|
-
Please take a look at the examples to see the supported features.
|
|
18
|
-
|
|
19
|
-
### Future
|
|
20
|
-
|
|
21
|
-
In no particular order, we plan to add support for:
|
|
22
|
-
|
|
23
|
-
- Support more variable types from FMI3
|
|
24
|
-
- Improve array support
|
|
25
|
-
- Add event mode
|
|
26
|
-
|
|
27
|
-
### How do I build an FMU from python code?
|
|
28
|
-
|
|
29
|
-
1. Install `pythonfmu3` package:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip install pythonfmu3
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
|
|
36
|
-
3. Run `pythonfmu3 build` to create the fmu.
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
usage: pythonfmu3 build [-h] -f SCRIPT_FILE [-d DEST] [--doc DOCUMENTATION_FOLDER] [--terminals TERMINALS_FILE] [--no-external-tool]
|
|
40
|
-
[--no-variable-step] [--interpolate-inputs] [--only-one-per-process] [--handle-state]
|
|
41
|
-
[--serialize-state] [--use-memory-management]
|
|
42
|
-
[Project files [Project files ...]]
|
|
43
|
-
|
|
44
|
-
Build an FMU from a Python script.
|
|
45
|
-
|
|
46
|
-
positional arguments:
|
|
47
|
-
Project files Additional project files required by the Python script.
|
|
48
|
-
|
|
49
|
-
optional arguments:
|
|
50
|
-
-h, --help show this help message and exit
|
|
51
|
-
-f SCRIPT_FILE, --file SCRIPT_FILE
|
|
52
|
-
Path to the Python script.
|
|
53
|
-
-d DEST, --dest DEST Where to save the FMU.
|
|
54
|
-
--doc DOCUMENTATION_FOLDER
|
|
55
|
-
Documentation folder to include in the FMU.
|
|
56
|
-
--terminals TERMINALS_FILE
|
|
57
|
-
Terminals file (terminalsAndIcons.xml) to include in the FMU.
|
|
58
|
-
--no-external-tool If given, needsExecutionTool=false
|
|
59
|
-
--no-variable-step If given, canHandleVariableCommunicationStepSize=false
|
|
60
|
-
--interpolate-inputs If given, canInterpolateInputs=true
|
|
61
|
-
--only-one-per-process
|
|
62
|
-
If given, canBeInstantiatedOnlyOncePerProcess=true
|
|
63
|
-
--handle-state If given, canGetAndSetFMUstate=true
|
|
64
|
-
--serialize-state If given, canSerializeFMUstate=true
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### How do I build an FMU from python code with third-party dependencies?
|
|
68
|
-
|
|
69
|
-
Often, Python scripts depends on non-builtin libraries like `numpy`, `scipy`, etc.
|
|
70
|
-
_PythonFMU_ does not package a full environment within the FMU.
|
|
71
|
-
However, you can package a `requirements.txt` or `environment.yml` file within your FMU following these steps:
|
|
72
|
-
|
|
73
|
-
1. Install _pythonfmu_ package: `pip install pythonfmu3`
|
|
74
|
-
2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
|
|
75
|
-
3. Create a `requirements.txt` file (to use _pip_ manager) and/or a `environment.yml` file (to use _conda_ manager) that defines your dependencies.
|
|
76
|
-
4. Run `pythonfmu3 build -f myscript.py requirements.txt` to create the fmu including the dependencies file.
|
|
77
|
-
|
|
78
|
-
And using `pythonfmu3 deploy`, end users will be able to update their local Python environment. The steps to achieve that:
|
|
79
|
-
|
|
80
|
-
1. Install _pythonfmu_ package: `pip install pythonfmu3`
|
|
81
|
-
2. Be sure to be in the Python environment to be updated. Then execute `pythonfmu3 deploy -f my.fmu`
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
usage: pythonfmu3 deploy [-h] -f FMU [-e ENVIRONMENT] [{pip,conda}]
|
|
85
|
-
|
|
86
|
-
Deploy a Python FMU. The command will look in the `resources` folder for one of the following files:
|
|
87
|
-
`requirements.txt` or `environment.yml`. If you specify a environment file but no package manager, `conda` will be selected for `.yaml` and `.yml` otherwise `pip` will be used. The tool assume the Python environment in which the FMU should be executed is the current one.
|
|
88
|
-
|
|
89
|
-
positional arguments:
|
|
90
|
-
{pip,conda} Python packages manager
|
|
91
|
-
|
|
92
|
-
optional arguments:
|
|
93
|
-
-h, --help show this help message and exit
|
|
94
|
-
-f FMU, --file FMU Path to the Python FMU.
|
|
95
|
-
-e ENVIRONMENT, --env ENVIRONMENT
|
|
96
|
-
Requirements or environment file.
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Example:
|
|
100
|
-
|
|
101
|
-
#### Write the script
|
|
102
|
-
|
|
103
|
-
```python
|
|
104
|
-
|
|
105
|
-
from pythonfmu3 import Fmi3Causality, Fmi3Slave, Boolean, Int32, Float64, String
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
class PythonSlave(Fmi3Slave):
|
|
109
|
-
|
|
110
|
-
def __init__(self, **kwargs):
|
|
111
|
-
super().__init__(**kwargs)
|
|
112
|
-
|
|
113
|
-
self.author = "John Doe"
|
|
114
|
-
self.description = "A simple description"
|
|
115
|
-
|
|
116
|
-
self.time = 0.0
|
|
117
|
-
self.intOut = 1
|
|
118
|
-
self.realOut = 3.0
|
|
119
|
-
self.booleanVariable = True
|
|
120
|
-
self.stringVariable = "Hello World!"
|
|
121
|
-
self.register_variable(Float64("time", causality=Fmi3Causality.independent))
|
|
122
|
-
self.register_variable(Int32("intOut", causality=Fmi3Causality.output))
|
|
123
|
-
self.register_variable(Float64("realOut", causality=Fmi3Causality.output))
|
|
124
|
-
self.register_variable(Boolean("booleanVariable", causality=Fmi3Causality.local))
|
|
125
|
-
self.register_variable(String("stringVariable", causality=Fmi3Causality.local))
|
|
126
|
-
|
|
127
|
-
# Note:
|
|
128
|
-
# it is also possible to explicitly define getters and setters as lambdas in case the variable is not backed by a Python field.
|
|
129
|
-
# self.register_variable(Float64("myReal", causality=Fmi3Causality.output, getter=lambda: self.realOut, setter=lambda v: set_real_out(v))
|
|
130
|
-
|
|
131
|
-
def do_step(self, current_time, step_size):
|
|
132
|
-
return True
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
#### Create the FMU
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
pythonfmu3 build -f pythonslave.py myproject
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
In this example a python class named `PythonSlave` that extends `Fmi3Slave` is declared in a file named `pythonslave.py`,
|
|
143
|
-
where `myproject` is an optional folder containing additional project files required by the python script.
|
|
144
|
-
Project folders such as this will be recursively copied into the FMU. Multiple project files/folders may be added.
|
|
1
|
+
# PythonFMU3
|
|
2
|
+
|
|
3
|
+
> A lightweight framework that enables the packaging of Python 3 code as co-simulation FMUs (following FMI version 3.0).
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/StephenSmith25/PythonFMU3/issues)
|
|
7
|
+
|
|
8
|
+
[](https://github.com/StephenSmith25/PythonFMU3/actions?query=workflow%3ACI)
|
|
9
|
+
[](https://pypi.org/project/pythonfmu3/)
|
|
10
|
+
[](https://pythonfmu3.readthedocs.io/)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
This project is a fork of the original PythonFMU repository available at https://github.com/NTNU-IHB/PythonFMU, which was used as the basis for adding support for FMI 3.0. While we have made efforts to expand the functionality of this project, it currently has some limitations and does not support all the features of FMI 3.0. We would like to acknowledge and give credit to the original PythonFMU project for their contributions to this work.
|
|
14
|
+
|
|
15
|
+
### Support:
|
|
16
|
+
|
|
17
|
+
Please take a look at the examples to see the supported features.
|
|
18
|
+
|
|
19
|
+
### Future
|
|
20
|
+
|
|
21
|
+
In no particular order, we plan to add support for:
|
|
22
|
+
|
|
23
|
+
- Support more variable types from FMI3
|
|
24
|
+
- Improve array support
|
|
25
|
+
- Add event mode
|
|
26
|
+
|
|
27
|
+
### How do I build an FMU from python code?
|
|
28
|
+
|
|
29
|
+
1. Install `pythonfmu3` package:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install pythonfmu3
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
|
|
36
|
+
3. Run `pythonfmu3 build` to create the fmu.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
usage: pythonfmu3 build [-h] -f SCRIPT_FILE [-d DEST] [--doc DOCUMENTATION_FOLDER] [--terminals TERMINALS_FILE] [--no-external-tool]
|
|
40
|
+
[--no-variable-step] [--interpolate-inputs] [--only-one-per-process] [--handle-state]
|
|
41
|
+
[--serialize-state] [--use-memory-management]
|
|
42
|
+
[Project files [Project files ...]]
|
|
43
|
+
|
|
44
|
+
Build an FMU from a Python script.
|
|
45
|
+
|
|
46
|
+
positional arguments:
|
|
47
|
+
Project files Additional project files required by the Python script.
|
|
48
|
+
|
|
49
|
+
optional arguments:
|
|
50
|
+
-h, --help show this help message and exit
|
|
51
|
+
-f SCRIPT_FILE, --file SCRIPT_FILE
|
|
52
|
+
Path to the Python script.
|
|
53
|
+
-d DEST, --dest DEST Where to save the FMU.
|
|
54
|
+
--doc DOCUMENTATION_FOLDER
|
|
55
|
+
Documentation folder to include in the FMU.
|
|
56
|
+
--terminals TERMINALS_FILE
|
|
57
|
+
Terminals file (terminalsAndIcons.xml) to include in the FMU.
|
|
58
|
+
--no-external-tool If given, needsExecutionTool=false
|
|
59
|
+
--no-variable-step If given, canHandleVariableCommunicationStepSize=false
|
|
60
|
+
--interpolate-inputs If given, canInterpolateInputs=true
|
|
61
|
+
--only-one-per-process
|
|
62
|
+
If given, canBeInstantiatedOnlyOncePerProcess=true
|
|
63
|
+
--handle-state If given, canGetAndSetFMUstate=true
|
|
64
|
+
--serialize-state If given, canSerializeFMUstate=true
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### How do I build an FMU from python code with third-party dependencies?
|
|
68
|
+
|
|
69
|
+
Often, Python scripts depends on non-builtin libraries like `numpy`, `scipy`, etc.
|
|
70
|
+
_PythonFMU_ does not package a full environment within the FMU.
|
|
71
|
+
However, you can package a `requirements.txt` or `environment.yml` file within your FMU following these steps:
|
|
72
|
+
|
|
73
|
+
1. Install _pythonfmu_ package: `pip install pythonfmu3`
|
|
74
|
+
2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
|
|
75
|
+
3. Create a `requirements.txt` file (to use _pip_ manager) and/or a `environment.yml` file (to use _conda_ manager) that defines your dependencies.
|
|
76
|
+
4. Run `pythonfmu3 build -f myscript.py requirements.txt` to create the fmu including the dependencies file.
|
|
77
|
+
|
|
78
|
+
And using `pythonfmu3 deploy`, end users will be able to update their local Python environment. The steps to achieve that:
|
|
79
|
+
|
|
80
|
+
1. Install _pythonfmu_ package: `pip install pythonfmu3`
|
|
81
|
+
2. Be sure to be in the Python environment to be updated. Then execute `pythonfmu3 deploy -f my.fmu`
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
usage: pythonfmu3 deploy [-h] -f FMU [-e ENVIRONMENT] [{pip,conda}]
|
|
85
|
+
|
|
86
|
+
Deploy a Python FMU. The command will look in the `resources` folder for one of the following files:
|
|
87
|
+
`requirements.txt` or `environment.yml`. If you specify a environment file but no package manager, `conda` will be selected for `.yaml` and `.yml` otherwise `pip` will be used. The tool assume the Python environment in which the FMU should be executed is the current one.
|
|
88
|
+
|
|
89
|
+
positional arguments:
|
|
90
|
+
{pip,conda} Python packages manager
|
|
91
|
+
|
|
92
|
+
optional arguments:
|
|
93
|
+
-h, --help show this help message and exit
|
|
94
|
+
-f FMU, --file FMU Path to the Python FMU.
|
|
95
|
+
-e ENVIRONMENT, --env ENVIRONMENT
|
|
96
|
+
Requirements or environment file.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Example:
|
|
100
|
+
|
|
101
|
+
#### Write the script
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
|
|
105
|
+
from pythonfmu3 import Fmi3Causality, Fmi3Slave, Boolean, Int32, Float64, String
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class PythonSlave(Fmi3Slave):
|
|
109
|
+
|
|
110
|
+
def __init__(self, **kwargs):
|
|
111
|
+
super().__init__(**kwargs)
|
|
112
|
+
|
|
113
|
+
self.author = "John Doe"
|
|
114
|
+
self.description = "A simple description"
|
|
115
|
+
|
|
116
|
+
self.time = 0.0
|
|
117
|
+
self.intOut = 1
|
|
118
|
+
self.realOut = 3.0
|
|
119
|
+
self.booleanVariable = True
|
|
120
|
+
self.stringVariable = "Hello World!"
|
|
121
|
+
self.register_variable(Float64("time", causality=Fmi3Causality.independent))
|
|
122
|
+
self.register_variable(Int32("intOut", causality=Fmi3Causality.output))
|
|
123
|
+
self.register_variable(Float64("realOut", causality=Fmi3Causality.output))
|
|
124
|
+
self.register_variable(Boolean("booleanVariable", causality=Fmi3Causality.local))
|
|
125
|
+
self.register_variable(String("stringVariable", causality=Fmi3Causality.local))
|
|
126
|
+
|
|
127
|
+
# Note:
|
|
128
|
+
# it is also possible to explicitly define getters and setters as lambdas in case the variable is not backed by a Python field.
|
|
129
|
+
# self.register_variable(Float64("myReal", causality=Fmi3Causality.output, getter=lambda: self.realOut, setter=lambda v: set_real_out(v))
|
|
130
|
+
|
|
131
|
+
def do_step(self, current_time, step_size):
|
|
132
|
+
return True
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Create the FMU
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
pythonfmu3 build -f pythonslave.py myproject
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
In this example a python class named `PythonSlave` that extends `Fmi3Slave` is declared in a file named `pythonslave.py`,
|
|
143
|
+
where `myproject` is an optional folder containing additional project files required by the python script.
|
|
144
|
+
Project folders such as this will be recursively copied into the FMU. Multiple project files/folders may be added.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from ._version import __version__
|
|
2
|
-
from .builder import FmuBuilder
|
|
3
|
-
from .enums import Fmi3Causality, Fmi3Initial, Fmi3Status, Fmi3Variability
|
|
4
|
-
from .fmi3slave import Fmi3Slave, Fmi3StepResult
|
|
5
|
-
from .variables import Boolean, Enumeration, Int32, Int64, UInt64, Float64, String, Dimension
|
|
6
|
-
from .default_experiment import DefaultExperiment
|
|
7
|
-
from .variable_types import Float64Type, EnumerationType
|
|
8
|
-
from .unit import BaseUnit, Unit
|
|
1
|
+
from ._version import __version__
|
|
2
|
+
from .builder import FmuBuilder
|
|
3
|
+
from .enums import Fmi3Causality, Fmi3Initial, Fmi3Status, Fmi3Variability
|
|
4
|
+
from .fmi3slave import Fmi3Slave, Fmi3StepResult
|
|
5
|
+
from .variables import Boolean, Enumeration, Int32, Int64, UInt64, Float64, String, Dimension
|
|
6
|
+
from .default_experiment import DefaultExperiment
|
|
7
|
+
from .variable_types import Float64Type, EnumerationType
|
|
8
|
+
from .unit import BaseUnit, Unit
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
|
|
3
|
-
from pythonfmu3 import builder, deploy
|
|
4
|
-
from ._version import __version__
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def cli_main():
|
|
8
|
-
parser = argparse.ArgumentParser(prog="pythonfmu")
|
|
9
|
-
|
|
10
|
-
parser.add_argument("-V", "--version", action="version", version=__version__)
|
|
11
|
-
|
|
12
|
-
def default_execution(**kwargs):
|
|
13
|
-
print("A subcommand must be provided.\n")
|
|
14
|
-
parser.print_help()
|
|
15
|
-
|
|
16
|
-
parser.set_defaults(execute=default_execution)
|
|
17
|
-
|
|
18
|
-
subparsers = parser.add_subparsers(
|
|
19
|
-
title="Subcommands", description="Call `pythonfmu _command_ -h` to get more help."
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
build_parser = subparsers.add_parser(
|
|
23
|
-
"build",
|
|
24
|
-
description="Build an FMU from a Python script.",
|
|
25
|
-
help="Build an FMU from a Python script."
|
|
26
|
-
)
|
|
27
|
-
builder.create_command_parser(build_parser)
|
|
28
|
-
|
|
29
|
-
deploy_parser = subparsers.add_parser(
|
|
30
|
-
"deploy",
|
|
31
|
-
description="""Deploy a Python FMU.
|
|
32
|
-
|
|
33
|
-
The command will look in the `resources` folder for one of the following files:
|
|
34
|
-
`requirements.txt` or `environment.yml`.
|
|
35
|
-
|
|
36
|
-
If you specify a environment file but no package manager, `conda` will be selected
|
|
37
|
-
for `.yaml` and `.yml` otherwise `pip` will be used.
|
|
38
|
-
|
|
39
|
-
The tool assume the Python environment in which the FMU should be executed
|
|
40
|
-
is the current one.
|
|
41
|
-
""",
|
|
42
|
-
help="Install Python FMU dependencies."
|
|
43
|
-
)
|
|
44
|
-
deploy.create_command_parser(deploy_parser)
|
|
45
|
-
|
|
46
|
-
options = vars(parser.parse_args())
|
|
47
|
-
execute = options.pop("execute")
|
|
48
|
-
execute(**options)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if __name__ == "__main__":
|
|
52
|
-
cli_main()
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
from pythonfmu3 import builder, deploy
|
|
4
|
+
from ._version import __version__
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def cli_main():
|
|
8
|
+
parser = argparse.ArgumentParser(prog="pythonfmu")
|
|
9
|
+
|
|
10
|
+
parser.add_argument("-V", "--version", action="version", version=__version__)
|
|
11
|
+
|
|
12
|
+
def default_execution(**kwargs):
|
|
13
|
+
print("A subcommand must be provided.\n")
|
|
14
|
+
parser.print_help()
|
|
15
|
+
|
|
16
|
+
parser.set_defaults(execute=default_execution)
|
|
17
|
+
|
|
18
|
+
subparsers = parser.add_subparsers(
|
|
19
|
+
title="Subcommands", description="Call `pythonfmu _command_ -h` to get more help."
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
build_parser = subparsers.add_parser(
|
|
23
|
+
"build",
|
|
24
|
+
description="Build an FMU from a Python script.",
|
|
25
|
+
help="Build an FMU from a Python script."
|
|
26
|
+
)
|
|
27
|
+
builder.create_command_parser(build_parser)
|
|
28
|
+
|
|
29
|
+
deploy_parser = subparsers.add_parser(
|
|
30
|
+
"deploy",
|
|
31
|
+
description="""Deploy a Python FMU.
|
|
32
|
+
|
|
33
|
+
The command will look in the `resources` folder for one of the following files:
|
|
34
|
+
`requirements.txt` or `environment.yml`.
|
|
35
|
+
|
|
36
|
+
If you specify a environment file but no package manager, `conda` will be selected
|
|
37
|
+
for `.yaml` and `.yml` otherwise `pip` will be used.
|
|
38
|
+
|
|
39
|
+
The tool assume the Python environment in which the FMU should be executed
|
|
40
|
+
is the current one.
|
|
41
|
+
""",
|
|
42
|
+
help="Install Python FMU dependencies."
|
|
43
|
+
)
|
|
44
|
+
deploy.create_command_parser(deploy_parser)
|
|
45
|
+
|
|
46
|
+
options = vars(parser.parse_args())
|
|
47
|
+
execute = options.pop("execute")
|
|
48
|
+
execute(**options)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
cli_main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.2.2"
|