XY
The XY system of planar spins on a torus.
- Class:
XYSystem - Import:
from skcomplex.systems.physics.statistical_mechanics import XYSystem - Field:
physics/statistical_mechanics - Topics:
lattice,Monte Carlo,vortices,spins - References:
- Kosterlitz and Thouless 1973
- 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.statistical_mechanics import XYSystem
trajectory = XYSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
size |
64 |
temperature |
0.5 |
J |
1.0 |
width |
1.0 |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | discrete |
| Space | lattice |
| Laws | sampling |
| Randomness | stochastic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class XYSystem(systems.BaseSystem):
"""The XY system of planar spins on a torus.
Its vortices bind below the Kosterlitz-Thouless point.
The system has the angles `spins.theta`.
Args:
size:
The side of the square lattice, or its shape.
temperature:
The temperature in units of the coupling.
J:
The coupling between neighbouring spins.
width:
The largest change of a proposed rotation.
random_state:
The seed or generator of the random initial angles.
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.statistical_mechanics import XYSystem
>>> XYSystem(8).prepare().system_.solver.width
1.0
"""
field = 'physics/statistical_mechanics'
topics = ('lattice', 'Monte Carlo', 'vortices', 'spins')
references = ('Kosterlitz and Thouless 1973', 'Jensen 2023')
until = 200
dt = 1
def __init__(
self,
size: int | Sequence[int] = 64,
*,
temperature: float = 0.5,
J: float = 1.0,
width: float = 1.0,
random_state: int | np.random.Generator | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.size = size
self.temperature = temperature
self.J = J
self.width = width
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the planar spins of a torus at random angles.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
shape = IsingSystem._get_square(self.size)
angles = np.random.default_rng(self.random_state).uniform(0, 2 * np.pi, size=shape)
group = XYSpinElement(
'spins',
theta=angles.ravel(),
J=self.J,
temperature=self.temperature,
space=LatticeSpace(shape),
)
self.system_ = systems.System(
self.label,
elements=[group],
interactions=[XYSamplingInteraction('sampling', target='spins')],
solver=MetropolisSolver(moves={'spins.theta': 'rotate'}, width=self.width),
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
XYSpinElement, fromElement
Interactions:
XYSamplingInteraction, fromInteraction
class XYSpinElement(Element):
"""Planar spin of the XY system, an angle `theta`.
The spin has its coupling `J` and its temperature.
An `XYSamplingInteraction` rotates the angles by Monte Carlo sweeps at the temperature of the spins.
Args:
label:
The label of the spin or the lattice group.
theta:
The initial angle.
J:
The coupling between neighbouring spins.
temperature:
The temperature in units of the coupling.
space:
The lattice of the spins, or `None` for one spin.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import XYSpinElement
>>> XYSpinElement('spin').temperature
0.5
"""
def __init__(
self,
label: str,
*,
theta: Annotated[object, Period(2 * math.pi)] = 0.0,
J: float = 1.0,
temperature: Annotated[float, RealSet.open(0, oo)] = 0.5,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.theta = theta
self.J = J
self.temperature = temperature
class XYSamplingInteraction(SpinSamplingInteraction):
"""Boltzmann weight of planar spins at angles `theta`, whose local energy is `-J sum_j cos(theta - theta_j)`.
The coupling `J` and the temperature are values of the spins, and the `MetropolisSolver` of the system rotates the
angles by a uniform number in `[-width, width]`, `MetropolisSolver(moves={'spins.theta': 'rotate'}, width=1.0)`.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the group of spins.
state:
The name of the state that holds the angle.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics._spins import XYSamplingInteraction
>>> XYSamplingInteraction('xy', target='spins').state
'theta'
"""
def __init__(self, label: str, *, target: Role, state: str = 'theta') -> None:
super().__init__(label, target=target, state=state, energy=self._get_energy)
def _get_energy(self, namespace: SimpleNamespace) -> Expression:
"""Return the local energy `-J sum_j cos(theta - theta_j)` of a spin."""
angle, other = getattr(namespace.target, self.state), getattr(namespace.target.other, self.state)
return -namespace.target.J * neighbors(cos(angle - other))