pythonfmu3 0.2.2.2__tar.gz → 0.2.3__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.
Files changed (66) hide show
  1. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/LICENSE +23 -23
  2. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/MANIFEST.in +8 -8
  3. pythonfmu3-0.2.3/PKG-INFO +171 -0
  4. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/README.md +144 -144
  5. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/__init__.py +8 -8
  6. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/__main__.py +52 -52
  7. pythonfmu3-0.2.3/pythonfmu3/_version.py +1 -0
  8. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/builder.py +260 -260
  9. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/default_experiment.py +7 -7
  10. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/deploy.py +118 -118
  11. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/enums.py +48 -48
  12. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/fmi3slave.py +438 -438
  13. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/logmsg.py +14 -14
  14. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/osutil.py +22 -22
  15. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/.clang-format +35 -35
  16. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/CMakeLists.txt +59 -59
  17. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/build_unix.sh +4 -4
  18. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/build_win.sh +4 -4
  19. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/CMakeLists.txt +45 -45
  20. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_common.hpp +161 -161
  21. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.cpp +192 -192
  22. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.hpp +185 -185
  23. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/cppfmu/fmi_functions.cpp +937 -937
  24. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/fmi/fmi3FunctionTypes.h +638 -638
  25. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/fmi/fmi3Functions.h +343 -343
  26. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/fmi/fmi3PlatformTypes.h +94 -94
  27. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/pythonfmu/IPyState.hpp +17 -17
  28. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.cpp +744 -744
  29. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.hpp +111 -111
  30. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/pythonfmu-export/src/pythonfmu/PyState.hpp +84 -84
  31. pythonfmu3-0.2.3/pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so +0 -0
  32. pythonfmu3-0.2.3/pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll +0 -0
  33. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/conftest.py +5 -5
  34. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/data/csvdemo.csv +7 -7
  35. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/slaves/PythonSlaveWithException.py +18 -18
  36. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/slaves/localmodule.py +8 -8
  37. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/slaves/pythonslave.py +52 -52
  38. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/slaves/pythonslave_read_file.py +23 -23
  39. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/slaves/slavewithdep.py +21 -21
  40. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_builder.py +195 -195
  41. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_deploy.py +48 -48
  42. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_fmi3slave.py +152 -152
  43. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_integration.py +350 -350
  44. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_logger.py +180 -180
  45. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_multiple_fmus.py +141 -141
  46. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/test_variables.py +334 -334
  47. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/utils.py +13 -13
  48. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/unit.py +62 -62
  49. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/variable_types.py +101 -101
  50. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/variables.py +400 -400
  51. pythonfmu3-0.2.3/pythonfmu3.egg-info/PKG-INFO +171 -0
  52. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3.egg-info/entry_points.txt +0 -1
  53. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3.egg-info/not-zip-safe +1 -1
  54. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/setup.py +4 -4
  55. pythonfmu3-0.2.2.2/PKG-INFO +0 -168
  56. pythonfmu3-0.2.2.2/pythonfmu3/_version.py +0 -1
  57. pythonfmu3-0.2.2.2/pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so +0 -0
  58. pythonfmu3-0.2.2.2/pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll +0 -0
  59. pythonfmu3-0.2.2.2/pythonfmu3.egg-info/PKG-INFO +0 -168
  60. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/__init__.py +0 -0
  61. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3/tests/data/hello.txt +0 -0
  62. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3.egg-info/SOURCES.txt +0 -0
  63. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3.egg-info/dependency_links.txt +0 -0
  64. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3.egg-info/requires.txt +0 -0
  65. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/pythonfmu3.egg-info/top_level.txt +0 -0
  66. {pythonfmu3-0.2.2.2 → pythonfmu3-0.2.3}/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,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythonfmu3
3
+ Version: 0.2.3
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
+ Keywords: FMI
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: End Users/Desktop
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Natural Language :: English
15
+ Classifier: Programming Language :: C++
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.6
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: tests
24
+ Requires-Dist: pytest; extra == "tests"
25
+ Requires-Dist: fmpy; extra == "tests"
26
+ Dynamic: license-file
27
+
28
+ # PythonFMU3
29
+
30
+ > A lightweight framework that enables the packaging of Python 3 code as co-simulation FMUs (following FMI version 3.0).
31
+
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
33
+ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/StephenSmith25/PythonFMU3/issues)
34
+
35
+ [![CI](https://github.com/StephenSmith25/PythonFMU3/workflows/CI/badge.svg)](https://github.com/StephenSmith25/PythonFMU3/actions?query=workflow%3ACI)
36
+ [![PyPI](https://img.shields.io/pypi/v/pythonfmu3)](https://pypi.org/project/pythonfmu3/)
37
+ [![Read the Docs](https://readthedocs.org/projects/pythonfmu3/badge/?version=latest)](https://pythonfmu3.readthedocs.io/)
38
+
39
+
40
+ 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.
41
+
42
+ ### Support:
43
+
44
+ Please take a look at the examples to see the supported features.
45
+
46
+ ### Future
47
+
48
+ In no particular order, we plan to add support for:
49
+
50
+ - Support more variable types from FMI3
51
+ - Improve array support
52
+ - Add event mode
53
+
54
+ ### How do I build an FMU from python code?
55
+
56
+ 1. Install `pythonfmu3` package:
57
+
58
+ ```bash
59
+ pip install pythonfmu3
60
+ ```
61
+
62
+ 2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
63
+ 3. Run `pythonfmu3 build` to create the fmu.
64
+
65
+ ```
66
+ usage: pythonfmu3 build [-h] -f SCRIPT_FILE [-d DEST] [--doc DOCUMENTATION_FOLDER] [--terminals TERMINALS_FILE] [--no-external-tool]
67
+ [--no-variable-step] [--interpolate-inputs] [--only-one-per-process] [--handle-state]
68
+ [--serialize-state] [--use-memory-management]
69
+ [Project files [Project files ...]]
70
+
71
+ Build an FMU from a Python script.
72
+
73
+ positional arguments:
74
+ Project files Additional project files required by the Python script.
75
+
76
+ optional arguments:
77
+ -h, --help show this help message and exit
78
+ -f SCRIPT_FILE, --file SCRIPT_FILE
79
+ Path to the Python script.
80
+ -d DEST, --dest DEST Where to save the FMU.
81
+ --doc DOCUMENTATION_FOLDER
82
+ Documentation folder to include in the FMU.
83
+ --terminals TERMINALS_FILE
84
+ Terminals file (terminalsAndIcons.xml) to include in the FMU.
85
+ --no-external-tool If given, needsExecutionTool=false
86
+ --no-variable-step If given, canHandleVariableCommunicationStepSize=false
87
+ --interpolate-inputs If given, canInterpolateInputs=true
88
+ --only-one-per-process
89
+ If given, canBeInstantiatedOnlyOncePerProcess=true
90
+ --handle-state If given, canGetAndSetFMUstate=true
91
+ --serialize-state If given, canSerializeFMUstate=true
92
+ ```
93
+
94
+ ### How do I build an FMU from python code with third-party dependencies?
95
+
96
+ Often, Python scripts depends on non-builtin libraries like `numpy`, `scipy`, etc.
97
+ _PythonFMU_ does not package a full environment within the FMU.
98
+ However, you can package a `requirements.txt` or `environment.yml` file within your FMU following these steps:
99
+
100
+ 1. Install _pythonfmu_ package: `pip install pythonfmu3`
101
+ 2. Create a new class extending the `Fmi3Slave` class declared in the `pythonfmu3.fmi3slave` module (see below for an example).
102
+ 3. Create a `requirements.txt` file (to use _pip_ manager) and/or a `environment.yml` file (to use _conda_ manager) that defines your dependencies.
103
+ 4. Run `pythonfmu3 build -f myscript.py requirements.txt` to create the fmu including the dependencies file.
104
+
105
+ And using `pythonfmu3 deploy`, end users will be able to update their local Python environment. The steps to achieve that:
106
+
107
+ 1. Install _pythonfmu_ package: `pip install pythonfmu3`
108
+ 2. Be sure to be in the Python environment to be updated. Then execute `pythonfmu3 deploy -f my.fmu`
109
+
110
+ ```
111
+ usage: pythonfmu3 deploy [-h] -f FMU [-e ENVIRONMENT] [{pip,conda}]
112
+
113
+ Deploy a Python FMU. The command will look in the `resources` folder for one of the following files:
114
+ `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.
115
+
116
+ positional arguments:
117
+ {pip,conda} Python packages manager
118
+
119
+ optional arguments:
120
+ -h, --help show this help message and exit
121
+ -f FMU, --file FMU Path to the Python FMU.
122
+ -e ENVIRONMENT, --env ENVIRONMENT
123
+ Requirements or environment file.
124
+ ```
125
+
126
+ ### Example:
127
+
128
+ #### Write the script
129
+
130
+ ```python
131
+
132
+ from pythonfmu3 import Fmi3Causality, Fmi3Slave, Boolean, Int32, Float64, String
133
+
134
+
135
+ class PythonSlave(Fmi3Slave):
136
+
137
+ def __init__(self, **kwargs):
138
+ super().__init__(**kwargs)
139
+
140
+ self.author = "John Doe"
141
+ self.description = "A simple description"
142
+
143
+ self.time = 0.0
144
+ self.intOut = 1
145
+ self.realOut = 3.0
146
+ self.booleanVariable = True
147
+ self.stringVariable = "Hello World!"
148
+ self.register_variable(Float64("time", causality=Fmi3Causality.independent))
149
+ self.register_variable(Int32("intOut", causality=Fmi3Causality.output))
150
+ self.register_variable(Float64("realOut", causality=Fmi3Causality.output))
151
+ self.register_variable(Boolean("booleanVariable", causality=Fmi3Causality.local))
152
+ self.register_variable(String("stringVariable", causality=Fmi3Causality.local))
153
+
154
+ # Note:
155
+ # it is also possible to explicitly define getters and setters as lambdas in case the variable is not backed by a Python field.
156
+ # self.register_variable(Float64("myReal", causality=Fmi3Causality.output, getter=lambda: self.realOut, setter=lambda v: set_real_out(v))
157
+
158
+ def do_step(self, current_time, step_size):
159
+ return True
160
+
161
+ ```
162
+
163
+ #### Create the FMU
164
+
165
+ ```
166
+ pythonfmu3 build -f pythonslave.py myproject
167
+ ```
168
+
169
+ In this example a python class named `PythonSlave` that extends `Fmi3Slave` is declared in a file named `pythonslave.py`,
170
+ where `myproject` is an optional folder containing additional project files required by the python script.
171
+ Project folders such as this will be recursively copied into the FMU. Multiple project files/folders may be added.
@@ -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
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
- [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/StephenSmith25/PythonFMU3/issues)
7
-
8
- [![CI](https://github.com/StephenSmith25/PythonFMU3/workflows/CI/badge.svg)](https://github.com/StephenSmith25/PythonFMU3/actions?query=workflow%3ACI)
9
- [![PyPI](https://img.shields.io/pypi/v/pythonfmu3)](https://pypi.org/project/pythonfmu3/)
10
- [![Read the Docs](https://readthedocs.org/projects/pythonfmu3/badge/?version=latest)](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
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/StephenSmith25/PythonFMU3/issues)
7
+
8
+ [![CI](https://github.com/StephenSmith25/PythonFMU3/workflows/CI/badge.svg)](https://github.com/StephenSmith25/PythonFMU3/actions?query=workflow%3ACI)
9
+ [![PyPI](https://img.shields.io/pypi/v/pythonfmu3)](https://pypi.org/project/pythonfmu3/)
10
+ [![Read the Docs](https://readthedocs.org/projects/pythonfmu3/badge/?version=latest)](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.3"