A lightweight framework that enables the packaging of Python3.x code as co-simulation FMUs.
Project description
PythonFMU (work in progress)
A lightweight framework that enables the packaging of Python3.x code as co-simulation FMUs.
How do I build an FMU from python code?
- Install
pythonfmu
package:
pip install git+https://github.com/NTNU-IHB/PythonFMU.git
- Create a new class extending the
Fmi2Slave
class declared in thepythonfmu.fmi2slave
module. - Run
pythonfmu-builder
to create the fmu.
usage: pythonfmu-builder [-h] -f SCRIPT_FILE [-d DEST]
[--doc DOCUMENTATION_FOLDER]
[Project files [Project files ...]]
Build a FMU from a Python script.
positional arguments:
Project files Additional project files required by the Python
script.
optional arguments:
-h, --help show this help message and exit
-f SCRIPT_FILE, --file SCRIPT_FILE
Path to the Python script.
-d DEST, --dest DEST Where to save the FMU.
--doc DOCUMENTATION_FOLDER
Documentation folder to include in the FMU.
Example:
Write the script
from pythonfmu import Fmi2Causality, Fmi2Slave, Boolean, Integer, Real, String
slave_class = "PythonSlave" # REQUIRED - Name of the class extending Fmi2Slave
class PythonSlave(Fmi2Slave):
author = "John Doe"
modelName = "PythonSlave" # REQUIRED
description = "A simple description"
def __init__(self):
super().__init__()
self.intOut = 1
self.realOut = 3.0
self.booleanVariable = True
self.stringVariable = "Hello World!"
self.register_variable(Integer("intOut", causality=Fmi2Causality.output))
self.register_variable(Real("realOut", causality=Fmi2Causality.output))
self.register_variable(Boolean("booleanVariable", causality=Fmi2Causality.local))
self.register_variable(String("stringVariable", causality=Fmi2Causality.local))
def do_step(self, current_time, step_size):
return True
Create the FMU
pythonfmu-builder -f pythonslave.py pythonfmu
In this example a python class named PythonSlave
that extends Fmi2Slave
is declared in a file named pythonslave.py
.
pythonfmu
is a optional folder containing additional project files required by the python script.
Project folders such as this will be recursively copied into the FMU. Multiple project files/folders may be added.
Note
PythonFMU does not bundle Python, which makes it a tool coupling solution. This means that you can not expect the generated FMU to work on a different system (The system would need a compatible Python version and libraries). But to ease its usage the wrapper is compile using
the limited Python API. So the provided binary libraries for Linux and Windows 64-bits should
be compatible of any Python 3 environment.
PythonFMU does not automatically resolve 3rd party dependencies either. If your code includes e.g. numpy
, the target system also needs to have numpy
installed.
Would you rather build FMUs in Java? Check out FMI4j!
Need to distribute your FMUs? FMU-proxy to the rescue!
Credits
This works has been possible thanks to the contributions of @markaren from NTNU-IHB and @fcollonval from Safran SA.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pythonfmu-0.3.0a0.tar.gz
.
File metadata
- Download URL: pythonfmu-0.3.0a0.tar.gz
- Upload date:
- Size: 202.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87bcacec0f8cb781d0295902293a8975c910b4a1cb399198bd5b7031ab2e603e |
|
MD5 | 8a22b7a356b706b6ed5faaaf77f72078 |
|
BLAKE2b-256 | 1f4a4b28ab154eeac467700717e6fca9576f738637db77b8eccd4877e31fac5a |
File details
Details for the file pythonfmu-0.3.0a0-py3-none-any.whl
.
File metadata
- Download URL: pythonfmu-0.3.0a0-py3-none-any.whl
- Upload date:
- Size: 212.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f380a8c41aa0abfafdf3f93dc58b4d750e63ca0d0f527300de069d34370f8308 |
|
MD5 | b9f2cf520a3f25d633ad17bc92eaf1b6 |
|
BLAKE2b-256 | 6b42d8c2f2e0e9fd4df0798d9ceb965b7c49755ee10f1b4044e99ccbbb0d2f34 |