Quantum Operators (quanguru.QuantumToolbox.operators)#

Contains methods to functions to create and/or manipulate quantum operators

Functions#

identity(dimension[, sparse])

Creates the identity operator \mathbb{I}.

number(dimension[, sparse])

Creates the (bosonic) number \hat{n} := a^{\dagger}a operator (in Fock basis).

destroy(dimension[, sparse])

Creates the bosonic annihilation \hat{a} operator (in Fock basis).

create(dimension[, sparse])

Creates the bosonic creation \hat{a}^{\dagger} operator (in Fock basis).

sigmaz([sparse])

Creates the Pauli (sigma z) \hat{\sigma}_{z} := \begin{bmatrix} 1, \ \ 0 \\ 0, -1 \end{bmatrix} operator.

sigmay([sparse])

Creates the Pauli (sigma y) \hat{\sigma}_{y} := \begin{bmatrix} 0, -i \\ i,\ \ 0 \end{bmatrix} operator.

sigmax([sparse])

Creates the Pauli (sigma x) \hat{\sigma}_{x} := \begin{bmatrix} 0, 1 \\ 1, 0 \end{bmatrix} operator.

sigmap([sparse])

Creates the Pauli (sigma +) \hat{\sigma}_{+} := \frac{1}{2}(\hat{\sigma}_{x} +i\hat{\sigma}_{y}) = \begin{bmatrix} 0, 1 \\ 0, 0 \end{bmatrix} operator.

sigmam([sparse])

Creates the Pauli (sigma -) \hat{\sigma}_{-} := \frac{1}{2}(\hat{\sigma}_{x} - i\hat{\sigma}_{y}) = \begin{bmatrix} 0, 0 \\ 1, 0 \end{bmatrix} operator.

Jp(j[, sparse, isDim])

Creates the angular momentum (spin) raising operator \hat{J}_{+} := \frac{1}{2}(\hat{J}_{x}+i\hat{J}_{y}) for a given spin quantum number j.

Jm(j[, sparse, isDim])

Creates the angular momentum (spin) lowering operator \hat{J}_{-} := \frac{1}{2}(\hat{J}_{x}-i\hat{J}_{y}) for a given spin quantum number j.

Jx(j[, sparse, isDim])

Creates the angular momentum (spin) X operator \hat{J}_{x} for a given spin quantum number j.

Jy(j[, sparse, isDim])

Creates the angular momentum (spin) Y operator \hat{J}_{y} for a given spin quantum number j.

Jz(j[, sparse, isDim])

Creates the angular momentum (spin) Z operator \hat{J}_{z} for a given spin quantum number j.

Js(j[, sparse, isDim])

Creates the total angular momentum (spin) operator \hat{J}_{s} := \hat{J}_{x}^{2} + \hat{J}_{y}^{2}+ \hat{J}_{z}^{2} for a given spin quantum number j.

displacement(alpha, dim[, sparse])

Creates the displacement operator \hat{D}(\alpha) := e^{\alpha a^{\dagger} - \alpha^{*}a} for a given displacement parameter \alpha.

squeeze(alpha, dim[, sparse])

Creates the squeezing operator \hat{S}(\alpha) := e^{\frac{1}{2}(\alpha^{*}a^{2} - \alpha a^{\dagger 2})} for a given squeezing parameter \alpha.

parityEXP(HamiltonianCavity)

Creates a parity operator \hat{P}(\hat{H}) := e^{i\pi\hat{H}} by exponenting a given Hamiltonian \hat{H}.

paritySUM(dimension[, sparse])

Creates a parity operator by explicitly placing alternating +/- into a matrix.

compositeOp(operator[, dimB, dimA])

Creates a composite operator \hat{O}_{comp} = \mathbb{I}_{dimB\times dimB}\otimes\hat{O}_{single}\otimes\mathbb{I}_{dimA\times dimA} ,ie tensor product with identities of dimensions before dimB and after dimA

operatorPow(op, dim, power[, sparse])

Creates a quantum operator for given function reference op and raises to a power.

Function Name

Docstrings

Examples

Unit Tests

Tutorials

identity

      ✅

    ✅

    ✅

    ❌

number

      ✅

    ✅

    ✅

    ❌

destroy

      ✅

    ✅

    ✅

    ❌

create

      ✅

    ✅

    ✅

    ❌

sigmaz

      ✅

    ✅

    ✅

    ❌

sigmay

      ✅

    ✅

    ✅

    ❌

sigmax

      ✅

    ✅

    ✅

    ❌

sigmap

      ✅

    ✅

    ✅

    ❌

sigmam

      ✅

    ✅

    ✅

    ❌

Jp

      ✅

    ✅

    ✅

    ❌

Jm

      ✅

    ✅

    ✅

    ❌

Jx

      ✅

    ✅

    ❌

    ❌

Jy

      ✅

    ✅

    ❌

    ❌

Jz

      ✅

    ✅

    ✅

    ❌

Js

      ✅

    ✅

    ✅

    ❌

displacement

      ✅

    ✅

    ✅

    ❌

squeeze

      ✅

    ✅

    ❌

    ❌

parityEXP

      ✅

    ✅

    ❌

    ❌

paritySUM

      ✅

    ✅

    ❌

    ❌

compositeOp

      ✅

    ✅

    ❌

    ❌

operatorPow

      ✅

    ✅

    ❌

    ❌

number(dimension: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the (bosonic) number \hat{n} := a^{\dagger}a operator (in Fock basis).

Parameters
  • dimension (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

number operator

Return type

Matrix

Examples

>>> number(dimension=3, sparse=False)
[[0 0 0]
 [0 1 0]
 [0 0 2]]
>>> print(number(3))
(0, 0)      0
(1, 1)      1
(2, 2)      2
destroy(dimension: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the bosonic annihilation \hat{a} operator (in Fock basis).

Parameters
  • dimension (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

bosonic annihilation operator

Return type

Matrix

Examples

>>> print(destroy(dimension=3))
(0, 1)      1.0
(1, 2)      1.4142135623730951
>>> destroy(3, sparse=False)
[[0.         1.         0.        ]
 [0.         0.         1.41421356]
 [0.         0.         0.        ]]
create(dimension: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the bosonic creation \hat{a}^{\dagger} operator (in Fock basis).

Parameters
  • dimension (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

bosonic creation operator

Return type

Matrix

Examples

>>> print(create(3))
(1, 0)      1.0
(2, 1)      1.4142135623730951
>>> create(3, sparse=False)
[[0.         0.         0.        ]
 [1.         0.         0.        ]
 [0.         1.41421356 0.        ]]
identity(dimension: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the identity operator \mathbb{I}.

Parameters
  • dimension (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

identity operator

Return type

Matrix

Examples

>>> print(identity(3))
(0, 0)      1.0
(1, 1)      1.0
(2, 2)      1.0
>>> identity(3, sparse=False)
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
sigmaz(sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the Pauli (sigma z) \hat{\sigma}_{z} := \begin{bmatrix} 1, \ \ 0 \\ 0, -1 \end{bmatrix} operator.

Parameters

sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Pauli sigma z operator

Return type

Matrix

Examples

>>> sigmaz(sparse=False)
[[ 1  0]
 [ 0 -1]]
>>> print(sigmaz())
(0, 0)      1
(1, 1)      -1
sigmay(sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the Pauli (sigma y) \hat{\sigma}_{y} := \begin{bmatrix} 0, -i \\ i,\ \ 0 \end{bmatrix} operator.

Parameters

sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Pauli sigma y operator

Return type

Matrix

Examples

>>> sigmay(sparse=False)
[[0.+0.j 0.-1.j]
 [0.+1.j 0.+0.j]]
>>> print(sigmay())
(1, 0)      1j
(0, 1)      (-0-1j)
sigmax(sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the Pauli (sigma x) \hat{\sigma}_{x} := \begin{bmatrix} 0, 1 \\ 1, 0 \end{bmatrix} operator.

Parameters

sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Pauli sigma x operator

Return type

Matrix

Examples

>>> sigmax(sparse=False)
[[0 1]
 [1 0]]
>>> print(sigmax())
(1, 0)      1
(0, 1)      1
sigmap(sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the Pauli (sigma +) \hat{\sigma}_{+} := \frac{1}{2}(\hat{\sigma}_{x} +i\hat{\sigma}_{y}) =
\begin{bmatrix} 0, 1 \\ 0, 0 \end{bmatrix} operator.

Parameters

sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Pauli sigma + operator

Return type

Matrix

Examples

>>> sigmap(sparse=False)
[[0 1]
 [0 0]]
>>> print(sigmap())
(0, 1)      1
sigmam(sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the Pauli (sigma -) \hat{\sigma}_{-} := \frac{1}{2}(\hat{\sigma}_{x} - i\hat{\sigma}_{y}) =
\begin{bmatrix} 0, 0 \\ 1, 0 \end{bmatrix} operator.

Parameters

sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Pauli sigma - operator

Return type

Matrix

Examples

>>> sigmam(sparse=False)
[[0 0]
 [1 0]]
>>> print(sigmam())
(1, 0)      1
Jp(j: float, sparse: bool = True, isDim: bool = False) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the angular momentum (spin) raising operator \hat{J}_{+} := \frac{1}{2}(\hat{J}_{x}+i\hat{J}_{y}) for a given spin quantum number j.

NOTE This is a direct matrix construction, i.e. it does not use the Jx and Jy functions, and this function is used in Jx and Jy implementations

Parameters
  • j (int or float) – integer or half-integer spin quantum number, or the dimension (then spin quantum number = (d-1)/2)

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

  • isDim (bool) – boolean for whether j is spin quantum number of dimension

Returns

Angular momentum (spin) raising operator

Return type

Matrix

Examples

>>> Jp(j=2, sparse=False)
[[0.         2.         0.         0.         0.        ]
 [0.         0.         2.44948974 0.         0.        ]
 [0.         0.         0.         2.44948974 0.        ]
 [0.         0.         0.         0.         2.        ]
 [0.         0.         0.         0.         0.        ]]
>>> print(Jp(j=2))
(0, 1)      2.0
(1, 2)      2.449489742783178
(2, 3)      2.449489742783178
(3, 4)      2.0
>>> Jp(j=5, sparse=False, isDim=True)
[[0.         2.         0.         0.         0.        ]
 [0.         0.         2.44948974 0.         0.        ]
 [0.         0.         0.         2.44948974 0.        ]
 [0.         0.         0.         0.         2.        ]
 [0.         0.         0.         0.         0.        ]]
>>> print(Jp(j=5, isDim=True))
(0, 1)      2.0
(1, 2)      2.449489742783178
(2, 3)      2.449489742783178
(3, 4)      2.0
Jm(j: float, sparse: bool = True, isDim: bool = False) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the angular momentum (spin) lowering operator \hat{J}_{-} := \frac{1}{2}(\hat{J}_{x}-i\hat{J}_{y}) for a given spin quantum number j.

NOTE This is a direct matrix construction, i.e. it does not use the Jx and Jy functions, and this function is used in Jx and Jy implementations

Parameters
  • j (int or float) – integer or half-integer spin quantum number, or the dimension (then spin quantum number = (d-1)/2)

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

  • isDim (bool) – boolean for whether j is spin quantum number of dimension

Returns

Angular momentum (spin) lowering operator

Return type

Matrix

Examples

>>> Jm(j=2, isDim=False, sparse=False)
[[0.         0.         0.         0.         0.        ]
 [2.         0.         0.         0.         0.        ]
 [0.         2.44948974 0.         0.         0.        ]
 [0.         0.         2.44948974 0.         0.        ]
 [0.         0.         0.         2.         0.        ]]
>>> print(Jm(j=2, isDim=False))
(1, 0)      2.0
(2, 1)      2.449489742783178
(3, 2)      2.449489742783178
(4, 3)      2.0
>>> Jm(j=5, sparse=False, isDim=True)
[[0.         0.         0.         0.         0.        ]
 [2.         0.         0.         0.         0.        ]
 [0.         2.44948974 0.         0.         0.        ]
 [0.         0.         2.44948974 0.         0.        ]
 [0.         0.         0.         2.         0.        ]]
>>> print(Jm(j=5, isDim=True))
(1, 0)      2.0
(2, 1)      2.449489742783178
(3, 2)      2.449489742783178
(4, 3)      2.0
Jx(j: float, sparse: bool = True, isDim: bool = False) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the angular momentum (spin) X operator \hat{J}_{x} for a given spin quantum number j.

NOTE This function uses the definition \hat{J}_{x} =\frac{1}{2}(\hat{J}_{p}+\hat{J}_{m}) and calls Jp and Jm There are no test for this method, it rely on Jp and Jm

Parameters
  • j (int or float) – integer or half-integer spin quantum number, or the dimension (then spin quantum number = (d-1)/2)

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

  • isDim (bool) – boolean for whether j is spin quantum number of dimension

Returns

Angular momentum (spin) X operator

Return type

Matrix

Examples

>>> Jx(j=2, isDim=False, sparse=False)
[[0.         1.         0.         0.         0.        ]
 [1.         0.         1.22474487 0.         0.        ]
 [0.         1.22474487 0.         1.22474487 0.        ]
 [0.         0.         1.22474487 0.         1.        ]
 [0.         0.         0.         1.         0.        ]]
>>> print(Jx(j=2, isDim=False))
(1, 0)      1.0
(0, 1)      1.0
(2, 1)      1.224744871391589
(1, 2)      1.224744871391589
(3, 2)      1.224744871391589
(2, 3)      1.224744871391589
(4, 3)      1.0
(3, 4)      1.0
>>> Jx(j=5, sparse=False, isDim=True)
[[0.         1.         0.         0.         0.        ]
 [1.         0.         1.22474487 0.         0.        ]
 [0.         1.22474487 0.         1.22474487 0.        ]
 [0.         0.         1.22474487 0.         1.        ]
 [0.         0.         0.         1.         0.        ]]
>>> print(Jx(j=5, isDim=True))
(1, 0)      1.0
(0, 1)      1.0
(2, 1)      1.224744871391589
(1, 2)      1.224744871391589
(3, 2)      1.224744871391589
(2, 3)      1.224744871391589
(4, 3)      1.0
(3, 4)      1.0
Jy(j: float, sparse: bool = True, isDim: bool = False) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the angular momentum (spin) Y operator \hat{J}_{y} for a given spin quantum number j.

NOTE This function uses the definition \hat{J}_{y}=\frac{1}{2j}(\hat{J}_{p}-\hat{J}_{m}) and calls Jp and Jm There are no test for this method, it rely on Jp and Jm

Parameters
  • j (int or float) – integer or half-integer spin quantum number, or the dimension (then spin quantum number = (d-1)/2)

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

  • isDim (bool) – boolean for whether j is spin quantum number of dimension

Returns

Angular momentum (spin) Y operator

Return type

Matrix

Examples

>>> Jy(j=2, isDim=False, sparse=False)
[[0.+0.j         0.-1.j         0.+0.j         0.+0.j                0.+0.j        ]
 [0.+1.j         0.+0.j         0.-1.22474487j 0.+0.j                0.+0.j        ]
 [0.+0.j         0.+1.22474487j 0.+0.j         0.-1.22474487j        0.+0.j        ]
 [0.+0.j         0.+0.j         0.+1.22474487j 0.+0.j                0.-1.j        ]
 [0.+0.j         0.+0.j         0.+0.j         0.+1.j                0.+0.j        ]]
>>> print(Jy(j=2, isDim=False))
(1, 0)      1j
(0, 1)      -1j
(2, 1)      1.224744871391589j
(1, 2)      -1.224744871391589j
(3, 2)      1.224744871391589j
(2, 3)      -1.224744871391589j
(4, 3)      1j
(3, 4)      -1j
>>> Jy(j=5, sparse=False, isDim=True)
[[0.+0.j         0.-1.j         0.+0.j         0.+0.j                0.+0.j        ]
 [0.+1.j         0.+0.j         0.-1.22474487j 0.+0.j                0.+0.j        ]
 [0.+0.j         0.+1.22474487j 0.+0.j         0.-1.22474487j        0.+0.j        ]
 [0.+0.j         0.+0.j         0.+1.22474487j 0.+0.j                0.-1.j        ]
 [0.+0.j         0.+0.j         0.+0.j         0.+1.j                0.+0.j        ]]
>>> print(Jy(j=5, isDim=True))
(1, 0)      1j
(0, 1)      -1j
(2, 1)      1.224744871391589j
(1, 2)      -1.224744871391589j
(3, 2)      1.224744871391589j
(2, 3)      -1.224744871391589j
(4, 3)      1j
(3, 4)      -1j
Jz(j: float, sparse: bool = True, isDim: bool = False) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the angular momentum (spin) Z operator \hat{J}_{z} for a given spin quantum number j.

Parameters
  • j (int or float) – integer or half-integer spin quantum number, or the dimension (then spin quantum number = (d-1)/2)

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

  • isDim (bool) – boolean for whether j is spin quantum number of dimension

Returns

Angular momentum (spin) Z operator

Return type

Matrix

Examples

>>> Jz(j=2, isDim=False, sparse=False)
[[ 2  0  0  0  0]
 [ 0  1  0  0  0]
 [ 0  0  0  0  0]
 [ 0  0  0 -1  0]
 [ 0  0  0  0 -2]]
>>> print(Jz(j=2, isDim=False))
(0, 0)      2
(1, 1)      1
(2, 2)      0
(3, 3)      -1
(4, 4)      -2
>>> Jz(j=5, sparse=False, isDim=True)
[[ 2.  0.  0.  0.  0.]
 [ 0.  1.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.]
 [ 0.  0.  0. -1.  0.]
 [ 0.  0.  0.  0. -2.]]
>>> print(Jz(j=5, isDim=True))
(0, 0)      2.0
(1, 1)      1.0
(2, 2)      0.0
(3, 3)      -1.0
(4, 4)      -2.0
Js(j: float, sparse: bool = True, isDim: bool = False) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the total angular momentum (spin) operator \hat{J}_{s} := \hat{J}_{x}^{2} + \hat{J}_{y}^{2}+ \hat{J}_{z}^{2} for a given spin quantum number j.

NOTE This function is direct implementation of the defition, meaning it uses Jx, Jy, and Jz functions

Parameters
  • j (int or float) – integer or half-integer spin quantum number, or the dimension (then spin quantum number = (d-1)/2)

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

  • isDim (bool) – boolean for whether j is spin quantum number of dimension

Return type

Total angular momentum (spin) operator

Examples

>>> Js(j=2, isDim=False, sparse=False)
[[6.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 6.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 6.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 6.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j 6.+0.j]]
>>> print(Js(j=2, isDim=False))
(0, 0)      (6+0j)
(1, 1)      (6+0j)
(2, 2)      (5.999999999999999+0j)
(3, 3)      (6+0j)
(4, 4)      (6+0j)
>>> Js(j=5, sparse=False, isDim=True)
[[6.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 6.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 6.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 6.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j 6.+0.j]]
>>> print(Js(j=5, isDim=True))
(0, 0)      (6+0j)
(1, 1)      (6+0j)
(2, 2)      (5.999999999999999+0j)
(3, 3)      (6+0j)
(4, 4)      (6+0j)
displacement(alpha: complex, dim: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the displacement operator \hat{D}(\alpha) := e^{\alpha a^{\dagger} - \alpha^{*}a} for a given displacement parameter \alpha.

NOTE can be implemented without matrix exponentiation

Parameters
  • alpha (complex) – complex number, the displacement parameter

  • dim (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Displacement operator

Return type

Matrix

Examples

>>> displacement(alpha=1j, dim=4, sparse=False)
[[ 0.60605894+0.j          0.        +0.6100857j  -0.41242505+0.j       0.        -0.30065525j]
 [ 0.        +0.6100857j   0.02280184+0.j          0.        +0.34204129j        -0.71434114+0.j]
 [-0.41242505+0.j          0.        +0.34204129j -0.56045527+0.j        0.        +0.63150869j]
 [ 0.        -0.30065525j -0.71434114+0.j          0.        +0.63150869j        0.02280184+0.j]]
>>> print(displacement(alpha=1j, dim=4))
(0, 0)      (0.6060589372864117+0j)
(1, 0)      0.610085698426889j
(2, 0)      (-0.41242505189886125+0j)
(3, 0)      (-0-0.3006552538647247j)
(0, 1)      0.610085698426889j
(1, 1)      (0.02280183542861441+0j)
(2, 1)      0.3420412936689465j
(3, 1)      (-0.7143411442030587+0j)
(0, 2)      (-0.4124250518988613+0j)
(1, 2)      0.34204129366894637j
(2, 2)      (-0.5604552664291825+0j)
(3, 2)      0.6315086890322961j
(0, 3)      -0.3006552538647247j
(1, 3)      (-0.7143411442030586+0j)
(2, 3)      0.6315086890322962j
(3, 3)      (0.02280183542861464+0j)
squeeze(alpha: complex, dim: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates the squeezing operator \hat{S}(\alpha) := e^{\frac{1}{2}(\alpha^{*}a^{2} - \alpha a^{\dagger 2})} for a given squeezing parameter \alpha.

NOTE can be implemented without matrix exponentiation

Parameters
  • alpha (complex) – complex number, the squeezing parameter

  • dim (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Squeezing operator

Return type

Matrix

Examples

>>> squeeze(alpha=1j, dim=4, sparse=False)
[[0.7602446 +0.j         0.        +0.j         0.        -0.64963694j      0.        +0.j        ]
 [0.        +0.j         0.33918599+0.j         0.        +0.j               0.        -0.94071933j]
 [0.        -0.64963694j 0.        +0.j         0.7602446 +0.j               0.        +0.j        ]
 [0.        +0.j         0.        -0.94071933j 0.        +0.j               0.33918599+0.j        ]]
>>> print(squeeze(alpha=1j, dim=4))
(0, 0)      (0.7602445970756301+0j)
(2, 0)      -0.6496369390800625j
(1, 1)      (0.3391859889869473+0j)
(3, 1)      -0.940719333741444j
(0, 2)      -0.6496369390800625j
(2, 2)      (0.7602445970756302+0j)
(1, 3)      -0.9407193337414442j
(3, 3)      (0.33918598898694713+0j)
parityEXP(HamiltonianCavity: Union[scipy.sparse._base.spmatrix, numpy.ndarray]) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates a parity operator \hat{P}(\hat{H}) := e^{i\pi\hat{H}} by exponenting a given Hamiltonian \hat{H}.

Keeps sparse/array as sparse/array.

Parameters

HamiltonianCavity (Matrix) – dimension of the Hilbert space

Returns

Parity operator

Return type

Matrix

Examples

>>> ham = number(dimension=5, sparse=False)
>>> parityEXP(HamiltonianCavity=ham) # returns an array since ham is an array
[[ 1.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j]
 [ 0.+0.0000000e+00j -1.+1.2246468e-16j  0.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j]
 [ 0.+0.0000000e+00j  0.+0.0000000e+00j  1.-2.4492936e-16j  0.+0.0000000e+00j  0.+0.0000000e+00j]
 [ 0.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j  -1.+3.6739404e-16j  0.+0.0000000e+00j]
 [ 0.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j  0.+0.0000000e+00j  1.-4.8985872e-16j]]
>>> ham = number(dimension=5)
>>> print(parityEXP(HamiltonianCavity=ham)) # returns a sparse since ham is a sparse
(0, 0)      (1+0j)
(0, 1)      0j
(1, 1)      (-1+1.2246467991473532e-16j)
(1, 2)      -0j
(2, 2)      (1-2.4492935982947064e-16j)
(2, 3)      0j
(3, 3)      (-1+3.6739403974420594e-16j)
(3, 4)      -0j
(4, 4)      (1-4.898587196589413e-16j)
paritySUM(dimension: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates a parity operator by explicitly placing alternating +/- into a matrix.

Parameters
  • dimension (int) – dimension of the Hilbert space

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

Parity operator

Return type

Matrix

Examples

>>> paritySUM(dimension=5, sparse=False)
[[ 1.  0.  0.  0.  0.]
 [ 0. -1.  0.  0.  0.]
 [ 0.  0.  1.  0.  0.]
 [ 0.  0.  0. -1.  0.]
 [ 0.  0.  0.  0.  1.]]
>>> print(paritySUM(dimension=5))
(0, 0)      1.0
(1, 1)      -1.0
(2, 2)      1.0
(3, 3)      -1.0
(4, 4)      1.0
compositeOp(operator: Union[scipy.sparse._base.spmatrix, numpy.ndarray], dimB: int = 1, dimA: int = 1) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates a composite operator \hat{O}_{comp} = \mathbb{I}_{dimB\times dimB}\otimes\hat{O}_{single}\otimes\mathbb{I}_{dimA\times dimA} ,ie tensor product with identities of dimensions before dimB and after dimA

NOTE simply calls and returns tensorProd

Parameters
  • operator (Matrix) – operator of a sub-system

  • dimB (int) – (total) dimension of the systems that appear before in the tensor product order

  • dimA (int) – (total) dimension of the systems that appear after in the tensor product order

Returns

sub-system operator in the extended Hilbert space

Return type

Matrix

Examples

>>> compositeOp(operator=sigmaz(), dimB=0, dimA=2).A
[[ 1.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0. -1.  0.]
 [ 0.  0.  0. -1.]]
>>> compositeOp(operator=sigmaz(), dimB=2, dimA=0).A
[[ 1.  0.  0.  0.]
 [ 0. -1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0. -1.]]
operatorPow(op: Callable, dim: int, power: int, sparse: bool = True) Union[scipy.sparse._base.spmatrix, numpy.ndarray][source]#

Creates a quantum operator for given function reference op and raises to a power.

Parameters
  • op (Callable) – reference to the function (in here) for the operator

  • dim (int) – dimension of the Hilbert space

  • power (int) – power that the operator to be raised

  • sparse (bool) – if True(False), the returned Matrix type will be sparse(array)

Returns

an operator raised to a power

Return type

Matrix

Examples

>>> operatorPow(op=sigmax, dim=2, power=2, sparse=False)
[[1 0]
 [0 1]]
>>> print(operatorPow(op=sigmax, dim=2, power=2))
(0, 0)      1
(1, 1)      1
>>> operatorPow(op=sigmax, dim=2, power=3, sparse=False)
[[0 1]
 [1 0]]
>>> print(operatorPow(op=sigmax, dim=2, power=3))
(1, 0)      1
(0, 1)      1