Kuramoto on networks
Kuramoto oscillators coupled along the edges of a network.
- Class:
KuramotoOnNetworksSystem - Import:
from skcomplex.systems.physics.synchronization import KuramotoOnNetworksSystem - Field:
physics/synchronization - Topics:
synchronization,oscillators,phase,network - References:
- Arenas et al. 2008
- Jensen 2023
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 KuramotoOnNetworksSystem
trajectory = KuramotoOnNetworksSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_oscillators |
200 |
network |
'watts_strogatz' |
degree |
6 |
rewiring |
0.1 |
K |
1.0 |
sigma |
0.5 |
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 | network |
| 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 KuramotoOnNetworksSystem(BaseSystem):
"""Kuramoto oscillators coupled along the edges of a network.
The oscillators follow `theta_i' = omega_i + K sum_j A_ij sin(...)`.
Oscillator `i` follows `theta_i' = omega_i + (K / <k>) sum_j w_ij sin(theta_j - theta_i)` over its neighbours `j`,
where the weights `w_ij = 1` live on a group on the edges and `<k>` is the mean degree. The coupling runs once per
edge. The natural frequencies are drawn from a normal distribution of width `sigma`, and the phases uniformly from
the circle. Above a critical coupling of the order of the all-to-all value `2 sigma sqrt(2 / pi)`, the order
parameter `r = |<exp(i theta)>|` grows from about `1 / sqrt(N)` towards 1, and small-world shortcuts lower it. The
system has the phases `oscillators.theta`, the weights `links.w`, and the order parameter `order`.
Args:
n_oscillators:
The number of oscillators, the nodes of the network.
network:
The generator, `'watts_strogatz'`, `'erdos_renyi'`, or `'barabasi_albert'`.
degree:
The mean degree of the network, even for the Watts-Strogatz ring.
rewiring:
The probability of rewiring every edge of the Watts-Strogatz ring.
K:
The coupling strength, divided by the mean degree.
sigma:
The standard deviation of the natural frequencies.
seed:
The seed of the network, the frequencies, and the 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.
Raises:
ValueError:
The network is unknown.
Examples:
>>> from skcomplex.systems.physics.synchronization import KuramotoOnNetworksSystem
>>> system = KuramotoOnNetworksSystem(20, degree=4).prepare().system_
>>> system.elements[1].space.graph.number_of_edges()
40
"""
field = 'physics/synchronization'
topics = ('synchronization', 'oscillators', 'phase', 'network')
references = ('Arenas et al. 2008', 'Jensen 2023')
until = 40.0
dt = 0.2
observables = tuple(order_parameter('order', 'oscillators'))
@staticmethod
def _get_network(name: str, n_nodes: int, degree: int, rewiring: float, seed: int) -> NetworkSpace:
"""Return a network of a generator with a mean degree near `degree`."""
rng = np.random.default_rng(seed)
if name == 'watts_strogatz':
return NetworkSpace(nx.watts_strogatz_graph(n_nodes, degree, rewiring, seed=rng))
if name == 'erdos_renyi':
return NetworkSpace(nx.gnp_random_graph(n_nodes, degree / (n_nodes - 1), seed=rng))
if name == 'barabasi_albert':
return NetworkSpace(nx.barabasi_albert_graph(n_nodes, max(degree // 2, 1), seed=rng))
error_msg = f'Unknown network {name!r}. Use one of {", ".join(NETWORKS)}.'
raise ValueError(error_msg)
def __init__(
self,
n_oscillators: int = 200,
*,
network: str = 'watts_strogatz',
degree: int = 6,
rewiring: float = 0.1,
K: float = 1.0,
sigma: float = 0.5,
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.network = network
self.degree = degree
self.rewiring = rewiring
self.K = K
self.sigma = sigma
self.seed = seed
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of Kuramoto oscillators coupled along the edges of a network.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
space = KuramotoOnNetworksSystem._get_network(
self.network,
self.n_oscillators,
self.degree,
self.rewiring,
self.seed,
)
rng = np.random.default_rng(self.seed + 1)
mean_degree = 2 * space.graph.number_of_edges() / self.n_oscillators
oscillators = NodeOscillatorElement(
'oscillators',
theta=rng.uniform(0, 2 * math.pi, self.n_oscillators),
omega=rng.normal(0.0, self.sigma, self.n_oscillators),
space=space,
)
links = LinkElement('links', space=space, on='edges')
interactions = [
PhaseRotationInteraction('rotation', target='oscillators'),
EdgeCouplingInteraction('coupling', among='oscillators', K=self.K / mean_degree),
]
self.system_ = System(self.label, elements=[oscillators, links], interactions=interactions)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
Interactions:
PhaseRotationInteraction, fromInteractionEdgeCouplingInteraction, fromInteraction
class NodeOscillatorElement(PhaseOscillatorElement):
"""Phase oscillator on a node, drawn with its phase."""
visual = VisualSpec('sites', {'states': ['theta'], 'low': 0.0, 'high': 2 * math.pi})
class LinkElement(Element):
"""Edge of a network with a weight `w`.
Couplings along the edge read the weight, as the strength of a power line or of a synapse.
Args:
label:
The label of the edge or the group on the edges.
w:
The weight of the edge, or one weight per edge.
space:
The network of the edges, or `None` for one edge.
on:
`'edges'` for one member on every edge of the network, `'hyperedges'` for one on every hyperedge, or `None`.
Examples:
>>> from skcomplex.systems.physics.common.oscillators import LinkElement
>>> LinkElement('link', w=0.5).w
0.5
"""
def __init__(
self,
label: str,
*,
w: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
space: BaseSpace | None = None,
on: str | None = None,
) -> None:
super().__init__(label, space=space, on=on)
self.w = w
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 EdgeCouplingInteraction(Interaction):
"""Kuramoto coupling along the weighted edges of a network.
The coupling is `theta_i' += K w_ij sin(theta_j - theta_i - alpha)` at both ends of every edge.
The coupling runs once per edge of the network of its oscillators and reads the weight `w` of the edge from the
element on the edges, as the lines of a power grid or the gap junctions of neurons.
Args:
label:
The label of the interaction, unique among the components of its system.
among:
The path of the group of oscillators on the nodes.
along:
`True` for the edges of the network of the oscillators, or the name of a layer.
K:
The coupling strength.
alpha:
The phase lag.
Examples:
>>> from skcomplex.systems.physics.synchronization import EdgeCouplingInteraction
>>> EdgeCouplingInteraction('coupling', among='nodes', K=0.5).K
0.5
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
among: Role,
along: bool | str | None = True,
K: float = 1.0,
alpha: float = 0.0,
) -> None:
super().__init__(label, among=among, along=along)
self.K = K
self.alpha = alpha
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the turn of the phases at both ends of an edge towards each other.
Args:
context:
The namespace of the ends `source` and `target`, the edge `edge`, the time `t`, and the parameters.
"""
super()._prepare(context)
s = context
first, second = s.source.theta, s.target.theta
weight = s.K * s.edge.w
self.laws_ = [
RateLaw(second.diff(s.t), weight * sin(first - second - s.alpha)),
RateLaw(first.diff(s.t), weight * sin(second - first - s.alpha)),
]