diff --git a/.cache/v/cache/lastfailed b/.cache/v/cache/lastfailed new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.cache/v/cache/lastfailed @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/test_utilities.py b/tests/test_utilities.py new file mode 100644 index 0000000..eb3777b --- /dev/null +++ b/tests/test_utilities.py @@ -0,0 +1,20 @@ +""" +# test_utilities.py +Test the functions in the utilities module +""" +import numpy as np +from two_qubit_simulator import conjugate_transpose + +def test_conjugate_transpose(): + # Test with real-valued array + test_array_1 = np.array([[1, 2], [3, 4]]) + assert np.allclose( + conjugate_transpose(test_array_1), + np.array([[1, 3], [2, 4]]) + ) + # Test with complex-valued array + test_array_1 = np.array([[1j, 2], [1j, 4]]) + assert np.allclose( + conjugate_transpose(test_array_1), + np.array([[-1j, -1j], [2, 4]]) + ) diff --git a/two_qubit_simulator/__init__.py b/two_qubit_simulator/__init__.py index 942b51f..e925c73 100644 --- a/two_qubit_simulator/__init__.py +++ b/two_qubit_simulator/__init__.py @@ -2,3 +2,4 @@ Initialise the two_qubit_simulator module. Add import statements from auxilirary modules here. """ +from .utilities import conjugate_transpose \ No newline at end of file diff --git a/two_qubit_simulator/utilities.py b/two_qubit_simulator/utilities.py new file mode 100644 index 0000000..09fc142 --- /dev/null +++ b/two_qubit_simulator/utilities.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) + )