Rössler-driven Lorenz and generalized synchronization
A chaotic Rössler system that drives a Lorenz-63 system.
- Class:
RosslerDrivenLorenzSystem - Import:
from skcomplex.systems.physics.synchronization import RosslerDrivenLorenzSystem - Field:
physics/synchronization - Topics:
chaos,generalized synchronization,drive-response,ode - References:
- Rulkov et al. 1995
- Abarbanel, Rulkov, and Sushchik 1996
- Datseris and Parlitz 2022
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.synchronization import RosslerDrivenLorenzSystem
trajectory = RosslerDrivenLorenzSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
k |
8.0 |
auxiliary |
True |
p |
0.16666666666666666 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | rate |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class RosslerDrivenLorenzSystem(BaseSystem):
"""A chaotic Rössler system that drives a Lorenz-63 system.
The drive acts through the second variable.
The drive follows `p x1' = -x2 - x3`, `p x2' = x1 + 0.2 x2`, `p x3' = 0.2 + x3 (x1 - 5.7)`, with the time scale `p =
1 / 6` that brings it close to the Lorenz system, and the response follows `y1' = 10 (y2 - y1)`, `y2' = 28 y1 - y2 -
y1 y3 + k x2`, `y3' = y1 y2 - 2.666 y3`. The two systems have nothing in common, yet for a coupling above `k ≈ 6.66`
the response forgets its initial state and becomes a function of the state of the drive, generalized
synchronization. With `auxiliary`, a second copy of the response from another initial state receives the same drive,
and the two copies converge to each other exactly when generalized synchronization holds, the auxiliary system
method. The system has the drive `drive.x1`, `drive.x2`, `drive.x3`, the response `response.x`, `response.y`,
`response.z`, and with `auxiliary` the copy `auxiliary.x`, `auxiliary.y`, `auxiliary.z`.
Args:
k:
The strength of the coupling.
auxiliary:
Whether a second copy of the response, `auxiliary`, receives the drive too.
p:
The time scale of the drive.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.synchronization import RosslerDrivenLorenzSystem
>>> trajectory = RosslerDrivenLorenzSystem(auxiliary=False).prepare().simulate(until=1.0, dt=0.5)
>>> [round(float(value), 1) for value in trajectory.get_values('response.x')]
[1.0, -0.1, -8.9]
"""
field = 'physics/synchronization'
topics = ('chaos', 'generalized synchronization', 'drive-response', 'ode')
references = ('Rulkov et al. 1995', 'Abarbanel, Rulkov, and Sushchik 1996', 'Datseris and Parlitz 2022')
until = 100.0
dt = 0.01
def __init__(
self,
k: float = 8.0,
*,
auxiliary: bool = True,
p: float = 1 / 6,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.k = k
self.auxiliary = auxiliary
self.p = p
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a chaotic Rössler system that drives a Lorenz-63 system.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
responses = [Element('response', values={'x': 1.0, 'y': 1.0, 'z': 1.0})]
if self.auxiliary:
responses.append(Element('auxiliary', values={'x': -5.0, 'y': 3.0, 'z': 20.0}))
interactions: list[Interaction] = [RosslerFlowInteraction('drive_flow', target='drive', p=self.p)]
for response in responses:
interactions.append(LorenzFlowInteraction(f'{response.label}_flow', target=response.label, beta=2.666))
interactions.append(
DriveInteraction(f'coupling_{response.label}', source='drive', target=response.label, k=self.k),
)
self.system_ = System(
self.label,
elements=[RosslerOscillatorElement('drive', x1=1.0, x2=0.0, x3=0.0), *responses],
interactions=interactions,
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
Interactions:
RosslerFlowInteraction, fromInteractionLorenzFlowInteraction, fromInteractionDriveInteraction, fromInteraction
class RosslerOscillatorElement(Element):
"""Rössler oscillator with the three variables `x1`, `x2`, and `x3`.
`RosslerFlowInteraction` moves the variables.
Args:
label:
The label of the oscillator.
x1:
The initial first variable.
x2:
The initial second variable.
x3:
The initial third variable.
Examples:
>>> from skcomplex.systems.physics.synchronization import RosslerOscillatorElement
>>> RosslerOscillatorElement('oscillator', x1=2.0).x1
2.0
"""
def __init__(self, label: str, *, x1: float = 1.0, x2: float = 0.0, x3: float = 0.0) -> None:
super().__init__(label)
self.x1 = x1
self.x2 = x2
self.x3 = x3
class Element(BaseElement):
"""An element that holds named values of one thing or of a group of members.
It holds its values by name, such as the height and mass of a ball in
`Element('ball', values={'x': 10.0, 'm': 1.0})`, and the laws of the interactions decide which values change. With
`size` it holds a group of members with values of their own, such as 1000 molecules of a gas, and with `space` one
member per site, such as the cells of a grid. A subclass may take its values as arguments of `__init__` instead,
such as a population class with a growth rate. Members whose values change by agent rules, Python functions run for
each member at each step, act as agents, and their values may be any Python object. It holds a prey population, a
firm of an economy, and the charge of a capacitor.
Read more in the user guide, under Elements.
Args:
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}`. A derivative or a past value that a law reads starts from
the value named with primes or a past index, such as `{'x': 10.0, "x'": 3.0}` for a ball thrown upwards or
`{'y': 1.0, 'y[-1]': 0.5}` for an economy. A group of members takes one value per member as an array.
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.
Attributes:
default_visual_:
How the element is drawn by default, the `visual` of its class.
See Also:
BaseElement: The base of every element.
Interaction: States the laws that change the values of elements.
Examples:
>>> from skcomplex.core.components.elements import Element
>>> ball = Element('ball', values={'x': 10.0, 'm': 1.0})
>>> ball.get_params()['x']
10.0
"""
law_classes: ClassVar[tuple[type, ...]] = ()
def __init__(
self,
label: str,
*,
values: Mapping[str, object] | None = None,
size: int | None = None,
space: BaseSpace | None = None,
on: str | None = None,
) -> None:
super().__init__(label)
self.values = values
self.size = size
self.space = space
self.on: object = on
def get_params(self, deep: bool = True) -> dict[str, Any]:
"""Return the parameters of the element, with each entry of `values` when deep.
An entry of `values` whose name is a Python identifier is listed under its own name, so a system lists it as
`<element>__<name>` and `set_params(ball__x=2.0)`, grid searches, and sweeps reach it. A primed or past value,
such as `"x'"` or `'x[-1]'`, is no identifier and stays inside `values`. An entry that has the name of an
argument is not listed twice.
Args:
deep:
Whether to add the parameters of nested estimators and the entries of `values`.
Returns:
params:
The parameters by name.
Examples:
>>> from skcomplex.core.components.elements import Element
>>> params = Element('ball', values={'x': 10.0, "x'": 3.0}).get_params()
>>> params['x'], "x'" in params
(10.0, False)
"""
params = super().get_params(deep=deep)
if deep and isinstance(self.values, Mapping):
entries = self._get_value_entries()
params.update({name: value for name, value in entries.items() if name not in params})
return params
def set_params(self, **params: object) -> Self:
"""Set parameters of the element and entries of `values` by name.
An entry of `values` takes its new value in a new mapping, so the mapping the user gave never changes, as
`clone` of scikit-learn leaves the arguments of an estimator unchanged. A new `values` is set first, so the
output of `get_params` is accepted as it is.
Args:
**params:
The new values, by the name of a parameter or of an entry of `values`, such as `x=2.0`.
Returns:
self:
The element.
Examples:
>>> from skcomplex.core.components.elements import Element
>>> values = {'x': 10.0}
>>> Element('ball', values=values).set_params(x=2.0).values, values
({'x': 2.0}, {'x': 10.0})
"""
arguments = super().get_params(deep=True)
if 'values' in params:
super().set_params(values=params['values'])
entries = self._get_value_entries()
changed = {name: value for name, value in params.items() if name in entries and name not in arguments}
rest = {name: value for name, value in params.items() if name not in changed and name != 'values'}
super().set_params(**rest)
if changed:
self.values = {**(self.values or {}), **changed}
return self
def _get_value_entries(self) -> dict[str, object]:
"""Return the entries of `values` whose names are Python identifiers."""
values = self.values if isinstance(self.values, Mapping) else {}
return {name: value for name, value in values.items() if name.isidentifier()}
def _prepare(self, context: BaseSpace | None = None) -> None:
"""Set `default_visual_`, checking the reserved names.
Args:
context:
The space the element inherits from its system, which an element with `on` and no space of its own
sits on.
Raises:
ValidationError:
`size` is not a number of members, `space` is not a space, or `values` is not a mapping, as when a
subclass stores a quantity of its own under a reserved name.
"""
super()._prepare(context)
size = self.size
checks = {
'size': size is None or (isinstance(size, numbers.Integral) and not isinstance(size, bool) and size >= 1),
'space': self.space is None or isinstance(self.space, BaseSpace),
'values': self.values is None or isinstance(self.values, Mapping),
}
for name, valid in checks.items():
if not valid:
error_msg = (
f'Element {self.label!r} has {name} = {getattr(self, name)!r}, but {name} is the '
f'{RESERVED_MEANINGS[name]}. The names {", ".join(RESERVED)} are reserved, so rename the value, '
f'such as half_side for the half side of a table.'
)
raise ValidationError(error_msg)
self._check_on(self.space if self.space is not None else context)
def _get_tags(self) -> Tags:
"""Return the tags of the element, with the tags of its space when it has one.
A field on a phase space thus asks for a solver that supports phase spaces, as a group on it does.
"""
tags = super()._get_tags()
if not isinstance(self.space, BaseSpace):
return tags
return replace(tags, space=self.space.get_tags().space)
def _check_on(self, space: BaseSpace | None) -> None:
"""Raise an error for an `on` that names no part of a network space.
A value named `on` that the element declares as its own state or parameter names no place. The space is the
element's own, or else that of its system.
"""
if isinstance(type(self)._get_specs().get('on'), _StateSpec | _ParameterSpec):
return
on = getattr(self, 'on', None)
if on is None or (isinstance(space, NetworkSpace) and (on in LINKS or on in space.prepare().graphs_)):
return
error_msg = (
f'Element {self.label!r} has on = {on!r}, but on is the part of a network space that holds one member '
"each, 'edges', 'hyperedges', or the name of a layer for its edges, such as "
"Element('links', values={'sign': 1}, space=network, on='edges'). The names "
f'{", ".join(RESERVED)} are reserved, so rename a value of the element named on, such as closed for a '
'switch.'
)
raise ValidationError(error_msg)
@staticmethod
def _get_domain_of(annotation: object, value: object) -> object:
"""Return the domain of a value from its annotation or its Python type.
A value without an annotation, such as one given through `values`, takes the domain of its type, so `3` is an
integer and `0.5 + 1j` is complex. The annotation `object` says nothing of the kind, so a value annotated so,
such as a point that may be one number or an array of complex numbers, also takes the domain of its type, and
so does a value of one of several types, such as `float | Sequence[float]`. A subshift, such as
`Annotated[int, SubshiftSpec(LatticeNeighborhood(((0,), (1,))), ((1, 1),))]`, is the domain of the cells of a
lattice whose configurations hold no forbidden word.
"""
if get_origin(annotation) is Annotated:
for item in get_args(annotation)[1:]:
if isinstance(item, set | frozenset):
return FiniteEnumeratedSet(sorted(item, key=str))
allowed = hasattr(item, '__contains__') and not isinstance(item, str | MatrixGroupSpec)
if allowed or isinstance(item, SubshiftSpec | PowerSeriesSpec):
return item
annotation = get_args(annotation)[0]
annotated = isinstance(annotation, type) and annotation not in {inspect.Parameter.empty, object}
kind = annotation if annotated else type(value)
if kind is bool:
return BOOLEAN
if kind is int:
return ZZ
if kind is complex or (isinstance(kind, type) and issubclass(kind, np.complexfloating)):
return CC
return RR
def _get_domain_tags(self) -> frozenset[str]:
"""Return the domain tags of the states of the element.
An element that declares no states has the domains of all its numeric values, since the laws of the system
decide which of them are states, such as `boolean` for `opinion: Annotated[int, {0, 1}] = 0`.
"""
if self._get_component_specs():
return super()._get_domain_tags()
params = self.get_params(deep=False)
values = {name: params.get(name) for name in self._get_hints()}
values |= {name: value for name, value in (self.values or {}).items() if name.isidentifier()}
hints = self._get_hints()
domains = {
_StateSpec(domain=self._get_domain_of(hints.get(name, inspect.Parameter.empty), value))._get_domain_tag()
for name, value in values.items()
if isinstance(value, numbers.Number | list | np.ndarray)
}
return frozenset(domain for domain in domains if domain is not None)
def _get_hints(self) -> dict[str, object]:
"""Return the type hint of every value argument by name, in their order.
The hints are the annotations of the arguments of the class, such as `Annotated[float, Quantity('energy')]`,
from which the kind, the allowed values, the quantity, and the period of each value are read. A generic
subclass that takes its values through `values` gives their hints here instead, and the arguments it leaves
out, such as the allowed values themselves, are no values.
"""
parameters = inspect.signature(type(self)).parameters
return {name: parameter.annotation for name, parameter in parameters.items() if name not in RESERVED}
@classmethod
def _get_view(cls) -> type | None:
"""Return the class of the views of the element's agents.
The result is `None` for the engine's plain view. An agent element names a subclass of the engine's `AgentView`
that annotates its states and parameters, such as `class WordView(AgentView): count: float`, so its rules read
them with checked types.
"""
return None
class RosslerFlowInteraction(Interaction):
"""Rössler flow `x1' = -omega x2 - x3`, `x2' = omega x1 + a x2`, `x3' = b + x3 (x1 - c)`.
The flow is chaotic for `a = b = 0.2` and `c = 5.7`. The time scale `p` divides every rate, `p x' = f(x)`, so `p <
1` speeds the oscillator up.
Args:
label:
The label of the interaction.
target:
The path of the oscillator whose variables `x1`, `x2`, and `x3` the flow moves.
omega:
The natural frequency.
a:
The first Rössler parameter.
b:
The second Rössler parameter.
c:
The third Rössler parameter.
p:
The time scale, which divides every rate.
Examples:
>>> from skcomplex.systems.physics.synchronization import RosslerFlowInteraction
>>> RosslerFlowInteraction('flow', target='oscillator').c
5.7
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
target: Role,
omega: float = 1.0,
a: float = 0.2,
b: float = 0.2,
c: float = 5.7,
p: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
super().__init__(label)
self.target = target
self.omega = omega
self.a = a
self.b = b
self.c = c
self.p = p
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rates of the three variables of the target.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
s, t = context, context.t
x1, x2, x3 = s.target.x1, s.target.x2, s.target.x3
self.laws_ = [
RateLaw(x1.diff(t), (-s.omega * x2 - x3) / s.p),
RateLaw(x2.diff(t), (s.omega * x1 + s.a * x2) / s.p),
RateLaw(x3.diff(t), (s.b + x3 * (x1 - s.c)) / s.p),
]
class LorenzFlowInteraction(Interaction):
"""Lorenz flow `x' = sigma (y - x)`, `y' = x (rho - z) - y`, `z' = x y - beta z`.
For `sigma = 10`, `rho = 28`, and `beta = 8/3` the runs never settle and never repeat, the strange attractor of
Lorenz.
Args:
label:
The label of the interaction.
target:
The path of the element whose values `x`, `y`, and `z` the flow moves.
sigma:
The Prandtl number.
rho:
The Rayleigh number relative to its critical value.
beta:
The geometric factor.
Examples:
>>> from skcomplex.systems.physics.synchronization import LorenzFlowInteraction
>>> LorenzFlowInteraction('flow', target='response', beta=2.666).beta
2.666
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
target: Role,
sigma: float = 10.0,
rho: float = 28.0,
beta: float = 8 / 3,
) -> None:
super().__init__(label)
self.target = target
self.sigma = sigma
self.rho = rho
self.beta = beta
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rates of the three values of the target.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
s, t = context, context.t
x, y, z = s.target.x, s.target.y, s.target.z
self.laws_ = [
RateLaw(x.diff(t), s.sigma * (y - x)),
RateLaw(y.diff(t), x * (s.rho - z) - y),
RateLaw(z.diff(t), x * y - s.beta * z),
]
class DriveInteraction(Interaction):
"""Drive of a state of the target by a state of the source, `x_t' += k x_s`.
Args:
label:
The label of the interaction, unique among the components of its system.
source:
The path of the element that drives.
target:
The path of the element that is driven.
read:
The name of the state of the source that drives.
write:
The name of the state of the target whose rate the drive adds to.
k:
The strength of the drive.
Examples:
>>> from skcomplex.systems.physics.synchronization import DriveInteraction
>>> DriveInteraction('coupling', source='drive', target='response', k=8.0).k
8.0
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
source: Role,
target: Role,
read: str = 'x2',
write: str = 'y',
k: float = 1.0,
) -> None:
super().__init__(label)
self.source = source
self.target = target
self.read = read
self.write = write
self.k = k
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rate `k x_s` of the state of the target.
Args:
context:
The namespace of the source, the target, the time `t`, and the parameters.
"""
super()._prepare(context)
x = getattr(context.target, self.write)
self.laws_ = [RateLaw(x.diff(context.t), context.k * getattr(context.source, self.read))]
Equations
The equations are those that symbolic returns for the system with its default parameters.
drive.x1: diff(x1_drive(t), t) == -(omega_drive_flow*x2_drive(t) + x3_drive(t))/p_drive_flow
drive.x2: diff(x2_drive(t), t) == (omega_drive_flow*x1_drive(t) + a_drive_flow*x2_drive(t))/p_drive_flow
drive.x3: diff(x3_drive(t), t) == -((c_drive_flow - x1_drive(t))*x3_drive(t) - b_drive_flow)/p_drive_flow
response.x: diff(x_response(t), t) == -sigma_response_flow*(x_response(t) - y_response(t))
response.y: diff(y_response(t), t) == k_coupling_response*x2_drive(t) + (rho_response_flow - z_response(t))*x_response(t) - y_response(t)
response.z: diff(z_response(t), t) == x_response(t)*y_response(t) - beta_response_flow*z_response(t)
auxiliary.x: diff(x_auxiliary(t), t) == -sigma_auxiliary_flow*(x_auxiliary(t) - y_auxiliary(t))
auxiliary.y: diff(y_auxiliary(t), t) == k_coupling_auxiliary*x2_drive(t) + (rho_auxiliary_flow - z_auxiliary(t))*x_auxiliary(t) - y_auxiliary(t)
auxiliary.z: diff(z_auxiliary(t), t) == x_auxiliary(t)*y_auxiliary(t) - beta_auxiliary_flow*z_auxiliary(t)