Skip to content

Commit

Permalink
Deprecate qiskit/quantum_info/synthesis and move to qiskit/synthesis (#…
Browse files Browse the repository at this point in the history
…11460)

* 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

* update qsd after review

* change pending deprecatrion to deprecation in ion_decompose

* update release notes following review

* update pending deprecation to deprecation

* add test for a deprecation

* add more tests for deprecations

* add another test for deprecation

* handle lint errors

* minor fix following review

* remove test for _cnot_rxx_decompose() private method

(cherry picked from commit 8887f44)

# Conflicts:
#	qiskit/synthesis/__init__.py
#	qiskit/transpiler/synthesis/qsd.py
#	test/benchmarks/random_circuit_hex.py
  • Loading branch information
ShellyGarion authored and mergify[bot] committed Jan 24, 2024
1 parent 1c4a4de commit a05527b
Show file tree
Hide file tree
Showing 49 changed files with 322 additions and 241 deletions.
4 changes: 2 additions & 2 deletions qiskit/circuit/library/generalized_gates/rv.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def __init__(self, v_x, v_y, v_z, basis="U"):
v_y (float): y-component
v_z (float): z-component
basis (str, optional): basis (see
:class:`~qiskit.quantum_info.synthesis.one_qubit_decompose.OneQubitEulerDecomposer`)
:class:`~qiskit.synthesis.one_qubit.one_qubit_decompose.OneQubitEulerDecomposer`)
"""
# pylint: disable=cyclic-import
from qiskit.quantum_info.synthesis.one_qubit_decompose import OneQubitEulerDecomposer
from qiskit.synthesis.one_qubit.one_qubit_decompose import OneQubitEulerDecomposer

super().__init__("rv", 1, [v_x, v_y, v_z])
self._decomposer = OneQubitEulerDecomposer(basis=basis)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/generalized_gates/uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from qiskit.exceptions import QiskitError

# pylint: disable=cyclic-import
from qiskit.quantum_info.synthesis.one_qubit_decompose import OneQubitEulerDecomposer
from qiskit.synthesis.one_qubit.one_qubit_decompose import OneQubitEulerDecomposer

from .diagonal import Diagonal

Expand Down
6 changes: 3 additions & 3 deletions qiskit/circuit/library/generalized_gates/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from qiskit.quantum_info.operators.predicates import is_unitary_matrix

# pylint: disable=cyclic-import
from qiskit.quantum_info.synthesis.one_qubit_decompose import OneQubitEulerDecomposer
from qiskit.quantum_info.synthesis.two_qubit_decompose import two_qubit_cnot_decompose
from qiskit.synthesis.one_qubit.one_qubit_decompose import OneQubitEulerDecomposer
from qiskit.synthesis.two_qubit.two_qubit_decompose import two_qubit_cnot_decompose

from .isometry import Isometry

Expand Down Expand Up @@ -148,7 +148,7 @@ def _define(self):
elif self.num_qubits == 2:
self.definition = two_qubit_cnot_decompose(self.to_matrix())
else:
from qiskit.quantum_info.synthesis.qsd import ( # pylint: disable=cyclic-import
from qiskit.synthesis.unitary.qsd import ( # pylint: disable=cyclic-import
qs_decomposition,
)

Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/pauli_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from qiskit.circuit.gate import Gate
from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.synthesis import EvolutionSynthesis, LieTrotter
from qiskit.synthesis.evolution import EvolutionSynthesis, LieTrotter
from qiskit.quantum_info import Pauli, SparsePauliOp


Expand Down
40 changes: 35 additions & 5 deletions qiskit/circuit/library/standard_gates/equivalence_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
Clbit,
)

from qiskit.quantum_info.synthesis.ion_decompose import cnot_rxx_decompose

from . import (
HGate,
CHGate,
Expand Down Expand Up @@ -83,6 +81,38 @@
_sel = StandardEquivalenceLibrary = EquivalenceLibrary()


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 * pi / 4)
circuit.append(RYGate(sgn_ry * pi / 2), [0])
circuit.append(RXXGate(sgn_rxx * pi / 2), [0, 1])
circuit.append(RXGate(-sgn_rxx * pi / 2), [0])
circuit.append(RXGate(-sgn_rxx * sgn_ry * pi / 2), [1])
circuit.append(RYGate(-sgn_ry * pi / 2), [0])
return circuit


# Import existing gate definitions

# HGate
Expand Down Expand Up @@ -1250,9 +1280,9 @@

# CXGate

for plus_ry in [False, True]:
for plus_rxx in [False, True]:
cx_to_rxx = cnot_rxx_decompose(plus_ry, plus_rxx)
for pos_ry in [False, True]:
for pos_rxx in [False, True]:
cx_to_rxx = _cnot_rxx_decompose(pos_ry, pos_rxx)
_sel.add_equivalence(CXGate(), cx_to_rxx)

# CXGate
Expand Down
50 changes: 29 additions & 21 deletions qiskit/quantum_info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
Utility Functions
=================
.. autosummary::
:toctree: ../stubs/
Quaternion
.. autofunction:: partial_trace
.. autofunction:: schmidt_decomposition
.. autofunction:: shannon_entropy
Expand Down Expand Up @@ -105,19 +110,6 @@
Z2Symmetries
Synthesis
=========
.. autosummary::
:toctree: ../stubs/
OneQubitEulerDecomposer
TwoQubitBasisDecomposer
Quaternion
XXDecomposer
.. autofunction:: two_qubit_cnot_decompose
.. autofunction:: decompose_clifford
"""

from __future__ import annotations
Expand Down Expand Up @@ -163,11 +155,27 @@
state_fidelity,
negativity,
)
from .synthesis import (
OneQubitEulerDecomposer,
Quaternion,
TwoQubitBasisDecomposer,
XXDecomposer,
decompose_clifford,
two_qubit_cnot_decompose,
)
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}'")
File renamed without changes.
20 changes: 15 additions & 5 deletions qiskit/quantum_info/synthesis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
"""State and Unitary synthesis methods."""

from __future__ import annotations
from .two_qubit_decompose import TwoQubitBasisDecomposer, two_qubit_cnot_decompose
from .one_qubit_decompose import OneQubitEulerDecomposer
from .quaternion import Quaternion
from .clifford_decompose import decompose_clifford
from .xx_decompose.decomposer import XXDecomposer
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,
)
69 changes: 0 additions & 69 deletions qiskit/quantum_info/synthesis/clifford_decompose.py

This file was deleted.

50 changes: 0 additions & 50 deletions qiskit/quantum_info/synthesis/cnotdihedral_decompose.py

This file was deleted.

2 changes: 2 additions & 0 deletions qiskit/quantum_info/synthesis/ion_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
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.
Expand Down
45 changes: 44 additions & 1 deletion qiskit/synthesis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
r"""
===========================================
Circuit Synthesis (:mod:`qiskit.synthesis`)
===========================================
Expand Down Expand Up @@ -84,6 +84,40 @@
.. autofunction:: generate_basic_approximations
<<<<<<< HEAD
=======
Basis Change Synthesis
======================
.. autofunction:: synth_qft_line
Unitary Synthesis
=================
Decomposition of general :math:`2^n \times 2^n` unitary matrices for any number of qubits.
.. autofunction:: qs_decomposition
The Approximate Quantum Compiler is available here: :mod:`qiskit.synthesis.unitary.aqc`
One-Qubit Synthesis
===================
.. autosummary::
:toctree: ../stubs/
OneQubitEulerDecomposer
Two-Qubit Synthesis
===================
.. autosummary::
:toctree: ../stubs/
TwoQubitBasisDecomposer
XXDecomposer
>>>>>>> 8887f4436 (Deprecate qiskit/quantum_info/synthesis and move to qiskit/synthesis (#11460))
"""

from .evolution import (
Expand Down Expand Up @@ -120,3 +154,12 @@
)
from .stabilizer import synth_stabilizer_layers, synth_stabilizer_depth_lnn
from .discrete_basis import SolovayKitaevDecomposition, generate_basic_approximations
<<<<<<< HEAD
=======
from .qft import synth_qft_line
from .unitary.qsd import qs_decomposition
from .unitary import aqc
from .one_qubit import OneQubitEulerDecomposer
from .two_qubit.xx_decompose import XXDecomposer
from .two_qubit.two_qubit_decompose import TwoQubitBasisDecomposer, two_qubit_cnot_decompose
>>>>>>> 8887f4436 (Deprecate qiskit/quantum_info/synthesis and move to qiskit/synthesis (#11460))
Loading

0 comments on commit a05527b

Please sign in to comment.