Skip to content

Elements

An element holds the states of a system, the numbers that change as the system runs, such as an amount, a position, or a cell of a lattice. Each value has a domain, a tag read from the value itself that names the set its values lie in, such as real or boolean. get_tags() of an element returns its domains. Every role of an interaction lists the domains it accepts, so the domains of an element decide which interactions it can be bound to. The table lists the states, domains, and law kinds that each element class of the core declares. A subclass adds the states its interactions read, and their domains with them.

Element Values Domains Law kinds
BaseElement given as data or by a subclass from its values unknown until run
Element given as data or by a subclass from its values none

Comparison

Class Summary Uses See also
BaseElement An abstract element, the component of a system that holds its values. Its subclasses hold a population in ecology, a chemical in a reactor, and an account in a bank. Element, VisualSpec
Element An element that holds named values of one thing or of a group of members. It holds a prey population, a firm of an economy, and the charge of a capacitor. BaseElement, Interaction

Fact sheets

BaseElement

An abstract element, the component of a system that holds its values.

  • Values: given as data or by a subclass
  • Law kinds: unknown until run
  • Times: any
  • Solvers: any
  • Backends: any
  • Arguments:
    • label: The name of the element, unique among the components of its system, such as 'rabbits'.
  • Errors: none of its own
  • Catalog systems: none yet
  • Field realizations: AbundanceElement, ActiveBeadElement, ActiveFieldElement, ActiveHostElement, ActiveParticleElement, ActiveScalarElement, ActivityDensityElement, AdaptiveHostElement, AdaptiveLinkElement, AdaptiveResponderElement, and more in the catalog
  • See also: reference, API

Element

An element that holds named values of one thing or of a group of members.

  • Values: given as data or by a subclass
  • Law kinds: none of its own
  • Times: any
  • Solvers: any
  • Backends: any
  • Arguments:
    • label: The name of the element, unique among the components of its system, such as 'rabbits'.
    • values: Values by name, such as {'x': 10.0, 'm': 1.0}.
    • size: The number of members, each with its own values, such as 1000 molecules of a gas, or None for one.
    • space: The space of the element, with one member per site, such as a lattice of cells, or None for none.
    • on: The part of a network space that holds one member each: 'edges' for every link, 'hyperedges' for every hyperedge, the name of a layer for every link of that layer, such as 'immune', or None for every site.
  • Errors: none of its own
  • Catalog systems: absorbing_birth_death, active_brownian_particles, active_gels, active_ornstein_uhlenbeck_particles, active_polymer, active_system_b, active_viscoelastic_gel, active_walkers, activity_driven_epidemics, adaptive_climbing, and more in the catalog
  • Field realizations: AbundanceElement, ActiveBeadElement, ActiveFieldElement, ActiveHostElement, ActiveParticleElement, ActiveScalarElement, ActivityDensityElement, AdaptiveHostElement, AdaptiveLinkElement, AdaptiveResponderElement, and more in the catalog
  • See also: reference, API

A compatible element

An Element takes its values as data. Here a tank holds a real amount, and a decay at a rate changes it.

from skcomplex.core.components.elements import Element
from skcomplex.core.systems import System
from skcomplex.systems.general.reactions import ReactionInteraction

tank = Element('tank', values={'x': 10.0})
decay = ReactionInteraction('decay', target='tank', reactants={'x': 1}, k=0.5)
sorted(tank.get_tags().domains)
trajectory = System(elements=[tank], interactions=[decay]).prepare().simulate(until=2)
round(trajectory.get_values('tank.x')[-1], 2)
['real']
3.68

The tank has the domain real, and its amount decays from 10 to 3.68 after two time units, which is 10 exp(-1).

An incompatible element

A switch that is lit or dark holds a value of the domain boolean. A rate does not change a boolean, so prepare raises a ValidationError that names the law and the allowed values.

from typing import Annotated

from skcomplex.core.components.elements import Element
from skcomplex.core.errors import ValidationError
from skcomplex.core.systems import System
from skcomplex.systems.general.reactions import ReactionInteraction


class SwitchElement(Element):
    def __init__(self, label, *, lit: Annotated[int, {0, 1}] = 0):
        super().__init__(label)
        self.lit = lit


switch = SwitchElement('switch')
sorted(switch.get_tags().domains)
flip = ReactionInteraction('flip', target='switch', products={'lit': 1})
try:
    System(elements=[switch], interactions=[flip]).prepare()
except ValidationError as error:
    message = str(error)
message
assert 'finite set {0, 1}' in message
['boolean']
The system is not valid, with 1 error(s):
- flip: The RateLaw of flip changes switch.lit continuously, but its allowed values are the finite set {0, 1}. Change the value with an UpdateLaw or a JumpLaw, or allow it a range of real numbers. [law-domain]

The message says that the RateLaw of flip changes switch.lit continuously, while its allowed values are the finite set {0, 1}. Change the value with an UpdateLaw or a JumpLaw, or allow it a range of real numbers.