From 07838fc0c19c751dfb405e4e0464a1bdce437a68 Mon Sep 17 00:00:00 2001 From: Virginia Date: Wed, 30 Jan 2019 14:13:27 +1100 Subject: [PATCH 1/3] Add conjugate_transpose function --- two_qubit_simulator/utilities.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 two_qubit_simulator/utilities.py 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) + ) From 51a855dfe61f317844cd9932860015fc14b7acfc Mon Sep 17 00:00:00 2001 From: Virginia Date: Wed, 30 Jan 2019 14:18:06 +1100 Subject: [PATCH 2/3] Add test --- tests/test_utilities.py | 19 +++++++++++++++++++ two_qubit_simulator/__init__.py | 1 + 2 files changed, 20 insertions(+) create mode 100644 tests/test_utilities.py diff --git a/tests/test_utilities.py b/tests/test_utilities.py new file mode 100644 index 0000000..260cb9a --- /dev/null +++ b/tests/test_utilities.py @@ -0,0 +1,19 @@ +""" +# test_utilities.py +Test the functions in the utilities module +""" +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 From 5262a4b7fbde4986b560e17f76d2348ff5da147e Mon Sep 17 00:00:00 2001 From: Virginia Date: Wed, 30 Jan 2019 14:19:53 +1100 Subject: [PATCH 3/3] fixed numpy import --- .cache/v/cache/lastfailed | 1 + tests/test_utilities.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 .cache/v/cache/lastfailed 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 index 260cb9a..eb3777b 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -2,6 +2,7 @@ # 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():