mbdlyb.functional.operating_mode

Classes

OpmLogic

OpmLogicAnd

OpmLogicOr

OpmSet

Set of mutually exclusive operating mode variables.

OpmVariable

Module Contents

class mbdlyb.functional.operating_mode.OpmLogic(opm_vars: list[OpmVariable] | None = None)
add(opm_logic: OpmLogic) → OpmLogic

Append a non-empty logic expression as an operand.

Parameters:

opm_logic (OpmLogic) – Expression to add.

Returns:

This expression, for method chaining.

Return type:

OpmLogic

classmethod create(modes: list[str], opm_set: OpmSet | None = None) → OpmLogicOr

Create an OR expression from operating mode names.

Parameters:
  • modes (list[str]) – Names of operating modes to include.

  • opm_set (Optional[OpmSet]) – Set to associate with each variable. Defaults to None.

Returns:

OR expression containing the requested variables.

Return type:

OpmLogicOr

eval(active_modes: list[str]) → bool

Evaluate this expression against the active operating modes.

Parameters:

active_modes (list[str]) – Names of the currently active modes.

Returns:

Result of applying this expression’s logical operation.

Return type:

bool

classmethod from_copy(other) → OpmLogic

Create a shallow copy of another operating mode logic expression.

Parameters:

other – Logic expression whose operands are copied.

Returns:

New expression of the same class with the same operands.

Return type:

OpmLogic

unwrap() → OpmVariable | OpmLogic

Remove a redundant expression wrapper when there is one operand.

Returns:

The sole operand, or this expression if it has

zero or multiple operands.

Return type:

OpmVariable | OpmLogic

logic_function
property sets: set[OpmSet]

Return the non-None sets associated with variables in this expression.

Returns:

Distinct associated operating mode sets.

Return type:

set[OpmSet]

var_separator: str = ', '
property variables: list[OpmVariable]

Return all variables nested in this expression.

Returns:

Variables in operand order, including nested expressions.

Return type:

list[OpmVariable]

class mbdlyb.functional.operating_mode.OpmLogicAnd(opm_vars: list[OpmVariable] | None = None)

Bases: OpmLogic

logic_function
var_separator: str = ' & '
class mbdlyb.functional.operating_mode.OpmLogicOr(opm_vars: list[OpmVariable] | None = None)

Bases: OpmLogic

logic_function
var_separator: str = ' | '
class mbdlyb.functional.operating_mode.OpmSet(variables: list[str | OpmVariable] | None = None)

Set of mutually exclusive operating mode variables.

An OpmSet represents a group of operating mode variables that are mutually exclusive with each other. Only one variable from the set can be active at any given time.

Variables:

_variables (list[OpmVariable]) – List of variables in this set.

add_variables(opm_vars: list[str | OpmVariable])

Add variables to this set and associate each variable with it.

Parameters:

opm_vars (list[str | OpmVariable]) – Variable names or variables to add.

Returns:

None

contains_variable(var: OpmVariable) → bool

Check whether a variable belongs to this set.

Parameters:

var (OpmVariable) – Variable to check.

Returns:

Whether the variable is in this set.

Return type:

bool

property variable_names: list[str]

Return the names of variables in this set, sorted alphabetically.

Returns:

Names of the variables.

Return type:

list[str]

class mbdlyb.functional.operating_mode.OpmVariable(name, opm_set: OpmSet | None = None)
eval(active_modes: list[str]) → bool

Evaluate whether this variable is active in the supplied mode selection.

A variable evaluates to false when another variable in its set is active; if none from the set are selected, it evaluates to true.

Parameters:

active_modes (list[str]) – Names of the currently active modes.

Returns:

Whether this variable evaluates as active.

Return type:

bool

set_opmset(opm_set: OpmSet) → None

Associate this variable with an operating mode set.

Parameters:

opm_set (OpmSet) – Set to associate with this variable.

Returns:

None

property name: str

Return this variable’s name.

Returns:

The variable name.

Return type:

str

property opmset: OpmSet | None

Return the set associated with this variable, if any.

Returns:

The associated set, or None if it has not been set.

Return type:

Optional[OpmSet]