Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-complex dtypes in OneQubitEulerDecomposer methods #9828

Merged
merged 3 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions qiskit/quantum_info/synthesis/one_qubit_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def angles(self, unitary):
Returns:
tuple: (theta, phi, lambda).
"""
unitary = np.asarray(unitary, dtype=complex)
theta, phi, lam, _ = self._params(unitary)
return theta, phi, lam

Expand All @@ -264,6 +265,7 @@ def angles_and_phase(self, unitary):
Returns:
tuple: (theta, phi, lambda, phase).
"""
unitary = np.asarray(unitary, dtype=complex)
return self._params(unitary)

_params_zyz = staticmethod(euler_one_qubit_decomposer.params_zyz)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
fixes:
- |
Fixed an issue with the :class:`~.OneQubitEulerDecomposer` class's methods
:meth:`~.OneQubitEulerDecomposer.angles` and :meth:`~.OneQubitEulerDecomposer.angles_and_phase`
would error if the input matrix was of a dtype other than ``complex``/``np.cdouble``. In earlier
releases this worked fine but this stopped working in Qiskit Terra 0.23.0
when the internals of :class:`~.OneQubitEulerDecomposer` were re-written
in Rust.
Fixed `#9827 <https://github.com/Qiskit/qiskit-terra/issues/9827>`__
38 changes: 38 additions & 0 deletions test/python/quantum_info/test_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,44 @@ def test_psx_zsx_special_cases(self):
self.assertTrue(np.allclose(unitary, Operator(qc_zsx).data))
self.assertTrue(np.allclose(unitary, Operator(qc_zsxx).data))

def test_float_input_angles_and_phase(self):
"""Test angles and phase with float input."""
decomposer = OneQubitEulerDecomposer("PSX")
input_matrix = np.array(
[
[0.70710678, 0.70710678],
[0.70710678, -0.70710678],
],
dtype=np.float64,
)
(theta, phi, lam, gamma) = decomposer.angles_and_phase(input_matrix)
expected_theta = 1.5707963267948966
expected_phi = 0.0
expected_lam = 3.141592653589793
expected_gamma = -0.7853981633974483
self.assertAlmostEqual(theta, expected_theta)
self.assertAlmostEqual(phi, expected_phi)
self.assertAlmostEqual(lam, expected_lam)
self.assertAlmostEqual(gamma, expected_gamma)

def test_float_input_angles(self):
"""Test angles with float input."""
decomposer = OneQubitEulerDecomposer("PSX")
input_matrix = np.array(
[
[0.70710678, 0.70710678],
[0.70710678, -0.70710678],
],
dtype=np.float64,
)
(theta, phi, lam) = decomposer.angles(input_matrix)
expected_theta = 1.5707963267948966
expected_phi = 0.0
expected_lam = 3.141592653589793
self.assertAlmostEqual(theta, expected_theta)
self.assertAlmostEqual(phi, expected_phi)
self.assertAlmostEqual(lam, expected_lam)


# FIXME: streamline the set of test cases
class TestTwoQubitWeylDecomposition(CheckDecompositions):
Expand Down