Skip to content

Dissipative zero-range process on a tree

The dissipative zero-range process on a tree.

  • Class: DissipativeZeroRangeSystem
  • Import: from skcomplex.systems.physics.statistical_mechanics import DissipativeZeroRangeSystem
  • Field: physics/statistical_mechanics
  • Topics: zero-range process, energy cascade, nonequilibrium, tree, jump process
  • References:
    • Bertin 2021
    • Bertin 2005

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 DissipativeZeroRangeSystem

trajectory = DissipativeZeroRangeSystem().prepare().simulate()

Parameters

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

Parameter Default
n_levels 5
branches 2
nu 1.0
alpha 0.5
beta_ext 1.0
epsilon0 1.0
dissipation 1.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 jump
Randomness stochastic
Domains real, vector
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class DissipativeZeroRangeSystem(BaseSystem):
    """The dissipative zero-range process on a tree.

    Energy is injected at the root and lost at the leaves.

    Level `j` of the tree has `m^(j - 1)` nodes, each with `m` branches to the next level. A quantum `epsilon0` of
    energy crosses a branch between levels `j` and `j + 1` at rate `nu_j = nu k_j^alpha`, `k_j = m^(j - 1)`, in either
    direction from an occupied node. A reservoir at the inverse temperature `beta_ext` exchanges quanta with the root,
    adding one at rate `nu exp(-beta_ext epsilon0)` and removing one at rate `nu`, and every leaf loses a quantum at the
    rate `dissipation`. The stationary distribution is a product of geometric laws `z_j^n`, with `z_j` the solution of
    the linear balance of the currents `nu_j (z_j - z_(j + 1))` at every level, and the injected flux is `nu
    (exp(-beta_ext epsilon0) - z_1)`. The system has the quanta `nodes.n` of the nodes in breadth-first order, from the
    root to the leaves.

    Args:
        n_levels:
            The number of levels `M`.

        branches:
            The number `m` of branches of every node above the leaves.

        nu:
            The rate scale of transfers and of the exchange with the reservoir.

        alpha:
            The exponent of the growth of the transfer rate with the pseudo wave number `k_j`.

        beta_ext:
            The inverse temperature of the reservoir.

        epsilon0:
            The quantum of energy.

        dissipation:
            The rate at which every leaf loses a quantum.

        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 DissipativeZeroRangeSystem
        >>> system = DissipativeZeroRangeSystem(3, branches=3).prepare().system_
        >>> system.elements[0].size, len(system.interactions)
        (13, 14)
    """

    field = 'physics/statistical_mechanics'
    topics = ('zero-range process', 'energy cascade', 'nonequilibrium', 'tree', 'jump process')
    references = ('Bertin 2021', 'Bertin 2005')
    until = 200.0
    dt = 1.0

    def __init__(
        self,
        n_levels: int = 5,
        *,
        branches: int = 2,
        nu: float = 1.0,
        alpha: float = 0.5,
        beta_ext: float = 1.0,
        epsilon0: float = 1.0,
        dissipation: float = 1.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_levels = n_levels
        self.branches = branches
        self.nu = nu
        self.alpha = alpha
        self.beta_ext = beta_ext
        self.epsilon0 = epsilon0
        self.dissipation = dissipation

    @staticmethod
    def _get_level_start(level: int, branches: int) -> int:
        """Return the index of the first node of a level of a tree.

        The levels are counted from level 1, in breadth-first order.
        """
        return (branches ** (level - 1) - 1) // (branches - 1)

    @staticmethod
    def _get_tree_layout(n_levels: int, branches: int) -> Array:
        """Return the drawing positions of the nodes of a tree in breadth-first order.

        The positions lie on ellipses around the root.
        """
        rings = []
        for level in range(1, n_levels + 1):
            width = branches ** (level - 1)
            radius = (level - 1) / max(n_levels - 1, 1)
            angles = 2 * np.pi * (np.arange(width) + 0.5) / width
            rings.append(radius * np.column_stack([np.cos(angles), TREE_ASPECT * np.sin(angles)]))
        return np.concatenate(rings)

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the nodes of the tree, the transfers between levels, the injection, and the dissipation.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        n_nodes = self._get_level_start(self.n_levels + 1, self.branches)
        nodes = TreeNodeElement('nodes', x=self._get_tree_layout(self.n_levels, self.branches), size=n_nodes)
        interactions: list[BaseInteraction] = []
        for level in range(1, self.n_levels):
            rate = self.nu * float(self.branches ** (level - 1)) ** self.alpha
            start, below = self._get_level_start(level, self.branches), self._get_level_start(level + 1, self.branches)
            for index in range(self.branches ** (level - 1)):
                for branch in range(self.branches):
                    child = below + self.branches * index + branch
                    link = (f'nodes[{start + index}]', f'nodes[{child}]')
                    interactions.append(
                        ZeroRangeHopInteraction(f'transfer_{start + index}_{child}', link=link, p=rate, q=rate, b=0.0),
                    )
        leaves = tuple(
            f'nodes[{index}]' for index in range(self._get_level_start(self.n_levels, self.branches), n_nodes)
        )
        interactions += [
            ReservoirInteraction(
                'injection',
                sites=('nodes[0]',),
                inflow=self.nu * np.exp(-self.beta_ext * self.epsilon0),
                outflow=self.nu,
            ),
            ReservoirInteraction('dissipation', sites=leaves, outflow=self.dissipation),
        ]
        self.system_ = System(
            self.label,
            elements=[nodes],
            interactions=interactions,
            space=ContinuousSpace(n_dim=2),
            backend=NumbaBackend(),
        )

Components

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

Elements:

Interactions:

  • ZeroRangeHopInteraction, from Interaction
  • ReservoirInteraction, from Interaction
class TreeNodeElement(Element):
    """Nodes of a tree that hold a number `n` of energy quanta each.

    Every node is drawn at a fixed position.

    Args:
        label:
            The label of the node or the group.

        n:
            The initial number of quanta, or one number per node.

        x:
            The position of the node in the drawing of the tree, or one position per node.

        size:
            The number of nodes, or `None` for one.

    Examples:
        >>> from skcomplex.systems.physics.statistical_mechanics import TreeNodeElement
        >>> TreeNodeElement('root').n
        0.0
    """

    visual = VisualSpec(
        'points',
        {'position': 'x', 'radius': 0.04, 'color_by': 'n', 'color_range': (0.0, 2.0), 'states': (), 'trail': 0},
    )

    def __init__(self, label: str, *, n: object = 0.0, x: object = 0.0, size: int | None = None) -> None:
        super().__init__(label, size=size)
        self.n = n
        self.x = x

class ZeroRangeHopInteraction(Interaction):
    """Hop of one particle along a link.

    The particle hops forward at rate `p u(n)` and backward at rate `q u(n')`.

    The rate depends only on the occupation of the departure site, through `u(n) = 1 + b / n`. It is a transfer of one
    particle from the first site to the second, with jumps back at the reverse rate.

    Args:
        label:
            The label of the link.

        link:
            The departure and the arrival site of a forward hop.

        p:
            The forward rate scale.

        q:
            The backward rate scale.

        b:
            The strength of the decrease of `u(n)` with the occupation, 0 for a constant rate.

    Examples:
        >>> from skcomplex.systems.physics.statistical_mechanics import ZeroRangeHopInteraction
        >>> ZeroRangeHopInteraction('hop', link=['sites[0]', 'sites[1]']).b
        4.0
    """

    def __init__(
        self,
        label: str,
        *,
        link: tuple[Role, ...],
        p: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        q: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
        b: Annotated[float, RealSet.closed_open(0, oo)] = 4.0,
    ) -> None:
        super().__init__(label)
        self.link = link
        self.p = p
        self.q = q
        self.b = b

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the hops forward from the first site of the link and back from the second.

        Args:
            context:
                The namespace of the two sites, the time `t`, and the parameters.
        """
        super()._prepare(context)
        first, second = context.link
        self.laws_ = [
            JumpLaw(context.p * self._get_departure_rate(first.n, context.b), {first.n: -1, second.n: 1}),
            JumpLaw(context.q * self._get_departure_rate(second.n, context.b), {second.n: -1, first.n: 1}),
        ]

    @staticmethod
    def _get_departure_rate(n: Expression, b: Expression) -> Expression:
        """Return the zero-range rate `u(n) = 1 + b / n` of a site with `n` particles.

        The rate is 0 for an empty site.
        """
        return where(n > 0, 1 + b / where(n > 0, n, 1), 0)

class ReservoirInteraction(Interaction):
    """Reservoir that adds and removes particles at its sites.

    The reservoir adds one particle to each of its sites at rate `inflow` and removes one at rate `outflow`.

    A particle leaves only an occupied site. With exclusion a particle enters only an empty site. It is a transfer of
    one particle from the environment into every site, with jumps back to the environment at the outflow rate.

    Args:
        label:
            The label of the reservoir.

        sites:
            The sites in contact with the reservoir.

        inflow:
            The rate at which a particle enters a site.

        outflow:
            The rate at which a particle leaves an occupied site.

        exclusion:
            Whether a site holds at most one particle.

    Examples:
        >>> from skcomplex.systems.physics.statistical_mechanics import ReservoirInteraction
        >>> ReservoirInteraction('bath', sites=('lane[0]',), inflow=0.5).outflow
        0.0
    """

    def __init__(
        self,
        label: str,
        *,
        sites: tuple[Role, ...],
        inflow: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
        outflow: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
        exclusion: bool = False,
    ) -> None:
        super().__init__(label)
        self.sites = sites
        self.inflow = inflow
        self.outflow = outflow
        self.exclusion = exclusion

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the entries and the exits of a particle at every site.

        Under exclusion a particle enters only an empty site, and a particle leaves only an occupied one.

        Args:
            context:
                The namespace of the sites, the time `t`, and the parameters.
        """
        super()._prepare(context)
        self.laws_ = []
        for site in context.sites:
            entry = context.inflow * (1 - site.n if self.exclusion else 1)
            self.laws_ += [
                JumpLaw(entry, {site.n: 1}),
                JumpLaw(context.outflow * where(site.n > 0, 1, 0), {site.n: -1}),
            ]