Interactions
An interaction changes the states of the elements bound to its roles. Each role lists the domains of the states it
accepts, and each interaction lists the kinds of the laws it can return, which its arguments choose among. The law
kinds give the time the interaction runs in, so the parts of one system must agree on it. get_tags() of an
interaction returns the law kinds for the arguments you passed.
| Interaction | Roles and accepted domains | Law kinds |
|---|---|---|
AdvectionInteraction |
target: complex, integer, real, vectorsources: any domain |
rate |
CascadeInteraction |
target: any domain |
update |
ChoiceInteraction |
target: any domain |
update |
ConnectionInteraction |
members: any domain |
equation |
ConservationInteraction |
target: complex, integer, real, vectorsources: any domain |
rate |
CouplingInteraction |
target: any domainsource: any domain |
rate, update |
CrossingInteraction |
target: any domain |
update |
DiffusionInteraction |
target: complex, integer, real, vector |
rate |
EinsteinInteraction |
target: any domain |
rate |
EncounterInteraction |
candidate: any domainfield: any domain |
rate |
EulerLagrangeInteraction |
target: any domain |
equation |
EvolutionInteraction |
target: any domain |
update |
FeedbackInteraction |
from a subclass | update |
GeodesicInteraction |
target: any domain |
rate |
GradientInteraction |
target: any domainsources: any domain |
rate |
GroupingInteraction |
target: any domain |
update |
HamiltonianInteraction |
target: any domain |
rate |
HyperedgeInteraction |
from a subclass | unknown until run |
ImitationInteraction |
target: any domain |
jump, update |
ImpulseInteraction |
target: any domain |
update |
Interaction |
from a subclass | unknown until run |
JumpInteraction |
target: any domain |
jump, update |
LifeCycleInteraction |
target: any domaingroup: any domain |
update |
LocalRuleInteraction |
target: any domain |
update |
MapInteraction |
target: any domainsources: any domain |
update |
MatchingInteraction |
requesters: any domainproviders: any domain |
update |
MobilityInteraction |
target: any domain |
rate, update |
MovementInteraction |
target: any domain |
update |
NeighborInteraction |
from a subclass | unknown until run |
OptimizationInteraction |
target: any domain |
update |
PairCouplingInteraction |
first: any domainsecond: any domain |
rate |
PairInteraction |
first: any domainsecond: any domain |
unknown until run |
RateInteraction |
target: complex, integer, real, vectorsources: any domainprocess: a WienerProcessSpec |
noise, rate |
ReactionInteraction |
target: any domainreactants: any domainproducts: any domainmodifiers: any domain |
jump, noise, rate, update |
ReinforcementInteraction |
target: any domain |
update |
RelaxationInteraction |
target: complex, integer, real, vector |
noise, rate |
SamplingInteraction |
target: any domain |
sampling, update |
SatisfiabilityInteraction |
target: boolean |
update |
SignAdjustmentInteraction |
target: any domain |
update |
TopologyInteraction |
target: any domain |
jump, update |
TrainingInteraction |
system: any domain |
update |
TransferInteraction |
source: any domaintarget: any domainfallback: any domain |
update |
TransitionInteraction |
target: any domain |
jump, update |
A compatible interaction
A rate returns a rate law of continuous time, and its target accepts the real amount of a compartment.
from skcomplex.core.components.elements import CompartmentElement
from skcomplex.core.components.interactions import RateInteraction
from skcomplex.core.components.system import System
from skcomplex.core.engine.runtime import simulate
tank = CompartmentElement('tank', n=10.0)
decay = RateInteraction('decay', target='tank', state='n', rate=lambda s: -0.5 * s.target.n)
sorted(decay.get_tags().laws), sorted(decay.get_tags().time)
trajectory = simulate(System(elements=[tank], interactions=[decay]), until=2)
round(trajectory.values('tank.n')[-1], 2)
(['rate'], ['continuous'])
3.68
An incompatible interaction
A map returns an update law of discrete time. It cannot join the rate in one system without a time that joins them,
so the system names the tag the two parts disagree on.
from skcomplex.core.components.elements import CompartmentElement
from skcomplex.core.components.interactions import MapInteraction, RateInteraction
from skcomplex.core.components.system import System
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.errors import TagError
tank = CompartmentElement('tank', n=10.0)
decay = RateInteraction('decay', target='tank', state='n', rate=lambda s: -0.5 * s.target.n)
halve = MapInteraction('halve', target='tank', state='n', function=lambda s: s.target.n / 2)
sorted(halve.get_tags().laws), sorted(halve.get_tags().time)
try:
simulate(System(elements=[tank], interactions=[decay, halve]), until=1)
except TagError as error:
message = str(error)
message
assert "tag 'time'" in message
(['update'], ['discrete'])
The parts 'decay' and 'halve' disagree on the tag 'time': 'decay' has continuous and 'halve' has discrete. Give the system a time that joins them, or bind parts of one time.