Skip to content

Commit

Permalink
fix to_unitary
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Nov 24, 2023
1 parent 590d9c8 commit dec59aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/braket/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions test/unit_tests/braket/circuits/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit dec59aa

Please sign in to comment.