Nonlocal ring chimera
Identical phase oscillators on a ring.
- Class:
NonlocalRingChimeraSystem - Import:
from skcomplex.systems.physics.synchronization import NonlocalRingChimeraSystem - Field:
physics/synchronization - Topics:
synchronization,oscillators,phase,chimera,nonlocal coupling - References:
- Kuramoto and Battogtokh 2002
- 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 NonlocalRingChimeraSystem
trajectory = NonlocalRingChimeraSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_oscillators |
100 |
R |
14 |
alpha |
1.46 |
omega |
0.0 |
seed |
0 |
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 | continuous |
| Laws | rate |
| Randomness | deterministic |
| Domains | real, vector |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class NonlocalRingChimeraSystem(BaseSystem):
"""Identical phase oscillators on a ring.
Each oscillator is coupled to its `R` nearest neighbours on both sides.
Oscillator `i` follows `phi_i' = omega - (1 / 2R) sum_{j = i - R}^{i + R} sin(phi_i - phi_j + alpha)`, where the sum
includes the oscillator itself. Near `alpha = pi / 2`, coherent and incoherent domains coexist on the ring as a
chimera state, which is a long transient on small rings. The system has the phases `ring.theta` and the places of
the oscillators `ring.x`.
Args:
n_oscillators:
The number of oscillators on the ring.
R:
The range of the coupling.
alpha:
The phase lag.
omega:
The natural frequency.
seed:
The seed of the initial phases.
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 NonlocalRingChimeraSystem
>>> NonlocalRingChimeraSystem(20, R=3).prepare().system_.interactions[1].neighborhood.radius
3.5
"""
field = 'physics/synchronization'
topics = ('synchronization', 'oscillators', 'phase', 'chimera', 'nonlocal coupling')
references = ('Kuramoto and Battogtokh 2002', 'Datseris and Parlitz 2022')
until = 100.0
dt = 1.0
observables = tuple(order_parameter('order', 'ring'))
def __init__(
self,
n_oscillators: int = 100,
*,
R: int = 14,
alpha: float = 1.46,
omega: float = 0.0,
seed: int = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_oscillators = n_oscillators
self.R = R
self.alpha = alpha
self.omega = omega
self.seed = seed
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of identical phase oscillators on a ring, each coupled to its `R` nearest neighbours.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
ring = RingSitedOscillatorElement(
'ring',
theta=KuramotoSystem._spread_phases(self.n_oscillators, self.seed),
omega=self.omega,
x=np.arange(self.n_oscillators, dtype=float).reshape(-1, 1),
size=self.n_oscillators,
space=ContinuousSpace((float(self.n_oscillators),), boundary='periodic'),
)
interactions = [
PhaseRotationInteraction('rotation', target='ring'),
KuramotoCouplingInteraction(
'coupling',
target='ring',
K=1 / (2 * self.R),
alpha=self.alpha,
include_self=True,
neighborhood=RadiusNeighborhood(self.R + 0.5),
),
]
self.system_ = System(self.label, elements=[ring], interactions=interactions)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
RingSitedOscillatorElement, fromElement
Interactions:
PhaseRotationInteraction, fromInteractionKuramotoCouplingInteraction, fromInteraction
class RingSitedOscillatorElement(SitedOscillatorElement):
"""Phase oscillator with a place, drawn on the phase ring at its place."""
visual = VisualSpec('phase_ring', {'phase': 'theta', 'position': 'x'})
class PhaseRotationInteraction(Interaction):
"""Rotation of the phase `theta` of an oscillator at its natural frequency `omega`, `theta' = omega`.
The target holds the phase and the frequency, one of each per member of a group. Couplings to other oscillators add
to the rate of the phase, as for a clock, a firefly, or a generator of a power grid.
Args:
label:
The label of the interaction.
target:
The path of the oscillator or the group of oscillators.
Examples:
>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.common.oscillators import PhaseRotationInteraction
>>> clocks = Element('clocks', values={'theta': 0.0, 'omega': [1.0, 2.0]}, size=2)
>>> system = System(elements=[clocks], interactions=[PhaseRotationInteraction('turn', target='clocks')])
>>> system.prepare().simulate(until=1.0, dt=0.5).get_values('clocks.theta')[-1].tolist()
[1.0, 2.0]
"""
law_classes = (RateLaw,)
def __init__(self, label: str, *, target: Role) -> None:
super().__init__(label)
self.target = target
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rate of the phase of the target.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
oscillator = context.target
self.laws_ = [RateLaw(oscillator.theta.diff(context.t), oscillator.omega)]
class KuramotoCouplingInteraction(Interaction):
"""Kuramoto coupling `theta_i' += K sum_j sin(theta_j - theta_i - alpha)` of the phases of a group.
The sum, or the mean, runs over every other member of the group, or over the members within a neighbourhood such
as `RadiusNeighborhood(r)`. With `include_self` it also runs over `j = i`, whose term `-K sin(alpha)` slows every
phase. Over the whole group, the coupling reads the group sums of `sin theta` and `cos theta` once, so it costs time
linear in the size of the group, as for fireflies that all see each other or the generators of one grid.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the group of oscillators.
K:
The coupling strength of one pair.
alpha:
The phase lag.
reduce:
`'sum'` or `'mean'`.
include_self:
Whether the sum also runs over the member itself.
neighborhood:
The neighbourhood of every member, or `None` for the whole group.
Raises:
ValidationError:
The reduction is neither `'sum'` nor `'mean'`.
Examples:
>>> import numpy as np
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.common.oscillators import PhaseOscillatorElement
>>> from skcomplex.systems.physics.synchronization import KuramotoCouplingInteraction
>>> phases = PhaseOscillatorElement('phases', theta=[0.0, 1.0, 2.0, 3.0], size=4)
>>> coupling = KuramotoCouplingInteraction('coupling', target='phases', K=2.0, reduce='mean')
>>> system = System(elements=[phases], interactions=[coupling]).prepare()
>>> theta = system.simulate(until=20.0, dt=1.0).get_values('phases.theta')
>>> round(float(np.ptp(theta[-1])), 6)
0.0
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
target: Role,
K: float = 1.0,
alpha: float = 0.0,
reduce: str = 'sum',
include_self: bool = False,
neighborhood: BaseNeighborhood | None = None,
) -> None:
super().__init__(label)
self.target = target
self.K = K
self.alpha = alpha
self.reduce = reduce
self.include_self = include_self
self.neighborhood = neighborhood
def _get_group_sum(self, context: SimpleNamespace) -> tuple[Expression, Expression]:
"""Return the sum of the sines over the whole group and the number of terms, from the group sums."""
theta = context.target.theta
shifted = theta + context.alpha
sines, cosines = total(sin(theta)), total(cos(theta))
summed = sines * cos(shifted) - cosines * sin(shifted)
if self.include_self:
return summed, count()
return summed + sin(context.alpha), count() - 1
def _get_neighbour_sum(self, context: SimpleNamespace) -> tuple[Expression, Expression]:
"""Return the sum of the sines over the neighbourhood and the number of terms."""
theta, other = context.target.theta, context.target.other.theta
summed = neighbors(sin(other - theta - context.alpha), over=self.neighborhood)
terms = neighbors(SR(1), over=self.neighborhood)
if self.include_self:
return summed - sin(context.alpha), terms + 1
return summed, terms
def _check_arguments(self) -> None:
"""Raise an error for an argument the interaction cannot take.
Raises:
ValidationError:
The reduction is neither `'sum'` nor `'mean'`.
"""
super()._check_arguments()
if self.reduce not in REDUCTIONS:
error_msg = f'Unknown reduction {self.reduce!r}. Use one of {", ".join(REDUCTIONS)}.'
raise ValidationError(error_msg)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rate of the phases from the lagged sines of the other phases.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
get_sum = self._get_group_sum if self.neighborhood is None else self._get_neighbour_sum
summed, terms = get_sum(context)
rate = context.K * summed if self.reduce == 'sum' else context.K * summed / terms
self.laws_ = [RateLaw(context.target.theta.diff(context.t), rate)]