Commit fd6ec8be authored by Simon Sebastian Humpohl's avatar Simon Sebastian Humpohl
Browse files

Make paulis a singleton namedtuple instance

parent 5d8948cf
"""This module contains utilities pertaining to quantum information"""
from collections import namedtuple
import numpy as np
__all__ = ['paulis', 'hadamard', 'cnot', 'cphase', 'crot', 'swap']
......@@ -14,16 +15,29 @@ def crot(phi: float) -> np.ndarray:
)
return gate
paulis = np.array([
[[1, 0],
[0, 1]],
[[0, 1],
[1, 0]],
[[0, -1j],
[1j, 0]],
[[1, 0],
[0, -1]]
])
paulis = namedtuple('PauliMatrices', ['sigma_0',
'sigma_x',
'sigma_y',
'sigma_z'])(
np.array([[1, 0],
[0, 1]]),
np.array([[0, 1],
[1, 0]]),
np.array([[0, -1j],
[1j, 0]]),
np.array([[1, 0],
[0, -1]]),
)
type(paulis).__doc__ = "Collection of pauli matrices that can be addressed by 'name' or by index"
type(paulis).__repr__ = lambda self: ('PauliMatrices(sigma_0=array([[1, 0],\n'
' [0, 1]]),\n'
' sigma_x=array([[0, 1],\n'
' [1, 0]]),\n'
' sigma_y=array([[0, -1j],\n'
' [1j, 0]]),\n'
' sigma_z=array([[1, 0],\n'
' [0, -1]]))')
hadamard = np.array(
[[1, 1],
......@@ -50,4 +64,3 @@ swap = np.array(
[0, 1, 0, 0],
[0, 0, 0, 1]]
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment