From 055ec2d057434ebb33527aa25dd94d2bcf0508b0 Mon Sep 17 00:00:00 2001 From: pweb6304 Date: Wed, 30 Jan 2019 15:39:25 +1100 Subject: [PATCH 1/2] Million Dollar Project --- two_qubit_simulator/quantum_gates/hadamard.py | 2 +- .../quantum_gates/quantum_gate.py | 2 +- two_qubit_simulator/utilties.py | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 two_qubit_simulator/utilties.py 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 From 8ac58976cba6030806978729c24b72d0ea7422c4 Mon Sep 17 00:00:00 2001 From: EQUSPhysics Date: Wed, 30 Jan 2019 16:34:58 +1100 Subject: [PATCH 2/2] Prepares state --- two_qubit_simulator/initial_state.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 two_qubit_simulator/initial_state.py 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