cosapp.core.module

Basic class handling model tree structure.

Classes

Module(name)

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.Component

A class to describe generic properties and functions of a component that can be single or made of child Module.

Parameters

name [str] (-) – 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: Optional[int] = 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
  • child [Module] (-) – Module to add to the current Module

  • execution_index [int (-) – 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.

  • desc [str (-) – Module description in the context of its parent module.

  • optional] – Module description in the context of its parent module.

Returns

Return type

child

call_clean_run()[source]

Execute clean_run recursively on all modules.

call_setup_run()[source]

Execute setup_run recursively on all modules.

children
clean_ran
clean_run()[source]

Method called once after any simulation.

compute()None[source]

Contains the customized Module calculation, to execute after children.

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 description

Module description

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
setup_run()[source]

Method called once before starting any simulation.

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.