Invariant
Invariant utils
- twiss.invariant.cs_invariant(twiss: torch.Tensor, orbit: torch.Tensor) torch.Tensor [source]
Compute linear invariants for a given CS twiss and orbit
- Parameters:
twiss (Tensor) – CS twiss ax, bx, ay, by
orbit (Tensor) – orbit
- Returns:
[jx, jy] for each turn
- Return type:
Tensor
Note
Orbit is assumed to have the form […, [qx_i, px_i, qy_i, py_i], …]
Examples
>>> from math import pi >>> from twiss.matrix import rotation >>> from twiss.wolski import twiss >>> from twiss.convert import wolski_to_cs >>> m = rotation(*2*pi*torch.tensor([0.12, 0.31], dtype=torch.float64)) >>> t, n, w = twiss(m) >>> cs = wolski_to_cs(w) >>> x = torch.tensor([[1, 0, 1, 0]], dtype=torch.float64) >>> torch.allclose(cs_invariant(cs, x), cs_invariant(cs, torch.func.vmap(lambda x: m @ x)(x))) True
- twiss.invariant.invariant(normal: torch.Tensor, orbit: torch.Tensor) torch.Tensor [source]
Compute linear invariants for a given normalization matrix and orbit
- Parameters:
normal (Tensor, even-dimension, symplectic) – normalization matrix
orbit (Tensor) – orbit
- Returns:
[jx, jy] for each turn
- Return type:
Tensor
Note
Orbit is assumed to have the form […, [qx_i, px_i, qy_i, py_i], …]
Examples
>>> from math import pi >>> from twiss.matrix import rotation >>> from twiss.wolski import twiss >>> m = rotation(*2*pi*torch.tensor([0.12, 0.31], dtype=torch.float64)) >>> t, n, w = twiss(m) >>> x = torch.tensor([[1, 0, 1, 0]], dtype=torch.float64) >>> torch.allclose(invariant(n, x), invariant(n, torch.func.vmap(lambda x: m @ x)(x))) True
- twiss.invariant.lb_invariant(twiss: torch.Tensor, orbit: torch.Tensor) torch.Tensor [source]
Compute linear invariants for a given LB twiss and orbit
- Parameters:
twiss (Tensor) – LB twiss a1x, b1x, a2x, b2x, a1y, b1y, a2y, b2y, u, v1, v2
orbit (Tensor) – orbit
- Returns:
[jx, jy] for each turn
- Return type:
Tensor
Note
Orbit is assumed to have the form […, [qx_i, px_i, qy_i, py_i], …]
Examples
>>> from math import pi >>> from twiss.matrix import rotation >>> from twiss.wolski import twiss >>> from twiss.convert import wolski_to_lb >>> m = rotation(*2*pi*torch.tensor([0.12, 0.31], dtype=torch.float64)) >>> t, n, w = twiss(m) >>> lb = wolski_to_lb(w) >>> x = torch.tensor([[1, 0, 1, 0]], dtype=torch.float64) >>> torch.allclose(lb_invariant(lb, x), lb_invariant(lb, torch.func.vmap(lambda x: m @ x)(x))) True