From dec59aa629f3da76f6c1988e052d1e0fd3a15590 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Jaskula Date: Sat, 25 Nov 2023 00:47:59 +0100 Subject: [PATCH] fix to_unitary --- src/braket/circuits/circuit.py | 4 +--- test/unit_tests/braket/circuits/test_circuit.py | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/braket/circuits/circuit.py b/src/braket/circuits/circuit.py index a844ed117..aeae8585d 100644 --- a/src/braket/circuits/circuit.py +++ b/src/braket/circuits/circuit.py @@ -1434,9 +1434,7 @@ def to_unitary(self) -> np.ndarray: qubits = self.qubits if not qubits: return np.zeros(0, dtype=complex) - return calculate_unitary_big_endian(self.instructions, qubits) * np.exp( - 1j * self.global_phase - ) + return calculate_unitary_big_endian(self.instructions, qubits) @property def qubits_frozen(self) -> bool: diff --git a/test/unit_tests/braket/circuits/test_circuit.py b/test/unit_tests/braket/circuits/test_circuit.py index 4b1a1f289..64e4d7ccf 100644 --- a/test/unit_tests/braket/circuits/test_circuit.py +++ b/test/unit_tests/braket/circuits/test_circuit.py @@ -2013,6 +2013,14 @@ def test_to_unitary_with_compiler_directives_returns_expected_unitary(): ) +def test_to_unitary_with_global_phase(): + circuit = Circuit().x(0) + circuit_unitary = np.array([[0, 1], [1, 0]]) + assert np.allclose(circuit.to_unitary(), circuit_unitary) + circuit = circuit.gphase(np.pi / 2) + assert np.allclose(circuit.to_unitary(), 1j * circuit_unitary) + + @pytest.mark.parametrize( "circuit,expected_unitary", [