Skip to content

Quantum

Quantum realizations shared by the physics packages: qubits and bosonic modes.

ModeElement(label, psi=0, *, hilbert=None, visual=VisualSpec('expectations'))

Bases: Element

Bosonic mode of the Hilbert space it takes, with annihilate, create, and number.

Parameters:

Name Type Description Default
label str

The label of the mode.

required
psi Annotated[object, StateSpec(domain=CC)]

The state in the Hilbert space: the number of quanta, or a vector.

0
hilbert HilbertSpec | None

The Hilbert space, mode_space(quanta).

None
visual VisualSpec | None

How the mode is drawn.

VisualSpec('expectations')

Examples:

>>> from skcomplex.systems.physics.common.quantum import ModeElement, mode_space
>>> ModeElement('cavity', hilbert=mode_space(4)).hilbert.dimension
5
Source code in src/skcomplex/systems/physics/common/quantum/_mode.py
73
74
75
76
77
78
79
80
81
82
83
def __init__(
    self,
    label: str,
    psi: Annotated[object, StateSpec(domain=CC)] = 0,
    *,
    hilbert: HilbertSpec | None = None,
    visual: VisualSpec | None = VisualSpec('expectations'),
) -> None:
    super().__init__(label, visual=visual)
    self.psi = psi
    self.hilbert = hilbert

QubitElement(label, psi='up', *, hilbert=QUBIT, visual=VisualSpec('expectations'))

Bases: Element

Two-level system with the Pauli matrices x, y, z and the ladder operators plus and minus.

The state 'up', also 'excited', is index 0 with z = 1, and 'down', also 'ground', is index 1.

Parameters:

Name Type Description Default
label str

The label of the qubit.

required
psi Annotated[object, StateSpec(domain=CC)]

The state in the Hilbert space: 'up', 'down', 'excited', 'ground', a basis index, or a vector.

'up'
hilbert HilbertSpec

The Hilbert space of the qubit.

QUBIT
visual VisualSpec | None

How the qubit is drawn.

VisualSpec('expectations')

Examples:

>>> from skcomplex.systems.physics.common.quantum import QubitElement
>>> sorted(QubitElement('q').hilbert.operators)
['minus', 'plus', 'x', 'y', 'z']
Source code in src/skcomplex/systems/physics/common/quantum/_qubit.py
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    label: str,
    psi: Annotated[object, StateSpec(domain=CC)] = 'up',
    *,
    hilbert: HilbertSpec = QUBIT,
    visual: VisualSpec | None = VisualSpec('expectations'),
) -> None:
    super().__init__(label, visual=visual)
    self.psi = psi
    self.hilbert = hilbert

mode_space(quanta=4)

Return the Hilbert space of a bosonic mode truncated at a number of quanta.

Its operators are annihilate, create, and number, and its basis state n holds n quanta.

Parameters:

Name Type Description Default
quanta int

The largest number of quanta, so the dimension is quanta + 1.

4

Returns:

Name Type Description
space HilbertSpec

The Hilbert space.

Raises:

Type Description
ValidationError

The number of quanta is not a positive integer.

Examples:

>>> from skcomplex.systems.physics.common.quantum import mode_space
>>> mode_space(4).dimension
5
Source code in src/skcomplex/systems/physics/common/quantum/_mode.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def mode_space(quanta: int = 4) -> HilbertSpec:
    """Return the Hilbert space of a bosonic mode truncated at a number of quanta.

    Its operators are `annihilate`, `create`, and `number`, and its basis state `n` holds `n` quanta.

    Args:
        quanta:
            The largest number of quanta, so the dimension is `quanta + 1`.

    Returns:
        space:
            The Hilbert space.

    Raises:
        ValidationError:
            The number of quanta is not a positive integer.

    Examples:
        >>> from skcomplex.systems.physics.common.quantum import mode_space
        >>> mode_space(4).dimension
        5
    """
    if isinstance(quanta, bool) or not isinstance(quanta, int | np.integer) or quanta < 1:
        error_msg = f'A mode has quanta = {quanta!r}, which is not a positive integer.'
        raise ValidationError(error_msg)
    size = int(quanta) + 1
    operators = {
        'annihilate': (qutip.destroy(size).full(), False),
        'create': (qutip.create(size).full(), False),
        'number': (qutip.num(size).full(), True),
    }
    return HilbertSpec(size, operators, display='number')