From 53581108fdbb0c6e43951a4338b6296a47e8fdfd Mon Sep 17 00:00:00 2001 From: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com> Date: Mon, 29 Jan 2024 13:01:41 +0200 Subject: [PATCH] Remove qiskit.quantum_info.synthesis for Qiskit 1.0 release (#11592) * remove deprecated code in clifford_decompose and cnotdihedral_decompose * move tests from test/python/quantum_info to test/python/synthesis * move the Quaternion class from quantum_info/synthesis to quantum_info * deprecate cnot_rxx_decompose, and move to an internal code in the equivalence_library * deprecate cnot_rxx_decompose * move qsd from qiskit/quantum_info/synthesis to qiskit/synthesis/unitary * handle lint and docs errors in qsd * handle lint and docs errors in qsd * handle lint and docs errors in qsd * handle lint and docs errors in qsd * handle lint and docs errors in qsd * handle cyclic imports in qsd * minor * update qsd docs * move one_qubit_decompose from qiskit/quantum_info/synthesis to qiskit/synthesis/one_qubit * move xx_decompose from qiskit/quantum_info/synthesis to qiskit/synthesis/two_qubits * handle cyclic imports * move two-qubit synthesis code from qiskit/quantum_info/synthesis to qiskit/synthesis/two_qubits * update qsd docs * minor * add release notes * updates following review * add disable cyclic import to rv.py * add deprecation warning in qiskit/quantum_info/__init__.py * fix links * improve qsd docs following review * remove qiskit.quantum_info.synthesis * add release notes * update qsd docs * update release notes * update release notes --- qiskit/quantum_info/__init__.py | 23 -------- qiskit/quantum_info/synthesis/__init__.py | 30 ---------- .../quantum_info/synthesis/ion_decompose.py | 57 ------------------- ...move_qinfo_synthesis-1917c7ccfcc62180.yaml | 13 +++++ test/python/synthesis/test_synthesis.py | 38 ------------- .../synthesis/xx_decompose/test_decomposer.py | 8 --- 6 files changed, 13 insertions(+), 156 deletions(-) delete mode 100644 qiskit/quantum_info/synthesis/__init__.py delete mode 100644 qiskit/quantum_info/synthesis/ion_decompose.py create mode 100644 releasenotes/notes/remove_qinfo_synthesis-1917c7ccfcc62180.yaml diff --git a/qiskit/quantum_info/__init__.py b/qiskit/quantum_info/__init__.py index 4597520a0aa3..ba3299c9e100 100644 --- a/qiskit/quantum_info/__init__.py +++ b/qiskit/quantum_info/__init__.py @@ -156,26 +156,3 @@ negativity, ) from .quaternion import Quaternion - -_DEPRECATED_NAMES = { - "OneQubitEulerDecomposer": "qiskit.synthesis", - "TwoQubitBasisDecomposer": "qiskit.synthesis", - "XXDecomposer": "qiskit.synthesis", - "two_qubit_cnot_decompose": "qiskit.synthesis", -} - - -def __getattr__(name): - if name in _DEPRECATED_NAMES: - import importlib - import warnings - - module_name = _DEPRECATED_NAMES[name] - warnings.warn( - f"Accessing '{name}' from '{__name__}' is deprecated since Qiskit 0.46" - f" and will be removed in 1.0. Import from '{module_name}' instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(importlib.import_module(module_name), name) - raise AttributeError(f"module '{__name__}' has no attribute '{name}'") diff --git a/qiskit/quantum_info/synthesis/__init__.py b/qiskit/quantum_info/synthesis/__init__.py deleted file mode 100644 index a32236a1a8b3..000000000000 --- a/qiskit/quantum_info/synthesis/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2017. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -"""State and Unitary synthesis methods.""" - -from __future__ import annotations -import warnings - -from qiskit.synthesis.one_qubit import OneQubitEulerDecomposer -from qiskit.synthesis.two_qubit.xx_decompose import XXDecomposer -from qiskit.synthesis.two_qubit.two_qubit_decompose import ( - TwoQubitBasisDecomposer, - two_qubit_cnot_decompose, -) - -warnings.warn( - "The qiskit.quantum_info.synthesis module is deprecated since Qiskit 0.46.0." - "It will be removed in the Qiskit 1.0 release.", - stacklevel=2, - category=DeprecationWarning, -) diff --git a/qiskit/quantum_info/synthesis/ion_decompose.py b/qiskit/quantum_info/synthesis/ion_decompose.py deleted file mode 100644 index 66f2831ecdb7..000000000000 --- a/qiskit/quantum_info/synthesis/ion_decompose.py +++ /dev/null @@ -1,57 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2017, 2019. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -""" -Decomposition methods for trapped-ion basis gates RXXGate, RXGate, RYGate. -""" - -from __future__ import annotations -import numpy as np - -from qiskit.circuit.quantumcircuit import QuantumCircuit -from qiskit.circuit.library.standard_gates.ry import RYGate -from qiskit.circuit.library.standard_gates.rx import RXGate -from qiskit.circuit.library.standard_gates.rxx import RXXGate -from qiskit.utils.deprecation import deprecate_func - - -@deprecate_func(since="0.46.0") -def cnot_rxx_decompose(plus_ry: bool = True, plus_rxx: bool = True): - """Decomposition of CNOT gate. - - NOTE: this differs to CNOT by a global phase. - The matrix returned is given by exp(1j * pi/4) * CNOT - - Args: - plus_ry (bool): positive initial RY rotation - plus_rxx (bool): positive RXX rotation. - - Returns: - QuantumCircuit: The decomposed circuit for CNOT gate (up to - global phase). - """ - # Convert boolean args to +/- 1 signs - if plus_ry: - sgn_ry = 1 - else: - sgn_ry = -1 - if plus_rxx: - sgn_rxx = 1 - else: - sgn_rxx = -1 - circuit = QuantumCircuit(2, global_phase=-sgn_ry * sgn_rxx * np.pi / 4) - circuit.append(RYGate(sgn_ry * np.pi / 2), [0]) - circuit.append(RXXGate(sgn_rxx * np.pi / 2), [0, 1]) - circuit.append(RXGate(-sgn_rxx * np.pi / 2), [0]) - circuit.append(RXGate(-sgn_rxx * sgn_ry * np.pi / 2), [1]) - circuit.append(RYGate(-sgn_ry * np.pi / 2), [0]) - return circuit diff --git a/releasenotes/notes/remove_qinfo_synthesis-1917c7ccfcc62180.yaml b/releasenotes/notes/remove_qinfo_synthesis-1917c7ccfcc62180.yaml new file mode 100644 index 000000000000..bd335e7fb61e --- /dev/null +++ b/releasenotes/notes/remove_qinfo_synthesis-1917c7ccfcc62180.yaml @@ -0,0 +1,13 @@ +--- +upgrade: + - | + Removed the ``qiskit.quantum_info.synthesis`` module, which has been deprecated since the 0.46 release. + The following objects have been moved to :mod:`qiskit.synthesis`: + + * :class:`~.OneQubitEulerDecomposer` has been moved to :mod:`qiskit.synthesis.one_qubit` + * :class:`~.TwoQubitBasisDecomposer` has been moved to :mod:`qiskit.synthesis.two_qubits` + * :class:`~.XXDecomposer` has been moved to :mod:`qiskit.synthesis.two_qubits` + * :func:`~.two_qubit_cnot_decompose` has been moved to :mod:`qiskit.synthesis.two_qubits` + + This function was removed, since it has already been deprecated in the 0.46 release: + * ``cnot_rxx_decompose`` diff --git a/test/python/synthesis/test_synthesis.py b/test/python/synthesis/test_synthesis.py index 31aef162fed1..875cac013d49 100644 --- a/test/python/synthesis/test_synthesis.py +++ b/test/python/synthesis/test_synthesis.py @@ -78,7 +78,6 @@ from qiskit.synthesis.unitary import qsd from qiskit.test import QiskitTestCase -from qiskit.quantum_info.synthesis.ion_decompose import cnot_rxx_decompose def make_oneq_cliffords(): @@ -630,14 +629,6 @@ def test_float_input_angles(self): self.assertAlmostEqual(phi, expected_phi) self.assertAlmostEqual(lam, expected_lam) - def test_deprecation(self): - """Assert that importing this class from quantum_info raises a deprecation warning.""" - # pylint: disable = no-name-in-module - with self.assertWarns(DeprecationWarning): - from qiskit.quantum_info import OneQubitEulerDecomposer as old_OneQubitEulerDecomposer - - _ = old_OneQubitEulerDecomposer(basis="PSX") - # FIXME: streamline the set of test cases class TestTwoQubitWeylDecomposition(CheckDecompositions): @@ -988,21 +979,6 @@ def test_weyl_specialize_general(self, aaa=0.456, bbb=0.345, ccc=0.123): class TestTwoQubitDecompose(CheckDecompositions): """Test TwoQubitBasisDecomposer() for exact/approx decompositions""" - def test_cnot_rxx_decompose(self): - """Verify CNOT decomposition into RXX gate is correct""" - cnot = Operator(CXGate()) - # Assert that this class raises a deprecation warning - with self.assertWarns(DeprecationWarning): - decomps = [ - cnot_rxx_decompose(), - cnot_rxx_decompose(plus_ry=True, plus_rxx=True), - cnot_rxx_decompose(plus_ry=True, plus_rxx=False), - cnot_rxx_decompose(plus_ry=False, plus_rxx=True), - cnot_rxx_decompose(plus_ry=False, plus_rxx=False), - ] - for decomp in decomps: - self.assertTrue(cnot.equiv(decomp)) - @combine(seed=range(10), name="test_exact_two_qubit_cnot_decompose_random_{seed}") def test_exact_two_qubit_cnot_decompose_random(self, seed): """Verify exact CNOT decomposition for random Haar 4x4 unitary (seed={seed}).""" @@ -1253,20 +1229,6 @@ def test_euler_basis_selection(self, euler_bases, kak_gates, seed): requested_basis = set(oneq_gates + [kak_gate_name]) self.assertTrue(decomposition_basis.issubset(requested_basis)) - def test_deprecation(self): - """Assert that importing these classes from quantum_info raises a deprecation warning.""" - # pylint: disable = no-name-in-module - with self.assertWarns(DeprecationWarning): - unitary = random_unitary(4, seed=1234) - from qiskit.quantum_info import TwoQubitBasisDecomposer as old_TwoQubitBasisDecomposer - - _ = old_TwoQubitBasisDecomposer(unitary) - - with self.assertWarns(DeprecationWarning): - from qiskit.quantum_info import two_qubit_cnot_decompose as old_two_qubit_cnot_decompose - - _ = old_two_qubit_cnot_decompose(unitary) - @ddt class TestPulseOptimalDecompose(CheckDecompositions): diff --git a/test/python/synthesis/xx_decompose/test_decomposer.py b/test/python/synthesis/xx_decompose/test_decomposer.py index b1a9f698594d..85cf1b9ed5f9 100644 --- a/test/python/synthesis/xx_decompose/test_decomposer.py +++ b/test/python/synthesis/xx_decompose/test_decomposer.py @@ -155,11 +155,3 @@ def test_no_error_on_empty_basis_fidelity_trivial_target(self): mat = Operator(qc).to_matrix() dqc = decomposer(mat) self.assertTrue(np.allclose(mat, Operator(dqc).to_matrix())) - - def test_deprecation(self): - """Assert that importing this class from quantum_info raises a deprecation warning.""" - # pylint: disable = no-name-in-module - with self.assertWarns(DeprecationWarning): - from qiskit.quantum_info import XXDecomposer as old_XXDecomposer - - _ = old_XXDecomposer(euler_basis="PSX")