TASEP
The totally asymmetric simple exclusion process with parallel update.
- Class:
TASEPSystem - Import:
from skcomplex.systems.physics.statistical_mechanics import TASEPSystem - Field:
physics/statistical_mechanics - Topics:
lattice,stochastic,exclusion,traffic,nonequilibrium - References:
- Derrida, Domany, and Mukamel 1992
- Schütz 2001
- Helbing 2001
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 TASEPSystem
trajectory = TASEPSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_sites |
200 |
p |
0.5 |
alpha |
0.3 |
beta |
0.7 |
ring |
False |
density |
0.5 |
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 | continuous |
| Space | lattice |
| Laws | rate |
| Randomness | unknown |
| Domains | boolean |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class TASEPSystem(BaseSystem):
"""The totally asymmetric simple exclusion process with parallel update.
The process runs on an open line or a ring.
Every step all particles whose right neighbour is empty hop to it with probability `p` at once, with one draw for
every pair of neighbouring sites. On an open line particles enter the first site with probability `alpha` and
leave the last site with probability `beta`. On a ring at density `rho` the current is `(1 - sqrt(1 - 4 p rho (1 -
rho))) / 2`. On an open line the entry and exit probabilities select the low-density, high-density, or
maximal-current phase. The system has the occupations `lane.occupied`, and on an open line the expected entries
`lane.entry` and exits `lane.exit` of every step.
Args:
n_sites:
The number of sites.
p:
The probability of a hop.
alpha:
The probability of an entry at the left end of an open line.
beta:
The probability of an exit at the right end of an open line.
ring:
Whether the line is a ring instead of an open line.
density:
The initial fraction of occupied sites.
random_state:
The seed or generator of the initial occupations.
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 TASEPSystem
>>> [interaction.label for interaction in TASEPSystem(20).prepare().system_.interactions]
['hops', 'entry', 'exit']
"""
field = 'physics/statistical_mechanics'
topics = ('lattice', 'stochastic', 'exclusion', 'traffic', 'nonequilibrium')
references = ('Derrida, Domany, and Mukamel 1992', 'Schütz 2001', 'Helbing 2001')
until = 500
dt = 1
def __init__(
self,
n_sites: int = 200,
*,
p: float = 0.5,
alpha: float = 0.3,
beta: float = 0.7,
ring: bool = False,
density: float = 0.5,
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.n_sites = n_sites
self.p = p
self.alpha = alpha
self.beta = beta
self.ring = ring
self.density = density
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set `system_` to the lane with random occupied sites, its hops, and on an open line its entry and exit.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
rng = np.random.default_rng(self.random_state)
occupied = np.zeros(self.n_sites)
occupied[rng.choice(self.n_sites, round(self.density * self.n_sites), replace=False)] = 1.0
boundary = 'periodic' if self.ring else 'fixed'
lane = ExclusionSiteElement('lane', occupied=occupied, space=LatticeSpace(self.n_sites, boundary=boundary))
interactions: list[Interaction] = [ParallelHopInteraction('hops', target='lane', p=self.p, boundary=boundary)]
if not self.ring:
interactions += [
LaneEntryInteraction('entry', target='lane[0]', alpha=self.alpha),
LaneExitInteraction('exit', target=f'lane[{self.n_sites - 1}]', beta=self.beta),
]
self.system_ = System(self.label, elements=[lane], interactions=interactions)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
ExclusionSiteElement, fromElement
Interactions:
ParallelHopInteraction, fromInteractionLaneEntryInteraction, fromInteractionLaneExitInteraction, fromInteraction
class ExclusionSiteElement(Element):
"""Sites of the totally asymmetric simple exclusion process.
Every site is empty at 0 or holds one particle at 1.
Args:
label:
The label of the site or the lane of sites.
occupied:
The initial occupation, or one occupation per site.
space:
The lattice of the sites, or `None` for one site.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import ExclusionSiteElement
>>> ExclusionSiteElement('site').occupied
0.0
"""
def __init__(
self,
label: str,
*,
occupied: Annotated[object, FiniteEnumeratedSet([0, 1])] = 0.0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.occupied = occupied
class ParallelHopInteraction(Interaction):
"""Hops of particles to the next site of a lane, all at once.
In one step every particle whose next site is empty hops to it with probability `p`. One draw decides the hop
between two sites, and both sites read it, so particles are never lost or doubled. On a fixed boundary the last
site has no next site. It is the parallel update of cars on a road, ribosomes on a messenger RNA, or molecular
motors on a filament.
Args:
label:
The label of the interaction.
target:
The path of the sites, whose value is `occupied`.
p:
The probability of a hop.
boundary:
`'periodic'` for a ring, or `'fixed'` for an open line.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import ParallelHopInteraction
>>> ParallelHopInteraction('hops', target='lane', p=0.75).p
0.75
"""
def __init__(
self,
label: str,
*,
target: Role,
p: Annotated[float, RealSet.closed(0, 1)] = 0.5,
boundary: str = 'periodic',
) -> None:
super().__init__(label)
self.target = target
self.p = p
self.boundary = boundary
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the flow `hops` of the particles to the next site in one step.
A particle leaves a site when it hops, and enters the next site with the draw of the site it left.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
occupied = context.target.occupied
ahead = shift_member(occupied, 1, boundary=self.boundary)
leaves = occupied * (1 - ahead) * bernoulli('hop', context.p)
self.laws_ = [UpdateLaw({occupied: -1, ahead: 1}, leaves, increment=True, label=self.label)]
class LaneEntryInteraction(Interaction):
"""Entry of particles at the first site of an open lane.
In one step a particle enters the empty first site with probability `alpha`, as cars join a road from a ramp.
Args:
label:
The label of the interaction.
target:
The path of the first site, whose value is `occupied`.
alpha:
The probability of an entry.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import LaneEntryInteraction
>>> LaneEntryInteraction('entry', target='lane[0]', alpha=0.4).alpha
0.4
"""
def __init__(self, label: str, *, target: Role, alpha: Annotated[float, RealSet.closed(0, 1)] = 0.3) -> None:
super().__init__(label)
self.target = target
self.alpha = alpha
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the occupation of the first site after an entry.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
occupied = context.target.occupied
enters = (1 - occupied) * bernoulli('entry', context.alpha)
self.laws_ = [UpdateLaw({occupied: +1}, enters, increment=True, label=self.label)]
class LaneExitInteraction(Interaction):
"""Exit of particles at the last site of an open lane.
In one step the particle on the last site leaves with probability `beta`, as cars leave a road by an exit.
Args:
label:
The label of the interaction.
target:
The path of the last site, whose value is `occupied`.
beta:
The probability of an exit.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import LaneExitInteraction
>>> LaneExitInteraction('exit', target='lane[9]', beta=0.6).beta
0.6
"""
def __init__(self, label: str, *, target: Role, beta: Annotated[float, RealSet.closed(0, 1)] = 0.7) -> None:
super().__init__(label)
self.target = target
self.beta = beta
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the occupation of the last site after an exit.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
occupied = context.target.occupied
leaves = occupied * bernoulli('exit', context.beta)
self.laws_ = [UpdateLaw({occupied: -1}, leaves, increment=True, label=self.label)]