Rössler-driven Lorenz and generalized synchronization
A chaotic Rössler system that drives a Lorenz-63 system through its second variable.
- Name:
rossler_driven_lorenz - Field:
physics/synchronization - Formalism: ordinary differential equations
- References: Rulkov et al. 1995; Abarbanel, Rulkov, and Sushchik 1996; Datseris and Parlitz 2022
Select this system
from skcomplex.systems import create_simulation, create_system, describe
system = create_system('rossler_driven_lorenz')
entry = describe('rossler_driven_lorenz')
trajectory = create_simulation('rossler_driven_lorenz').prepare().run().trajectory_
Factory
@register_system(
field='physics/synchronization',
tags=('chaos', 'generalized synchronization', 'drive-response', 'ode'),
references=('Rulkov et al. 1995', 'Abarbanel, Rulkov, and Sushchik 1996', 'Datseris and Parlitz 2022'),
defaults={'until': 100.0, 'dt': 0.01},
)
def rossler_driven_lorenz(k: float = 8.0, *, auxiliary: bool = True, p: float = 1 / 6) -> System:
"""Return a chaotic Rössler system that drives a Lorenz-63 system through its 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.
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.
Returns:
system:
The system, with 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`.
Examples:
>>> from skcomplex.systems.physics.synchronization import rossler_driven_lorenz
>>> [element.label for element in rossler_driven_lorenz(auxiliary=False).elements]
['drive', 'response']
"""
drive = RosslerOscillatorElement('drive', x1=1.0, x2=0.0, x3=0.0, p=p)
responses = [LorenzElement('response', x=1.0, y=1.0, z=1.0, beta=2.666)]
if auxiliary:
responses.append(LorenzElement('auxiliary', x=-5.0, y=3.0, z=20.0, beta=2.666))
couplings = [
RateInteraction(
f'coupling_{response.label}',
target=response.label,
state='y',
sources=['drive'],
rate=lambda s: k * s.sources[0].x2,
)
for response in responses
]
return System(elements=[drive, *responses], interactions=couplings)
Components
Elements:
RosslerOscillatorElement, fromElementLorenzElement, fromElement
Interactions:
RateInteraction
class RosslerOscillatorElement(Element):
"""Rössler oscillator `x1' = -omega x2 - x3`, `x2' = omega x1 + a x2`, `x3' = b + x3 (x1 - c)`.
It 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 oscillator.
visual:
How the oscillator is drawn, or `None` for `default_visual_`.
x1:
The initial first variable.
x2:
The initial second variable.
x3:
The initial third variable.
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.
Attributes:
default_visual_:
The visual of the oscillator when it sets none.
Examples:
>>> from skcomplex.systems.physics.synchronization import RosslerOscillatorElement
>>> RosslerOscillatorElement('oscillator').c
5.7
"""
def __init__(
self,
label: str,
visual: VisualSpec | None = None,
*,
x1: Annotated[float, StateSpec()] = 1.0,
x2: Annotated[float, StateSpec()] = 0.0,
x3: Annotated[float, StateSpec()] = 0.0,
omega: Annotated[float, ParameterSpec()] = 1.0,
a: Annotated[float, ParameterSpec()] = 0.2,
b: Annotated[float, ParameterSpec()] = 0.2,
c: Annotated[float, ParameterSpec()] = 5.7,
p: Annotated[float, ParameterSpec(domain=RealSet.open(0, oo))] = 1.0,
) -> None:
super().__init__(label, visual=visual)
self.x1 = x1
self.x2 = x2
self.x3 = x3
self.omega = omega
self.a = a
self.b = b
self.c = c
self.p = p
def _get_laws(self, namespace: SimpleNamespace) -> list[BaseLaw]:
"""Return the Rössler flow.
Args:
namespace:
The namespace of the symbols the laws can use.
Returns:
laws:
The rates of the three variables.
"""
s = namespace
return [
RateLaw(s.x1, (-s.omega * s.x2 - s.x3) / s.p),
RateLaw(s.x2, (s.omega * s.x1 + s.a * s.x2) / s.p),
RateLaw(s.x3, (s.b + s.x3 * (s.x1 - s.c)) / s.p),
]
class LorenzElement(Element):
"""Lorenz flow `x' = sigma (y - x)`, `y' = x (rho - z) - y`, `z' = x y - beta z`.
It is the response that a Rössler oscillator drives into generalized synchronization, and its auxiliary copy.
Args:
label:
The label of the element.
visual:
How the element is drawn, or `None` for `default_visual_`.
x:
The initial convection intensity.
y:
The initial temperature difference between rising and falling currents.
z:
The initial deviation of the vertical temperature profile.
sigma:
The Prandtl number.
rho:
The Rayleigh number relative to its critical value.
beta:
The geometric factor.
Examples:
>>> from skcomplex.core.components.system import System
>>> from skcomplex.core.engine.runtime import Simulation
>>> from skcomplex.systems.physics.synchronization._chaos import LorenzElement
>>> system = System(elements=[LorenzElement('lorenz', x=0.0, y=0.0, z=2.0, beta=0.5)])
>>> trajectory = Simulation(system, dt=0.5).prepare().run(until=1.0).trajectory_
>>> [round(float(value), 4) for value in trajectory.values('lorenz.z')]
[2.0, 1.5576, 1.2131]
"""
def __init__(
self,
label: str,
visual: VisualSpec | None = None,
*,
x: Annotated[float, StateSpec()] = 1.0,
y: Annotated[float, StateSpec()] = 1.0,
z: Annotated[float, StateSpec()] = 1.0,
sigma: Annotated[float, ParameterSpec()] = 10.0,
rho: Annotated[float, ParameterSpec()] = 28.0,
beta: Annotated[float, ParameterSpec()] = 8 / 3,
) -> None:
super().__init__(label, visual=visual)
self.x = x
self.y = y
self.z = z
self.sigma = sigma
self.rho = rho
self.beta = beta
def _get_laws(self, s: SimpleNamespace) -> list[BaseLaw]:
"""Return the rates of the three modes.
Args:
s:
The namespace of the symbols the laws can use.
Returns:
laws:
The rates of `x`, `y`, and `z`.
"""
return [
RateLaw(s.x, s.sigma * (s.y - s.x)),
RateLaw(s.y, s.x * (s.rho - s.z) - s.y),
RateLaw(s.z, s.x * s.y - s.beta * s.z),
]
class RateInteraction(Interaction):
"""Rate `rate(ns)` and noise `noise(ns) dW` added to the highest time derivative of a state of a target.
On a state of order 1 the rate is its first derivative, and on a state of order `k` it adds to the `k`-th
derivative, so rates on one state superpose. With a divisor `d` the rate and the noise are divided by `d`, the name
of a state or parameter of the target, such as an inertia, a friction, or a capacitance, which backends can read.
A rate, a noise, or a divisor function takes the namespace of the interaction, with the namespaces `target` and
`sources` of the bound elements, the time `t`, and the symbols of the parameters a subclass declares. A number
stands for a constant, and a number on a vector state applies to every component. The noise is a Wiener process per
component and member by default, a process of a `WienerProcessSpec` to share or correlate it across states and
members, or a fractional Brownian motion of a Hurst index.
Args:
label:
The label of the interaction, unique among the parts of its system.
target:
The path of the element or group whose state the rate changes.
state:
The name of the state of the target that the rate changes.
rate:
A function of the namespace that returns the rate, or a number.
sources:
The paths of the elements or groups the rate and the noise read but do not change.
noise:
A function of the namespace that returns the amplitude of the noise, a number, or `None` for no noise.
divisor:
The name of the state or parameter of the target that divides the rate and the noise, a function of the
namespace of the target that returns the divisor, such as a moment of inertia `m l^2`, or `None`.
process:
The Wiener processes that drive the noise, or `None` for one independent process per component and member.
index:
The process of `process` that drives the noise, or `None` for every process, one per component of a vector
state.
convention:
The stochastic calculus of the noise, `'ito'`, `'stratonovich'`, or `'anti-ito'`.
hurst:
The Hurst index in `(0, 1)` of a fractional Brownian motion that drives the noise, a number or a function
of the namespace that returns a parameter, or `None` for a Wiener process.
conserved:
Whether the noise is the divergence of a random flux on the links of the lattice of a field, so it keeps the
total of the state.
Raises:
ValidationError:
The state is not a name, a function is neither callable nor a number, the convention is unknown, the Hurst
index is outside `(0, 1)`, or the noise options cannot combine.
Examples:
>>> 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 Simulation
>>> decay = RateInteraction('decay', target='stock', state='n', rate=lambda s: -0.5 * s.target.n)
>>> system = System(elements=[CompartmentElement('stock', n=8.0)], interactions=[decay])
>>> trajectory = Simulation(system, dt=0.01).prepare().run(until=2.0).trajectory_
>>> round(float(trajectory.values('stock.n')[-1]), 3)
2.943
"""
law_classes: ClassVar[tuple[type[BaseLaw], ...]] = (RateLaw, NoiseLaw, FractionalNoiseLaw)
def __init__(
self,
label: str,
*,
target: Annotated[str, RoleSpec(elements=(ElementKind.ANY,), states=('state', 'divisor'))],
state: str = 'x',
rate: Callable[[SimpleNamespace], object] | float = 0.0,
sources: Annotated[Sequence[str], RoleSpec(variadic=True, elements=(ElementKind.ANY,))] = (),
noise: Callable[[SimpleNamespace], object] | float | None = None,
divisor: str | Callable[[SimpleNamespace], object] | None = None,
process: Annotated[WienerProcessSpec | None, RoleSpec(noise=True)] = None,
index: int | None = None,
convention: str = 'ito',
hurst: Callable[[SimpleNamespace], object] | float | None = None,
conserved: bool = False,
) -> None:
super().__init__(label)
self.target = target
self.state = state
self.rate = rate
self.sources = sources
self.noise = noise
self.divisor = divisor
self.process = process
self.index = index
self.convention = convention
self.hurst = hurst
self.conserved = conserved
def _check_functions(self) -> None:
"""Raise an error for a state that is not a name, or a function that is neither callable nor a number."""
if not isinstance(self.state, str) or not self.state.isidentifier():
error_msg = (
f'{type(self).__name__} {self.label!r} changes the state {self.state!r}, which is not a name of a '
'state.'
)
raise ValidationError(error_msg)
for name in ('rate', 'noise'):
value = getattr(self, name)
if not (value is None or callable(value) or isinstance(value, int | float)):
error_msg = f'The {name} of {self.label!r} is {value!r}. Give a function of the namespace or a number.'
raise ValidationError(error_msg)
if not (
self.divisor is None
or callable(self.divisor)
or (isinstance(self.divisor, str) and self.divisor.isidentifier())
):
error_msg = (
f'The divisor of {self.label!r} is {self.divisor!r}. Give the name of a state or parameter, or a '
'function of the namespace of the target.'
)
raise ValidationError(error_msg)
def _check_noise(self) -> None:
"""Raise an error for an unknown convention, a Hurst index outside `(0, 1)`, or noise options that conflict."""
if self.convention not in CONVENTIONS:
error_msg = f'Unknown noise convention {self.convention!r}. Use one of {", ".join(CONVENTIONS)}.'
raise ValidationError(error_msg)
if not (
self.hurst is None or callable(self.hurst) or (isinstance(self.hurst, int | float) and 0 < self.hurst < 1)
):
error_msg = f'The Hurst index of {self.label!r} is {self.hurst!r}. Give a number in (0, 1) or a function.'
raise ValidationError(error_msg)
if self.index is not None and self.process is None:
error_msg = f'{self.label!r} picks the process {self.index!r} but binds no processes. Give `process`.'
raise ValidationError(error_msg)
options = [
name
for name, given in (('hurst', self.hurst), ('process', self.process), ('conserved', self.conserved))
if given
]
if len(options) > 1:
error_msg = f'The noise of {self.label!r} takes {" and ".join(options)}. Give at most one of them.'
raise ValidationError(error_msg)
def _check(self) -> None:
"""Raise an error for a state, functions, or noise options the interaction cannot take.
Raises:
ValidationError:
The type declares states, the state is not a name, a function is neither callable nor a number, the
convention is unknown, the Hurst index is outside `(0, 1)`, or the noise options cannot combine.
"""
super()._check()
self._check_functions()
self._check_noise()
def _evaluate(self, function: Callable[[SimpleNamespace], object] | float, namespace: SimpleNamespace) -> object:
"""Return the value of a function of the namespace, or a number as it is."""
return function(namespace) if callable(function) else function
def _broadcast(self, value: object, state: object) -> object:
"""Return a value with one component per component of a vector state, repeating a number."""
if isinstance(state, FreeModuleElement) and not isinstance(value, FreeModuleElement | list | tuple):
return vector(SR, [value] * len(state))
if isinstance(value, list | tuple):
return vector(SR, value)
return value
def _divide(self, value: object, namespace: SimpleNamespace) -> object:
"""Return a value divided by the divisor of the target, or the value without a divisor."""
if self.divisor is None:
return value
divisor = (
self.divisor(self._get_member(namespace, 'target'))
if callable(self.divisor)
else getattr(self._get_member(namespace, 'target'), self.divisor)
)
return operator.truediv(value, divisor)
def _get_rate(self, namespace: SimpleNamespace) -> object:
"""Return the rate before the divisor, the hook a subclass overrides to derive it from its parameters."""
return self._evaluate(self.rate, namespace)
def _get_noise(self, namespace: SimpleNamespace) -> object:
"""Return the noise amplitude before the divisor, the hook a subclass overrides, or `None` for no noise."""
return None if self.noise is None else self._evaluate(self.noise, namespace)
def _get_noise_law(self, state: object, amplitude: object, namespace: SimpleNamespace) -> BasePart:
"""Return the noise law of an amplitude, by the process, the convention, and the Hurst index."""
if self.hurst is not None:
hurst = self._evaluate(self.hurst, namespace)
return FractionalNoiseLaw(state, amplitude, hurst=hurst, convention=self.convention)
process = None
if self.process is not None:
handle = self._get_member(namespace, 'process').dW
process = handle if self.index is None else handle[self.index]
return NoiseLaw(state, amplitude, convention=self.convention, process=process, conserved=self.conserved)
def _get_laws(self, namespace: SimpleNamespace) -> list[BasePart]:
"""Return the rate law of the state and its noise law, both divided by the divisor.
Args:
namespace:
The namespace of the symbols the laws can use, with the namespaces of the target and the sources.
Returns:
laws:
The rate law, and the noise law when the interaction has noise.
"""
state = getattr(self._get_member(namespace, 'target'), self.state)
rate = self._divide(self._broadcast(self._get_rate(namespace), state), namespace)
laws: list[BasePart] = [RateLaw(state, rate)]
noise = self._get_noise(namespace)
if noise is not None:
laws.append(self._get_noise_law(state, self._divide(noise, namespace), namespace))
return laws
Equations
drive.x1: diff(x1_drive(t), t) == -(omega_drive*x2_drive(t) + x3_drive(t))/p_drive
drive.x2: diff(x2_drive(t), t) == (omega_drive*x1_drive(t) + a_drive*x2_drive(t))/p_drive
drive.x3: diff(x3_drive(t), t) == -((c_drive - x1_drive(t))*x3_drive(t) - b_drive)/p_drive
response.x: diff(x_response(t), t) == -sigma_response*(x_response(t) - y_response(t))
response.y: diff(y_response(t), t) == (rho_response - z_response(t))*x_response(t) + 8.0*x2_drive(t) - y_response(t)
response.z: diff(z_response(t), t) == x_response(t)*y_response(t) - beta_response*z_response(t)
auxiliary.x: diff(x_auxiliary(t), t) == -sigma_auxiliary*(x_auxiliary(t) - y_auxiliary(t))
auxiliary.y: diff(y_auxiliary(t), t) == (rho_auxiliary - z_auxiliary(t))*x_auxiliary(t) + 8.0*x2_drive(t) - y_auxiliary(t)
auxiliary.z: diff(z_auxiliary(t), t) == x_auxiliary(t)*y_auxiliary(t) - beta_auxiliary*z_auxiliary(t)