diff --git a/two_qubit_simulator/initial_state.py b/two_qubit_simulator/initial_state.py new file mode 100644 index 0000000..58b28f3 --- /dev/null +++ b/two_qubit_simulator/initial_state.py @@ -0,0 +1,14 @@ +def random_quantum_state(): + """ + Returns a random qubit state. + The qubit will be a column vector with complex elements a+ib and c+id. + a,b,c and d are randomly chosen. The norm ensures the state is normalised. + """ + import numpy as np + import random + a = random.random() + b = random.random() + c = random.random() + d = random.random() + norm = np.sqrt (( a + 1j * b) * (a - 1j * b) + (c + 1j * d) * (c - 1j * d)) + return np.array([[a + 1j * b] , [c + 1j * d] ]) / norm \ No newline at end of file diff --git a/two_qubit_simulator/quantum_gates/hadamard.py b/two_qubit_simulator/quantum_gates/hadamard.py index 2dfcffc..82a2269 100644 --- a/two_qubit_simulator/quantum_gates/hadamard.py +++ b/two_qubit_simulator/quantum_gates/hadamard.py @@ -6,4 +6,4 @@ class Hadamard(QuantumGate): """ Implements the Hadamard gate """ - pass + def __init__(self,elements) diff --git a/two_qubit_simulator/quantum_gates/quantum_gate.py b/two_qubit_simulator/quantum_gates/quantum_gate.py index c15f811..f6ac763 100644 --- a/two_qubit_simulator/quantum_gates/quantum_gate.py +++ b/two_qubit_simulator/quantum_gates/quantum_gate.py @@ -27,7 +27,7 @@ def __init__(self, unitary_operator, symbol=None): def assert_operation_is_unitary(self): """ Checks that the input unitary operator is unitary """ - pass + assert unitary_operator.dot(conjugate_transpose(unitary_operator))== np.eye(4) def __call__(self, register): """ Apply the gate to a given qubit register. See apply_register method """ diff --git a/two_qubit_simulator/utilties.py b/two_qubit_simulator/utilties.py new file mode 100644 index 0000000..83240b1 --- /dev/null +++ b/two_qubit_simulator/utilties.py @@ -0,0 +1,22 @@ +""" +# utilities.py +Contains utility functions for the two_qubit_simulator module +""" +import numpy as np + +def conjugate_transpose(array): + """ Calculates the conjugate transpose of an array + + Parameters + ------- + array : numpy ndarray + The array to be transposed + + Returns + ------- + numpy ndarray + The conjugate transpose of the input array + """ + return np.conjugate( + np.transpose(array) + ) \ No newline at end of file