Cases¶
- class sim_explorer.case.Cases(spec: str | Path, simulator: SimulatorInterface | None = None)¶
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 (SimulatorInterface) – Optional (pre-instantiated) SimulatorInterface object. If that is None, the spec shall contain a modelFile to be used to instantiate the simulator.
- __init__(spec: str | Path, simulator: SimulatorInterface | None = None)¶
Methods
__init__
(spec[, simulator])case_by_name
(name)Find the case 'name' amoung all defined cases.
case_var_by_ref
(comp, ref)Get the case variable name related to the component model comp and the reference ref Returns a tuple of case variable name and an index (if composit variable).
comp_refs_to_case_var
(comp, refs)Get the translation of the component id comp + references refs to the variable names used in the cases file.
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).
Read the 'variables' main key, which defines self.variables (case variables) as a dictionary.
info
([case, level])Show main infromation and the cases structure as string.
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_var_by_ref(comp: int | str, ref: int | tuple[int, ...]) tuple[str, tuple] ¶
Get the case variable name related to the component model comp and the reference ref Returns a tuple of case variable name and an index (if composit variable).
- comp_refs_to_case_var(comp: int, refs: tuple[int, ...])¶
Get the translation of the component id comp + references refs to the variable names used in the cases file. To speed up the process the cache dict _comp_refs_to_case_var_cache is used.
- disect_variable(key: str, err_level: int = 2) tuple[str, dict, list | range] ¶
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. An iterator over indices of the variable, i.e. the range
- get_case_variables() dict[str, dict] ¶
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, ‘variables’: tuple of ValueReference, ‘type’:CosimVariableType, ‘causality’:CosimVariableCausality, ‘variability’: CosimVariableVariability}.
Optionally a description of the alias variable may be provided (and added to the dictionary).
- info(case: Case | None = None, level: int = 0) str ¶
Show main infromation and the cases structure as string.
- read_cases()¶
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)¶
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_results: List[AssertionResult] = []¶
- base¶
- file¶
- js¶
- results_print_type¶
- simulator¶
- spec¶
- timefac¶
- variables¶