qnet.algebra.library.spin_algebra module

Definitions for an algebra on spin (angular momentum) Hilbert spaces, both for integer and half-integer spin

Summary

Classes:

Jminus Lowering operator on a spin space
Jplus Raising operator of a spin space
Jz Spin (angular momentum) operator in z-direction
SpinOperator Base class for operators in a spin space
SpinSpace A Hilbert space for an integer or half-integer spin system

Functions:

Jmjmcoeff Eigenvalue of the \(\Op{J}_{-}\) (Jminus) operator
Jpjmcoeff Eigenvalue of the \(\Op{J}_{+}\) (Jplus) operator
Jzjmcoeff Eigenvalue of the \(\Op{J}_z\) (Jz) operator
SpinBasisKet Constructor for a BasisKet for a SpinSpace

__all__: Jminus, Jplus, Jz, SpinBasisKet, SpinOperator, SpinSpace

Reference

class qnet.algebra.library.spin_algebra.SpinSpace(label, *, spin, basis=None, local_identifiers=None, order_index=None)[source]

Bases: qnet.algebra.core.hilbert_space_algebra.LocalSpace

A Hilbert space for an integer or half-integer spin system

For a given spin \(N\), the resulting Hilbert space has dimension \(2 N + 1\) with levels labeled from \(-N\) to \(+N\) (as strings)

For an integer spin:

>>> hs = SpinSpace(label=0, spin=1)
>>> hs.dimension
3
>>> hs.basis_labels
('-1', '0', '+1')

For a half-integer spin:

>>> hs = SpinSpace(label=0, spin=sympy.Rational(3, 2))
>>> hs.spin
3/2
>>> hs.dimension
4
>>> hs.basis_labels
('-3/2', '-1/2', '+1/2', '+3/2')

For convenience, you may also give spin as a tuple or a string:

>>> hs = SpinSpace(label=0, spin=(3, 2))
>>> assert hs == SpinSpace(label=0, spin=sympy.Rational(3, 2))
>>> hs = SpinSpace(label=0, spin='3/2')
>>> assert hs == SpinSpace(label=0, spin=(3, 2))

You may use custom labels, e.g.:

>>> hs = SpinSpace(label='s', spin='1/2', basis=('-', '+'))
>>> hs.basis_labels
('-', '+')

The labels “up” and “down” are recognized and printed as the appropritate arrow symbols:

>>> hs = SpinSpace(label='s', spin='1/2', basis=('down', 'up'))
>>> unicode(BasisKet('up', hs=hs))
'|↑⟩⁽ˢ⁾'
>>> unicode(BasisKet('down', hs=hs))
'|↓⟩⁽ˢ⁾'
Raises:ValueError – if spin is not an integer or half-integer greater than zero
next_basis_label_or_index(label_or_index, n=1)[source]

Given the label or index of a basis state, return the label the next basis state.

More generally, if n is given, return the n’th next basis state label/index; n may also be negative to obtain previous basis state labels. Returns a str label if label_or_index is a str or int, or a SpinIndex if label_or_index is a SpinIndex.

Parameters:
  • label_or_index (int or str or SpinIndex) – If int, the zero-based index of a basis state; if str, the label of a basis state
  • n (int) – The increment
Raises:
  • IndexError – If going beyond the last or first basis state
  • ValueError – If label is not a label for any basis state in the Hilbert space
  • BasisNotSetError – If the Hilbert space has no defined basis
  • TypeError – if label_or_index is neither a str nor an int, nor a SpinIndex

Note

This differs from its super-method only by never returning an integer index (which is not accepted when instantiating a BasisKet for a SpinSpace)

spin

The spin-number associated with the SpinSpace

This can be a SymPy integer or a half-integer.

Return type:Rational
multiplicity

The multiplicity of the Hilbert space, \(2 S + 1\).

This is equivalent to the dimension:

>>> hs = SpinSpace('s', spin=sympy.Rational(3, 2))
>>> hs.multiplicity == 4 == hs.dimension
True
Return type:int
qnet.algebra.library.spin_algebra.SpinBasisKet(*numer_denom, hs)[source]

Constructor for a BasisKet for a SpinSpace

For a half-integer spin system:

>>> hs = SpinSpace('s', spin=(3, 2))
>>> assert SpinBasisKet(1, 2, hs=hs) == BasisKet("+1/2", hs=hs)

For an integer spin system:

>>> hs = SpinSpace('s', spin=1)
>>> assert SpinBasisKet(1, hs=hs) == BasisKet("+1", hs=hs)

Note that BasisKet(1, hs=hs) with an integer index (which would hypothetically refer to BasisKet("0", hs=hs) is not allowed for spin systems:

>>> BasisKet(1, hs=hs)
Traceback (most recent call last):
    ...
TypeError: label_or_index must be an instance of one of str, SpinIndex; not int
Raises:
  • TypeError – if hs is not a SpinSpace or the wrong number of positional arguments is given
  • ValueError – if any of the positional arguments are out range for the given hs
class qnet.algebra.library.spin_algebra.SpinOperator(*args, hs)[source]

Bases: qnet.algebra.core.operator_algebra.LocalOperator

Base class for operators in a spin space

class qnet.algebra.library.spin_algebra.Jz(*, hs)[source]

Bases: qnet.algebra.library.spin_algebra.SpinOperator

Spin (angular momentum) operator in z-direction

\(\Op{J}_z\) is the \(z\) component of a general spin operator acting on a particular SpinSpace hs of freedom with well defined spin quantum number \(s\). It is Hermitian:

>>> hs = SpinSpace(1, spin=(1, 2))
>>> print(ascii(Jz(hs=hs).adjoint()))
J_z^(1)

Jz, Jplus and Jminus satisfy the angular momentum commutator algebra:

>>> print(ascii((Jz(hs=hs) * Jplus(hs=hs) -
...              Jplus(hs=hs)*Jz(hs=hs)).expand()))
J_+^(1)

>>> print(ascii((Jz(hs=hs) * Jminus(hs=hs) -
...              Jminus(hs=hs)*Jz(hs=hs)).expand()))
-J_-^(1)

>>> print(ascii((Jplus(hs=hs) * Jminus(hs=hs)
...              - Jminus(hs=hs)*Jplus(hs=hs)).expand()))
2 * J_z^(1)
>>> Jplus(hs=hs).dag() == Jminus(hs=hs)
True
>>> Jminus(hs=hs).dag() == Jplus(hs=hs)
True

Printers should represent this operator with the default identifier:

>>> Jz._identifier
'J_z'

A custom identifier may be define using hs’s local_identifiers argument.

class qnet.algebra.library.spin_algebra.Jplus(*, hs)[source]

Bases: qnet.algebra.library.spin_algebra.SpinOperator

Raising operator of a spin space

\(\Op{J}_{+} = \Op{J}_x + i \op{J}_y\) is the raising ladder operator of a general spin operator acting on a particular SpinSpace hs with well defined spin quantum number \(s\). It’s adjoint is the lowering operator:

>>> hs = SpinSpace(1, spin=(1, 2))
>>> print(ascii(Jplus(hs=hs).adjoint()))
J_-^(1)

Jz, Jplus and Jminus satisfy that angular momentum commutator algebra, see Jz

Printers should represent this operator with the default identifier:

>>> Jplus._identifier
'J_+'

A custom identifier may be define using hs’s local_identifiers argument.

class qnet.algebra.library.spin_algebra.Jminus(*, hs)[source]

Bases: qnet.algebra.library.spin_algebra.SpinOperator

Lowering operator on a spin space

\(\Op{J}_{-} = \Op{J}_x - i \op{J}_y\) is the lowering ladder operator of a general spin operator acting on a particular SpinSpace hs with well defined spin quantum number \(s\). It’s adjoint is the raising operator:

>>> hs = SpinSpace(1, spin=(1, 2))
>>> print(ascii(Jminus(hs=hs).adjoint()))
J_+^(1)

Jz, Jplus and Jminus satisfy that angular momentum commutator algebra, see Jz.

Printers should represent this operator with the default identifier:

>>> Jminus._identifier
'J_-'

A custom identifier may be define using hs’s local_identifiers argument.

qnet.algebra.library.spin_algebra.Jpjmcoeff(ls, m, shift=False)[source]

Eigenvalue of the \(\Op{J}_{+}\) (Jplus) operator

\[\Op{J}_{+} \ket{s, m} = \sqrt{s (s+1) - m (m+1)} \ket{s, m}\]

where the multiplicity \(s\) is implied by the size of the Hilbert space ls: there are \(2s+1\) eigenstates with \(m = -s, -s+1, \dots, s\).

Parameters:
  • ls (LocalSpace) – The Hilbert space in which the \(\Op{J}_{+}\) operator acts.
  • m (str or int) – If str, the label of the basis state of hs to which the operator is applied. If integer together with shift=True, the zero-based index of the basis state. Otherwise, directly the quantum number \(m\).
  • shift (bool) – If True for a integer value of m, treat m as the zero-based index of the basis state (i.e., shift m down by \(s\) to obtain the quantum number $m$)
Return type:

Expr

qnet.algebra.library.spin_algebra.Jzjmcoeff(ls, m, shift)[source]

Eigenvalue of the \(\Op{J}_z\) (Jz) operator

\[\Op{J}_{z} \ket{s, m} = m \ket{s, m}\]

See also Jpjmcoeff().

Return type:Expr
qnet.algebra.library.spin_algebra.Jmjmcoeff(ls, m, shift)[source]

Eigenvalue of the \(\Op{J}_{-}\) (Jminus) operator

\[\Op{J}_{-} \ket{s, m} = \sqrt{s (s+1) - m (m-1)} \ket{s, m}\]

See also Jpjmcoeff().

Return type:Expr