Skip to content

Commit

Permalink
Feature/0.6.2 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren authored Feb 24, 2021
1 parent 241f52b commit 65bd445
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ jobs:
matrix:
os: [ubuntu-18.04, windows-2019]
python-version: [3.7, 3.8, 3.9]

timeout-minutes: 20

steps:
- uses: actions/checkout@v2

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ optional arguments:
If given, canBeInstantiatedOnlyOncePerProcess=true
--handle-state If given, canGetAndSetFMUstate=true
--serialize-state If given, canSerializeFMUstate=true
--use-memory-management
If given, canNotUseMemoryManagementFunctions=false
```

### How do I build an FMU from python code with third-party dependencies?

Often, Python scripts depends on non-builtin libraries like `numpy`, `scipy`, etc.
_PythonFMU_ does not package a full environment within the FMU.
However you can package a `requirements.txt` or `environment.yml` file within your FMU following these steps:
However, you can package a `requirements.txt` or `environment.yml` file within your FMU following these steps:

1. Install _pythonfmu_ package: `pip install pythonfmu`
2. Create a new class extending the `Fmi2Slave` class declared in the `pythonfmu.fmi2slave` module (see below for an example).
Expand Down Expand Up @@ -154,4 +152,6 @@ Need to distribute your FMUs? [FMU-proxy](https://github.com/NTNU-IHB/FMU-proxy)

### Credits

This works has been possible thanks to the contributions of @markaren from NTNU-IHB and @fcollonval from Safran SA.
This work has been possible thanks to the contributions of: <br>
@markaren from NTNU-IHB <br>
@fcollonval from Safran SA.
1 change: 1 addition & 0 deletions pythonfmu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .enums import Fmi2Causality, Fmi2Initial, Fmi2Variability
from .fmi2slave import Fmi2Slave
from .variables import Boolean, Integer, Real, String
from .default_experiment import DefaultExperiment
2 changes: 1 addition & 1 deletion pythonfmu/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.1"
__version__ = "0.6.2"
6 changes: 6 additions & 0 deletions pythonfmu/default_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class DefaultExperiment:

def __init__(self, start_time: float = None, stop_time: float = None, tolerance: float = None):
self.start_time = start_time
self.stop_time = stop_time
self.tolerance = tolerance
20 changes: 15 additions & 5 deletions pythonfmu/fmi2slave.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from typing import Any, ClassVar, Dict, List, Optional
from uuid import uuid1
from xml.etree.ElementTree import Element, SubElement
from ctypes import cdll, c_char_p, c_void_p, c_int, c_bool

from .logmsg import LogMsg
from .osutil import get_lib_extension, get_platform
from .default_experiment import DefaultExperiment
from ._version import __version__ as VERSION
from .enums import Fmi2Type, Fmi2Status, Fmi2Causality, Fmi2Initial, Fmi2Variability
from .variables import Boolean, Integer, Real, ScalarVariable, String
Expand All @@ -23,8 +22,7 @@
ModelOptions("canInterpolateInputs", False, "interpolate-inputs"),
ModelOptions("canBeInstantiatedOnlyOncePerProcess", False, "only-one-per-process"),
ModelOptions("canGetAndSetFMUstate", False, "handle-state"),
ModelOptions("canSerializeFMUstate", False, "serialize-state"),
ModelOptions("canNotUseMemoryManagementFunctions", True, "use-memory-management")
ModelOptions("canSerializeFMUstate", False, "serialize-state")
]


Expand All @@ -38,6 +36,7 @@ class Fmi2Slave(ABC):
copyright: ClassVar[Optional[str]] = None
modelName: ClassVar[Optional[str]] = None
description: ClassVar[Optional[str]] = None
default_experiment: ClassVar[Optional[DefaultExperiment]] = None

# Dictionary of (category, description) entries
log_categories: Dict[str, str] = {
Expand Down Expand Up @@ -97,6 +96,7 @@ def to_xml(self, model_options: Dict[str, str] = dict()) -> Element:
value = model_options.get(option.name, option.value)
options[option.name] = str(value).lower()
options["modelIdentifier"] = self.modelName
options["canNotUseMemoryManagementFunctions"] = "true"

SubElement(root, "CoSimulation", attrib=options)

Expand Down Expand Up @@ -127,6 +127,16 @@ def to_xml(self, model_options: Dict[str, str] = dict()) -> Element:
if v.causality == Fmi2Causality.output:
SubElement(outputs_node, "Unknown", attrib=dict(index=str(i + 1)))

if self.default_experiment is not None:
attrib = dict()
if self.default_experiment.start_time is not None:
attrib["startTime"] = self.default_experiment.start_time
if self.default_experiment.stop_time is not None:
attrib["stopTime"] = self.default_experiment.stop_time
if self.default_experiment.tolerance is not None:
attrib["tolerance"] = self.default_experiment.tolerance
SubElement(root, "DefaultExperiment", attrib)

return root

def __apply_start_value(self, var: ScalarVariable):
Expand Down Expand Up @@ -157,7 +167,7 @@ def register_variable(self, var: ScalarVariable, nested: bool = True):
# Set the unique value reference
var.value_reference = variable_reference
owner = self
if nested and "." in var.name:
if var.getter is None and nested and "." in var.name:
split = var.name.split(".")
split.pop(-1)
for s in split:
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

0 comments on commit 65bd445

Please sign in to comment.