Skip to content

Potts

The q-state Potts system on a torus.

  • Class: PottsSystem
  • Import: from skcomplex.systems.physics.statistical_mechanics import PottsSystem
  • Field: physics/statistical_mechanics
  • Topics: lattice, Monte Carlo, phase transition, spins
  • References:
    • Potts 1952
    • Wu 1982

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 PottsSystem

trajectory = PottsSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
size 64
q 3
temperature 1.0
J 1.0
sampler 'heat-bath'
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 PottsSystem(systems.BaseSystem):
    """The q-state Potts system on a torus.

    The system orders below the critical temperature `1 / ln(1 + sqrt q)`.

    The system has the states `spins.color`.

    Args:
        size:
            The side of the square lattice, or its shape.

        q:
            The number of states.

        temperature:
            The temperature in units of the coupling.

        J:
            The coupling between neighbouring spins.

        sampler:
            The acceptance rule, `'metropolis'`, `'glauber'`, or `'heat-bath'`.

        random_state:
            The seed or generator of the random initial states.

        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 PottsSystem
        >>> PottsSystem(8, q=4).prepare().system_.interactions[0].q
        4
    """

    field = 'physics/statistical_mechanics'
    topics = ('lattice', 'Monte Carlo', 'phase transition', 'spins')
    references = ('Potts 1952', 'Wu 1982')
    until = 200
    dt = 1

    def __init__(
        self,
        size: int | Sequence[int] = 64,
        *,
        q: int = 3,
        temperature: float = 1.0,
        J: float = 1.0,
        sampler: str = 'heat-bath',
        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.q = q
        self.temperature = temperature
        self.J = J
        self.sampler = sampler
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the q-state Potts system on a torus, which orders below the temperature `1 / ln(1 + sqrt q)`.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        shape = IsingSystem._get_square(self.size)
        colors = np.random.default_rng(self.random_state).integers(0, self.q, size=shape).astype(float)
        group = PottsSpinElement(
            'spins',
            color=colors.ravel(),
            J=self.J,
            temperature=self.temperature,
            space=LatticeSpace(shape),
        )
        self.system_ = systems.System(
            self.label,
            elements=[group],
            interactions=[PottsSamplingInteraction('sampling', target='spins', q=self.q)],
            solver=MetropolisSolver(
                moves={'spins.color': 'random-value'},
                rule=self.sampler,
                values={'spins.color': tuple(float(value) for value in range(self.q))},
            ),
        )

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

Interactions:

  • PottsSamplingInteraction, from Interaction
class PottsSpinElement(Element):
    """Spins of the q-state Potts system, each in a state from 0 to `q - 1`.

    Every spin has its coupling `J` and its temperature.

    A `PottsSamplingInteraction` redraws the states by Monte Carlo sweeps at the temperature of the spins.

    Args:
        label:
            The label of the spin or the lattice of spins.

        color:
            The initial state, or one state per site.

        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 PottsSpinElement
        >>> PottsSpinElement('spin').temperature
        1.0
    """

    def __init__(
        self,
        label: str,
        *,
        color: object = 0.0,
        J: float = 1.0,
        temperature: Annotated[float, RealSet.open(0, oo)] = 1.0,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, space=space)
        self.color = color
        self.J = J
        self.temperature = temperature

class PottsSamplingInteraction(SpinSamplingInteraction):
    """Boltzmann weight of Potts spins in states `0` to `q - 1`, whose local energy is `-J` times the like neighbours.

    The coupling `J` and the temperature are values of the spins, and the `MetropolisSolver` of the system proposes
    states drawn from the `q` states, `MetropolisSolver(moves={'spins.color': 'random-value'},
    values={'spins.color': range(q)})`.

    Args:
        label:
            The label of the interaction, unique among the components of its system.

        target:
            The path of the group of spins.

        q:
            The number of states.

        state:
            The name of the state that holds the spin.

    Examples:
        >>> from skcomplex.systems.physics.statistical_mechanics._spins import PottsSamplingInteraction
        >>> PottsSamplingInteraction('potts', target='spins', q=4).q
        4
    """

    def __init__(self, label: str, *, target: Role, q: int = 3, state: str = 'color') -> None:
        super().__init__(label, target=target, state=state, energy=self._get_energy)
        self.q = q

    def _get_energy(self, namespace: SimpleNamespace) -> Expression:
        """Return the local energy `-J` times the number of neighbours in the spin's state."""
        color, other = getattr(namespace.target, self.state), getattr(namespace.target.other, self.state)
        return -namespace.target.J * neighbors(where(other == color, 1, 0))