finam.Composition#

class finam.Composition(modules, logger_name='FINAM', print_log=True, log_file=None, log_level=20, slot_memory_limit=None, slot_memory_location='temp')[source]#

Bases: Loggable

A composition of linked components.

Manages initialization, initial connection and update schedule of components.

See Model coupling scripts for usage details.

Examples

comp_a = SomeComponent(...)
comp_b = AnotherComponent(...)

composition = Composition([comp_a, comp_b])
composition.initialize()

comp_b.outputs["Out"] >> SomeAdapter() >> comp_b.inputs["In"]

composition.run(end_time=...)
Parameters:
  • modules (list of IComponent) – Components in the composition.

  • logger_name (str, optional) – Name for the base logger, by default “FINAM”

  • print_log (bool, optional) – Whether to print log to stdout, by default True

  • log_file (str, None or bool, optional) – Whether to write a log file, by default None

  • log_level (int or str, optional) – Logging level, by default logging.INFO

  • slot_memory_limit (int, optional) – Memory limit per output and adapter data, in bytes. When the limit is exceeded, data is stored to disk under the path of slot_memory_location. Default: no limit (None).

  • slot_memory_location (str, optional) – Location for storing data when exceeding slot_memory_limit. Default: “temp”.

Attributes:
logger

Logger for this component.

logger_name

Logger name for the composition.

metadata

Meta data for all components and adapters.

uses_base_logger_name

Whether this class has a base_logger_name attribute.

Methods

connect([start_time])

Performs the connect and validate phases of the composition

initialize()

Initialize all modules.

run([start_time, end_time])

Run this composition using the loop-based update strategy.

initialize()[source]#

Initialize all modules.

After the call, module inputs and outputs are available for linking.

connect(start_time=None)[source]#

Performs the connect and validate phases of the composition

If this was not called by the user, it is called at the start of run().

Parameters:

start_time (datetime, optional) – Starting time of the composition. If provided, it should be the starting time of the earliest component. If not provided, the composition tries to determine the starting time automatically.

run(start_time=None, end_time=None)[source]#

Run this composition using the loop-based update strategy.

Performs the connect phase if it connect() was not already called.

Parameters:
  • start_time (datetime, optional) – Starting time of the composition. If provided, it should be the starting time of the earliest component. If not provided, the composition tries to determine the starting time automatically. Ignored if connect() was already called.

  • end_time (datetime, optional) – Simulation time up to which to simulate. Should be None if no components with time are present.

property logger_name#

Logger name for the composition.

property uses_base_logger_name#

Whether this class has a base_logger_name attribute. False.

property metadata#

Meta data for all components and adapters. Can only be used after connect.

Returns:

A dict with the following metadata keys:
  • components - A dict containing metadata for all components. Individual entries are generated by Component.metadata

  • adapters - A dict containing metadata for all adapters. Individual entries are generated by Adapter.metadata

  • links - A list of all coupling connections

  • time_frame - A list of two items: simulation start and end time

Component and adapter sub-dictionaries use keys like name@id.

Return type:

dict

Raises:

FinamStatusError – Raises the error if connect was not called.

property logger#

Logger for this component.