Skip to content

Base

Define the base of the parts of a system.

BasePart(label)

Bases: BaseConfig[ContextT, InputT]

Base of every part of a system: its elements, its interactions, the laws they return, and the system itself.

Every part has a label, returns the laws it contributes from _get_laws, and implements three hooks that the verbs prepare and run call:

  • _check() validates the arguments of the part, after check validates the label.
  • _prepare(context) prepares the part against its context and sets its attributes that end in _.
  • _run(inputs) sets what the part contributes: laws_, the laws of an element, an interaction, or a system, or value_, the value of a law.

A part is generic in the context of prepare and the input of run, which every base of parts names: a law is prepared against the path of its owner, an element against the space of its system.

A part declares which arguments of its constructor are states, parameters, or roles by annotating them with Annotated and a StateSpec, a ParameterSpec, or a RoleSpec, and prepare validates every declared spec.

Examples:

>>> from skcomplex.core.components.base import BasePart
>>> class DoublingPart(BasePart):
...     def __init__(self, label, factor=2):
...         super().__init__(label)
...         self.factor = factor
...
...     def _check(self):
...         pass
...
...     def _prepare(self, context=None):
...         pass
...
...     def _get_laws(self, namespace):
...         return []
...
...     def _run(self, value):
...         self.doubled_ = self.factor * value
>>> DoublingPart('doubling').prepare().run(3).doubled_
6

Parameters:

Name Type Description Default
label str

The label of the part, unique among the parts of its system.

required
Source code in src/skcomplex/core/components/base.py
59
60
61
62
63
64
65
66
def __init__(self, label: str) -> None:
    """Store the label of the part.

    Args:
        label:
            The label of the part, unique among the parts of its system.
    """
    self.label = label