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
14 changes: 14 additions & 0 deletions two_qubit_simulator/initial_state.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion two_qubit_simulator/quantum_gates/hadamard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

class Hadamard(QuantumGate):
""" Implements the Hadamard gate """
pass
def __init__(self,elements)
2 changes: 1 addition & 1 deletion two_qubit_simulator/quantum_gates/quantum_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
22 changes: 22 additions & 0 deletions two_qubit_simulator/utilties.py
Original file line number Diff line number Diff line change
@@ -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)
)