Transport

Transport matrix utils

twiss.transport.cs_transport(pars1: torch.Tensor, pars2: torch.Tensor, *mu12: torch.Tensor) torch.Tensor[source]

Generate transport matrix using CS twiss data between given locations

Parameters:
  • pars1 (Tensor) – twiss parameters at the 1st location

  • pars2 (Tensor) – twiss parameters at the 2nd location

  • *mu12 (Tensor) – phase advances between locations

Return type:

Tensor

Examples

>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> from twiss.wolski import advance
>>> from twiss.normal import normal_to_wolski
>>> from twiss.convert import wolski_to_cs
>>> t = torch.tensor([[1.0, 0.1], [0.0, 1.0]], dtype=torch.float64)
>>> t = torch.block_diag(t, t)
>>> m = rotation(*2*pi*torch.tensor([0.12, 0.31], dtype=torch.float64))
>>> _, n1, w1 = twiss(m @ t)
>>> mu12, n2 = advance(n1, t)
>>> w2 = normal_to_wolski(n2)
>>> t_cs = cs_transport(*torch.func.vmap(wolski_to_cs)(torch.stack([w1, w2])), *mu12)
>>> torch.allclose(t, t_cs)
True
twiss.transport.lb_transport(pars1: torch.Tensor, pars2: torch.Tensor, *mu12: torch.Tensor) torch.Tensor[source]

Generate transport matrix using LB twiss data between given locations

Parameters:
  • pars1 (Tensor) – twiss parameters at the 1st location

  • pars2 (Tensor) – twiss parameters at the 2nd location

  • *mu12 (Tensor) – phase advances between locations

Return type:

Tensor

Examples

>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> from twiss.wolski import advance
>>> from twiss.normal import normal_to_wolski
>>> from twiss.convert import wolski_to_lb
>>> t = torch.tensor([[1.0, 0.1], [0.0, 1.0]], dtype=torch.float64)
>>> t = torch.block_diag(t, t)
>>> m = rotation(*2*pi*torch.tensor([0.12, 0.31], dtype=torch.float64))
>>> _, n1, w1 = twiss(m @ t)
>>> mu12, n2 = advance(n1, t)
>>> w2 = normal_to_wolski(n2)
>>> t_lb = lb_transport(*torch.func.vmap(wolski_to_lb)(torch.stack([w1, w2])), *mu12)
>>> torch.allclose(t, t_lb)
True
twiss.transport.momenta(matrix: torch.Tensor, qx1: torch.Tensor, qx2: torch.Tensor, qy1: torch.Tensor, qy2: torch.Tensor) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor][source]

Compute momenta at positions 1 & 2 for given transport matrix and coordinates at 1 & 2

Parameters:
  • matrix (torch.Tensor, even-dimension, symplectic) – transport matrix between

  • qx1 (Tensor) – x & y coordinates at 1 & 2

  • qx2 (Tensor) – x & y coordinates at 1 & 2

  • qy1 (Tensor) – x & y coordinates at 1 & 2

  • qy2 (Tensor) – x & y coordinates at 1 & 2

Returns:

px1, px2, py1, py2

Return type:

tuple[Tensor, Tensor, Tensor, Tensor]

Examples

>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> m = rotation(*2*pi*torch.tensor([0.12, 0.31], dtype=torch.float64))
>>> x1 = torch.tensor([1.0, 0.0, 1.0, 0.0], dtype=torch.float64)
>>> x2 = m @ x1
>>> qx1, px1, qy1, py1 = x1
>>> qx2, px2, qy2, py2 = x2
>>> Px1, Px2, Py1, Py2 = momenta(m, qx1, qx2, qy1, qy2)
>>> all(torch.allclose(x, y) for x, y in zip((px1, px2, py1, py2), (Px1, Px2, Py1, Py2)))
True
twiss.transport.transport(n1: torch.Tensor, n2: torch.Tensor, *mu12: torch.Tensor) torch.Tensor[source]

Generate transport matrix using normalization matrices and phase advances between locations

Parameters:
  • n1 (Tensor, even-dimension, symplectic) – normalization matrix at the 1st location

  • n2 (Tensor, even-dimension, symplectic) – normalization matrix at the 2nd location

  • *mu12 (Tensor) – phase advances between locations

Return type:

Tensor

Examples

>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> from twiss.wolski import advance
>>> t = torch.tensor([[1.0, 0.1], [0.0, 1.0]], dtype=torch.float64)
>>> m = rotation(2*pi*torch.tensor(0.12, dtype=torch.float64))
>>> _, n1, w1 = twiss(m @ t)
>>> mu12, n2 = advance(n1, t)
>>> transport(n1, n2, *mu12)
tensor([[1.0000, 0.1000],
        [0.0000, 1.0000]], dtype=torch.float64)
twiss.transport.wolski_transport(pars1: torch.Tensor, pars2: torch.Tensor, *mu12: torch.Tensor) torch.Tensor[source]

Generate transport matrix using Wolski matrices and phase advances between locations

Parameters:
  • pars1 (Tensor) – Wolski matrices at the 1st location

  • pars2 (Tensor) – Wolski matrices at the 2nd location

  • *mu12 (Tensor) – phase advances between locations

Return type:

Tensor

Examples

>>> from math import pi
>>> import torch
>>> from twiss.matrix import rotation
>>> from twiss.wolski import twiss
>>> from twiss.wolski import propagate
>>> from twiss.wolski import advance
>>> t = torch.tensor([[1.0, 0.1], [0.0, 1.0]], dtype=torch.float64)
>>> m = rotation(2*pi*torch.tensor(0.12, dtype=torch.float64))
>>> _, n1, w1 = twiss(m @ t)
>>> mu12, n2 = advance(n1, t)
>>> w2 = propagate(w1, t)
>>> torch.allclose(t, wolski_transport(w1, w2, *mu12))
True