BF-OPS - Operations

../../../../../../../_images/MLPro-BF-OPS_class_diagram.drawio.png

Ver. 1.2.3 (2023-03-25)

This module provides classes for operation.

class mlpro.bf.ops.Mode(p_mode, p_logging=True)

Bases: Log

Property class that adds a mode and related methods to a child class.

Parameters:
  • p_mode – Operation mode. Valid values are stored in constant C_VALID_MODES.

  • p_logging – Log level (see constants of class Log). Default: Log.C_LOG_ALL

C_MODE_SIM = 0

Simulation mode.

C_MODE_REAL = 1

Real operation mode.

C_VALID_MODES

List of valid modes.

Type:

list

C_MODE_INITIAL = -1
C_MODE_SIM = 0
C_MODE_REAL = 1
C_VALID_MODES = [0, 1]
get_mode()

Returns current mode.

set_mode(p_mode)

Sets new mode.

Parameters:

p_mode – Operation mode. Valid values are stored in constant C_VALID_MODES.

class mlpro.bf.ops.ScenarioBase(p_mode, p_id=None, p_cycle_limit=0, p_auto_setup: bool = True, p_visualize: bool = True, p_logging=True)

Bases: Mode, Persistent, Plottable

Base class for executable scenarios in MLPro. To be inherited and specialized in higher layers.

The following key features are included:
  • Operation mode

  • Cycle management

  • Timer

  • Latency

Parameters:
  • p_mode – Operation mode. See Mode.C_VALID_MODES for valid values. Default = Mode.C_MODE_SIM.

  • p_id – Optional external id

  • p_cycle_limit (int) – Maximum number of cycles. Default = 0 (no limit).

  • p_auto_setup (bool) – If True custom method setup() is called after initialization.

  • p_visualize (bool) – Boolean switch for visualisation. Default = True.

  • p_logging – Log level (see constants of class Log). Default: Log.C_LOG_ALL.

C_TYPE = 'Scenario Base'
C_NAME = '????'
_init_timer()
setup()

Custom method to set up all components of the scenario.

set_mode(p_mode)

Sets operation mode of the scenario. Custom method _set_mode() is called.

Parameter

p_mode

Operation mode. See class bf.ops.Mode for further details.

_set_mode(p_mode)

Custom method to set the operation mode of components of the scenario. See method set_mode() for further details.

Parameter

p_mode

Operation mode. See class bf.ops.Mode for further details.

get_latency() timedelta

Returns the latency of the scenario. To be implemented in child class.

set_cycle_limit(p_limit)

Sets the maximum number of cycles to run.

Parameters:

p_cycle_limit (int) – Maximum number of cycles. Default = 0 (no limit).

reset(p_seed=1)

Resets the scenario and especially the ML model inside. Internal random generators are seed with the given value. Custom reset actions can be implemented in method _reset().

Parameters:

p_seed (int) – Seed value for internal random generator

_reset(p_seed)

Custom method to reset the components of the scenario and to set the given random seed value. See method reset() for further details.

Parameters:

p_seed (int) – Seed value for internal random generator

run_cycle()

Runs a single process cycle.

Returns:

  • success (bool) – True on success. False otherwise.

  • error (bool) – True on error. False otherwise.

  • timeout (bool) – True on timeout. False otherwise.

  • cycle_limit (bool) – True, if cycle limit has reached. False otherwise.

  • adapted (bool) – True, if something within the scenario has adapted something in this cycle. False otherwise.

  • end_of_data (bool) – True, if the end of the related data source has been reached. False otherwise.

_run_cycle()

Custom implementation of a single process cycle. To be redefined.

Returns:

  • success (bool) – True on success. False otherwise.

  • error (bool) – True on error. False otherwise.

  • adapted (bool) – True, if something within the scenario has adapted something in this cycle. False otherwise.

  • end_of_data (bool) – True, if the end of the related data source has been reached. False otherwise.

get_cycle_id()

Returns current cycle id.

run(p_term_on_success: bool = True, p_term_on_error: bool = True, p_term_on_timeout: bool = False)

Runs the scenario as a sequence of single process steps until a terminating event occures.

Parameters:
  • p_term_on_success (bool) – If True, the run terminates on success. Default = True.

  • p_term_on_error (bool) – If True, the run terminates on error. Default = True.

  • p_term_on_timeout (bool) – If True, the run terminates on timeout. Default = False.

Returns:

  • success (bool) – True on success. False otherwise.

  • error (bool) – True on error. False otherwise.

  • timeout (bool) – True on timeout. False otherwise.

  • cycle_limit (bool) – True, if cycle limit has reached. False otherwise.

  • adapted (bool) – True, if ml model adapted something. False otherwise.

  • end_of_data (bool) – True, if the end of the related data source has been reached. False otherwise.

  • num_cycles (int) – Number of cycles.