sop#

torchspin.sop(spins, comp, dtype=torch.complex128, device='cpu')[source]#

Build a spin operator matrix for a (multi-)spin system.

Parameters:
  • spins – Sequence of spin quantum numbers, e.g. [0.5], [0.5, 1.0]. A bare float is also accepted for single-spin systems.

  • comp –

    Operator specification (multiple formats):

    String syntax — one character per spin: characters e x y z + - give the component for each spin in order. For a single-spin system the string may be just one character.

    Integer syntax — a single int 0–5 (0=e 1=x 2=y 3=z 4=+ 5=-) for single-spin systems (mirrors EasySpin’s numeric shorthand).

    Flat-pair syntax — a 2-element list [spin_index, comp_index] (1-based spin index) for selecting one spin’s component in a multi-spin system. All other spins receive the identity operator.

    Multi-pair syntax — a list of [spin_index, comp_index] pairs for product operators, e.g. [[1, 1], [2, 3]].

    List-of-strings syntax — a list of single-character strings (e.g. ['x', 'y', 'z']) to return a list of operator matrices.

  • dtype (dtype) – Returned dtype. Default torch.complex128.

  • device (str) – PyTorch device string. Default 'cpu'.

Returns:

torch.Tensor or list[torch.Tensor] – Square matrix of shape (nStates, nStates), or a list of matrices when comp is a list of strings.

Examples

>>> Sx = sop(0.5, 'x')               # 2×2 Sx (single spin)
>>> Sx = sop(0.5, 1)                 # same, numeric index
>>> Sx, Sy, Sz = sop(0.5, ['x', 'y', 'z'])   # list syntax
>>> SxI = sop([0.5, 1.0], 'xe')     # 6×6: Sx⊗I
>>> SxI = sop([0.5, 0.5], [1, 1])   # same, flat-pair [spin_idx=1, comp_idx=x]
>>> SzIz = sop([0.5, 0.5], [[1, 3], [2, 3]])  # product Sz1⊗Sz2