Skip to content

Commit

Permalink
Added an optional argument to SimulatorInterface and to the cases spe…
Browse files Browse the repository at this point in the history
…cification to tune the CosimLogLevel setting. The level is set to FATAL per default
  • Loading branch information
eisDNV committed Nov 5, 2024
1 parent fed5415 commit c31dcc3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/source/cases_specification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ The following header section elements (denoted as `header-lines` above) are defi
* If no `CosimExecution` object is provided, but a `OspSystemStructure.xml` file is found in the same folder as the `.cases` file,
this file is assumed as the system definition file and a `CosimExecution` object is instantiated internally.
* A system structure file can be explicitly specified and will be used to generate a `CosimExecution` object.
*logLevel* (optional)
Log level of the simulator. Per default the level is set to FATAL,
but it can be set to TRACE, DEBUG, INFO, WARNING, ERROR or FATAL (e.g. for debugging purposes)
*timeUnit* (optional)
The unit of time the independent variable relates to, e.g. "second"
*variables* (mandatory)
Expand Down
5 changes: 4 additions & 1 deletion sim_explorer/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from typing import Any, Callable

from libcosimpy.CosimLogging import log_output_level, CosimLogLevel
import matplotlib.pyplot as plt
import numpy as np

Expand Down Expand Up @@ -530,7 +531,7 @@ def __init__(self, spec: str | Path, simulator: SimulatorInterface | None = None
self.file = Path(spec) # everything relative to the folder of this file!
assert self.file.exists(), f"Cases spec file {spec} not found"
self.js = Json5(spec)
# self.spec = self.js.js_py
log_level = CosimLogLevel[self.js.jspath("$.header.logLevel") or "FATAL"]
if simulator is None:
modelfile = self.js.jspath("$.header.modelFile", str) or "OspSystemStructure.xml"
path = self.file.parent / modelfile
Expand All @@ -540,11 +541,13 @@ def __init__(self, spec: str | Path, simulator: SimulatorInterface | None = None
system=path,
name=self.js.jspath("$.header.name", str) or "",
description=self.js.jspath("$.header.description", str) or "",
log_level = log_level,
)
except Exception as err:
raise AssertionError(f"'modelFile' needed from spec: {err}") from err
else:
self.simulator = simulator # SimulatorInterface( simulator = simulator)
log_output_level( log_level)

self.timefac = self._get_time_unit() * 1e9 # internally OSP uses pico-seconds as integer!
# read the 'variables' section and generate dict { alias : { (instances), (variables)}}:
Expand Down
5 changes: 5 additions & 0 deletions sim_explorer/simulator_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from zipfile import BadZipFile, ZipFile, is_zipfile

from libcosimpy.CosimEnums import CosimVariableCausality, CosimVariableType, CosimVariableVariability # type: ignore
from libcosimpy.CosimLogging import log_output_level, CosimLogLevel
from libcosimpy.CosimExecution import CosimExecution # type: ignore
from libcosimpy.CosimManipulator import CosimManipulator # type: ignore
from libcosimpy.CosimObserver import CosimObserver # type: ignore
Expand Down Expand Up @@ -65,6 +66,8 @@ class SimulatorInterface:
description (str)="": Optional possibility to provide a system description
simulator (CosimExecution)=None: Optional possibility to insert an existing simulator object.
Otherwise this is generated through CosimExecution.from_osp_config_file().
log_level (CosimLogLevel): Per default the level is set to FATAL,
but it can be set to TRACE, DEBUG, INFO, WARNING, ERROR or FATAL (e.g. for debugging purposes)
"""

simulator: CosimExecution
Expand All @@ -75,6 +78,7 @@ def __init__(
name: str | None = None,
description: str = "",
simulator: CosimExecution | None = None,
log_level: CosimLogLevel = CosimLogLevel.FATAL,
):
self.name = name # overwrite if the system includes that
self.description = description # overwrite if the system includes that
Expand All @@ -87,6 +91,7 @@ def __init__(
self.simulator = self._simulator_from_config(self.sysconfig)
else:
self.simulator = simulator
log_output_level( log_level)
self.components = self.get_components() # dict of {component name : modelId}
# Instantiate a suitable manipulator for changing variables.
self.manipulator = CosimManipulator.create_override()
Expand Down

0 comments on commit c31dcc3

Please sign in to comment.