cosapp.core.module¶
Basic class handling model tree structure.
Classes
|
A class to describe generic properties and functions of a component that can be single or made of child Module. |
- class cosapp.core.module.Module(name: str)[source]¶
Bases:
LoggerContext
,Component
A class to describe generic properties and functions of a component that can be single or made of child Module.
- Parameters:
[str] (- name) – Module name
- - name [str]
Module name
- - children [dict[str, Module]]
Sub-modules of current Module, referenced by names.
- - parent [Module]
Parent Module of current Module; None if there is no parent.
- - exec_order [Iterator[str]]
Execution order in which sub-modules should be computed.
- - description [str]
Module description.
- - _active [bool]
If False, the Module will not execute its run_once method
- - _compute_calls [int]
Store if the number of times
compute()
was called (due to inhibition of clean status)
- Signals¶
- -------
- - setup_ran [Signal]
Signal emitted after
call_setup_run()
execution
- - computed [Signal]
Signal emitted after the
compute()
stack (= after_post_compute()
) execution
- - clean_ran [Signal]
Signal emitted after the
call_clean_run()
execution
- add_child(child: Child, execution_index: int | None = None, desc='') Child [source]¶
Add a child Module to the current Module.
When adding a child Module, it is possible to specified its position in the execution order.
- Parameters:
[Module] (- child) – Module to add to the current Module
[int (- execution_index) – Index of the execution order list at which the Module should be inserted; default latest.
optional] – Index of the execution order list at which the Module should be inserted; default latest.
[str (- desc) – Module description in the context of its parent module.
optional] – Module description in the context of its parent module.
- Return type:
child
- clean_ran¶
- compute_before() None [source]¶
Contains the customized Module calculation, to execute before children.
- property compute_calls: int¶
Number of calls to the compute method at last execution.
- Type:
int
- computed¶
- property contextual_name: str¶
Name of the module relative to the root one.
- Type:
str
- property description: str¶
Module description
- Type:
str
- property exec_order: MappingView[str]¶
sub-module execution order, as a name iterator
- Type:
MappingView[str]
- full_name(trim_root=False) str [source]¶
Returns full name from root Module.
- Parameters:
trim_root (bool (optional, default False)) – Exclude root Module name if True.
- Returns:
The module full name
- Return type:
str
- get_path_to_child(other: Module, trim_top=True) str [source]¶
Returns the relative path to target Module other. Raises ValueError if other is not related to current Module.
Parameters:¶
- other [Module]:
sub-module of module tree.
- trim_top [boll, optional]:
if True, the name of the top module (self) is added to the path. Default is False.
- returns:
str
- rtype:
The relative path to other
- is_active() bool [source]¶
Is this Module execution activated?
- Returns:
Activation status
- Return type:
bool
- abstract is_standalone() bool [source]¶
Is this Module able to solve itself?
- Returns:
Ability to solve the module or not.
- Return type:
bool
- log_debug_message(handler: HandlerWithContextFilters, record: logging.LogRecord, format: LogFormat = LogFormat.RAW) bool [source]¶
Callback method on the module to log more detailed information.
This method will be called by the log handler when
log_context()
is active if the logging level is lower or equals to VERBOSE_LEVEL. It allows the object to send additional log message to help debugging a simulation.Note
logger.log method cannot be used here. Use handler.handle(record)
- Parameters:
handler (HandlerWithContextFilters) – Log handler on which additional message should be published.
record (logging.LogRecord) – Log record
format (LogFormat) – Format of the message
- Returns:
Should the provided record be logged?
- Return type:
bool
- property name: str¶
Module identifier.
- Type:
str
- path() List[Module] [source]¶
Returns full path from root Module as a list.
- Returns:
Full module list from root to self
- Return type:
List[Module]
- path_namelist() List[str] [source]¶
Returns full name list from root Module.
- Returns:
The module full name list
- Return type:
List[str]
- path_to_root() Generator[Module, None, None] [source]¶
Generator recursively yielding all elements up to root module.
- pop_child(name: str) Module [source]¶
Remove submodule name from current module.
- Parameters:
name (str) – Name of submodule to be removed.
- Returns:
The removed module.
- Return type:
Module
- Raises:
AttributeError –
- run_once() None [source]¶
Run the module once.
Execute the model of this Module and its children in the execution order.
Notes
The driver are not executed when calling this method; only the physical model.
- send_visitor(visitor: Visitor, downwards=False) None [source]¶
Recursively accept visitor throughout module tree.
- setup_ran¶
- property size: int¶
Total number of elements in tree.
- Type:
int