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:
cosapp.utils.logging.LoggerContext,cosapp.patterns.visitor.ComponentA class to describe generic properties and functions of a component that can be single or made of child Module.
- Parameters
name (str) – Name of the Module
-
name¶ Module name
- Type
str
-
exec_order¶ Execution order in which sub-modules should be computed.
- Type
MappingView[str]
-
_active¶ If False, the Module will not execute its run_once method
- Type
bool
-
_compute_calls¶ Store if the number of times
compute()was called (due to inhibition of clean status)- Type
int
-
Signals¶
-
-------
-
setup_ran¶ Signal emitted after
call_setup_run()execution- Type
Signal()
-
computed¶ Signal emitted after the
compute()stack (= after_post_compute()) execution- Type
Signal()
-
clean_ran¶ Signal emitted after the
call_clean_run()execution- Type
Signal()
-
add_child(child: Child, execution_index: Optional[int] = None) → 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
child (Module) – Module to add to the current Module
execution_index (int, optional) – Index of the execution order list at which the Module should be inserted; default latest.
-
children¶
-
clean_ran¶
-
compute_before() → None[source]¶ Contains the customized Module calculation, to execute before children.
-
property
compute_calls¶ Number of calls to the compute method at last execution.
- Type
int
-
computed¶
-
property
contextual_name¶ Name of the module relative to the root one.
- Type
str
-
property
exec_order¶ 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: cosapp.core.module.Module) → str[source]¶ Returns the relative path to target Module other. Raises ValueError if other is not related to current Module.
- Returns
The relative path to target
- Return type
Roots
-
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: 0>) → 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¶ Module identifier.
- Type
str
-
parent¶
-
path() → List[cosapp.core.module.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[cosapp.core.module.Module, None, None][source]¶ Generator recursively yielding all elements up to root module.
-
pop_child(name: str) → cosapp.core.module.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 –
-
root() → cosapp.core.module.Module[source]¶
-
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: cosapp.patterns.visitor.Visitor, downwards=False) → None[source]¶ Recursively accept visitor throughout module tree.
-
setup_ran¶
-
property
size¶ Total number of elements in tree.
- Type
int
-
tree(downwards=False) → Generator[cosapp.core.module.Module, None, None][source]¶ Generator recursively yielding all elements in module tree.
- downwards [bool, optional]:
If True, yields elements from top to bottom. If False (default), yields elements from bottom to top.