Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added cnot_README.txt
Empty file.
9 changes: 9 additions & 0 deletions two_qubit_simulator/quantum_gates/hadamard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
"""

from .quantum_gate import QuantumGate
import numpy as np

class Hadamard(QuantumGate):
""" Implements the Hadamard gate """
def __init__(self):
unitary_operator = 1/np.sqrt(2)*np.array([[1,1][1,-1]])
super(Hadamard, self).__init__(unitary_operator,'H',2)

def unitary_operator(self):
return self.unitary_operator

pass

5 changes: 3 additions & 2 deletions two_qubit_simulator/quantum_gates/quantum_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class QuantumGate(object): # pylint: disable=useless-object-inheritance
- - - CONTINUE DOUMENTATION FROM HERE - - -

"""
def __init__(self, unitary_operator, symbol=None):
def __init__(self, unitary_operator, symbol=None, dim = 2):
""" Create a QuantumGate object """
self.symbol = symbol
self.dim = dim
self.unitary_operator = unitary_operator.astype(np.complex128)

self.assert_operation_is_unitary()

def assert_operation_is_unitary(self):
""" Checks that the input unitary operator is unitary """
assert np.allclose(np.kron(self.unitary_operator.conj,self.unitary_operator),np.identity(self.dim))
pass

def __call__(self, register):
Expand Down