Cases

class sim_explorer.case.Cases(spec: str | Path)

Bases: object

Global book-keeping of all cases defined for a system model.

  • Ensure uniqueness of case names

  • Access to system model information: system model, component models and instantiated component models information

  • Definition of variable aliases (used throughout the cases)

  • Definition of cases and their relation (case hierarchy)

Parameters:
  • spec (Path) – file name for cases specification

  • simulator_type (SystemInterface) – Optional possibility to choose system simulator details Default is OSP (libcosimpy), but when only results are read the basic SystemInterface is sufficient.

__init__(spec: str | Path) None

Methods

__init__(spec)

case_by_name(name)

Find the case 'name' amoung all defined cases.

case_variable(component, variables)

Identify the case variable (as defined in the spec) from the component instance and fmu variable names.

disect_variable(key[, err_level])

Extract the variable name, definition and explicit variable range, if relevant (multi-valued variables, where only some elements are addressed).

get_case_variables()

Read the 'variables' main key, which defines self.variables (case variables) as a dictionary.

get_starts()

Get a copy of the start values (as advised by FMU) as dict {case-var : (start-values), }.

info([case, level])

Show main information and the cases structure as string.

read_cases()

Instantiate all cases defined in the spec.

run_case(name[, dump, run_subs, run_assertions])

Initiate case run.

Attributes

case_by_name(name: str) Case | None

Find the case ‘name’ amoung all defined cases. Return None if not found.

Parameters:

name (str) – the case name to find

Returns:

The case object or None

case_variable(component: str, variables: str | tuple[str]) tuple[str, tuple[int, ...]]

Identify the case variable (as defined in the spec) from the component instance and fmu variable names.

disect_variable(key: str, err_level: int = 2) tuple[str, dict[str, Any] | None, list[int]]

Extract the variable name, definition and explicit variable range, if relevant (multi-valued variables, where only some elements are addressed). ToDo: handle multi-dimensional arrays (tables, …).

Parameters:

key (str) – The key as provided in case spec(, with [range] if provided).

Returns:

  • 1. The variable name as defined in the ‘variables’ section of the spec

  • 2. The variable definition, which the name refers to

  • 3. A tuple with indices of the variable, i.e. the range

get_case_variables() dict[str, dict[str, Any]]

Read the ‘variables’ main key, which defines self.variables (case variables) as a dictionary.

{ c_var_name{‘model’: model ID,

‘instances’: tuple of instance names, ‘names’: tuple of variable names, ‘refs’: tuple of ValueReferences ‘type’: python type, ‘causality’: causality (str), ‘variability’: variability (str), ‘initial’: initial (str) ‘start’: tuple of start values}.

Optionally a description of the alias variable may be provided (and added to the dictionary).

get_starts() dict[str, tuple[int | float | bool | str, ...]]

Get a copy of the start values (as advised by FMU) as dict {case-var : (start-values), }.

info(case: Case | None = None, level: int = 0) str

Show main information and the cases structure as string.

read_cases() None

Instantiate all cases defined in the spec. ‘base’ is defined firsts, since the others build on these Return the base case object. The others are linked as sub-cases in their parent cases. The ‘header’ is treated elsewhere.

run_case(name: str | Case, dump: str | None = '', *, run_subs: bool = False, run_assertions: bool = False) None

Initiate case run. If done from here, the case name can be chosen. If run_subs = True, also the sub-cases are run.

assertion: Assertion
base: Case
file: Path
js: Json5
results_print_type
simulator
spec
timefac: float
variables: dict[str, dict[str, Any]]