From 65bd4455341b82eb3fb388b9b654b55a54ddf8e6 Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Wed, 24 Feb 2021 10:29:36 +0100 Subject: [PATCH] Feature/0.6.2 (#113) --- .github/workflows/main.yml | 3 ++- README.md | 8 ++++---- pythonfmu/__init__.py | 1 + pythonfmu/_version.py | 2 +- pythonfmu/default_experiment.py | 6 ++++++ pythonfmu/fmi2slave.py | 20 +++++++++++++++----- requirements.txt | 3 --- 7 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 pythonfmu/default_experiment.py delete mode 100644 requirements.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4108cd80..97d91db3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/README.md b/README.md index 947b39c3..ae320833 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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:
+@markaren from NTNU-IHB
+@fcollonval from Safran SA. diff --git a/pythonfmu/__init__.py b/pythonfmu/__init__.py index a5128976..010886db 100644 --- a/pythonfmu/__init__.py +++ b/pythonfmu/__init__.py @@ -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 diff --git a/pythonfmu/_version.py b/pythonfmu/_version.py index 43c4ab00..22049ab2 100644 --- a/pythonfmu/_version.py +++ b/pythonfmu/_version.py @@ -1 +1 @@ -__version__ = "0.6.1" +__version__ = "0.6.2" diff --git a/pythonfmu/default_experiment.py b/pythonfmu/default_experiment.py new file mode 100644 index 00000000..817cf08d --- /dev/null +++ b/pythonfmu/default_experiment.py @@ -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 diff --git a/pythonfmu/fmi2slave.py b/pythonfmu/fmi2slave.py index 67a03b6d..87808290 100644 --- a/pythonfmu/fmi2slave.py +++ b/pythonfmu/fmi2slave.py @@ -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 @@ -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") ] @@ -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] = { @@ -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) @@ -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): @@ -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: diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b7a5eed8..00000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -fmpy -pyfmi -pytest \ No newline at end of file