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

Deprecate qiskit/quantum_info/synthesis and move to qiskit/synthesis #11460

Merged
merged 38 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cdc35c4
remove deprecated code in clifford_decompose and cnotdihedral_decompose
ShellyGarion Dec 27, 2023
56e3d54
move tests from test/python/quantum_info to test/python/synthesis
ShellyGarion Dec 27, 2023
3e5f7ba
move the Quaternion class from quantum_info/synthesis to quantum_info
ShellyGarion Dec 28, 2023
133be57
deprecate cnot_rxx_decompose, and move to an internal code in the equ…
ShellyGarion Dec 28, 2023
70efcb2
deprecate cnot_rxx_decompose
ShellyGarion Dec 28, 2023
340ef4c
move qsd from qiskit/quantum_info/synthesis to qiskit/synthesis/unitary
ShellyGarion Dec 28, 2023
3daa862
handle lint and docs errors in qsd
ShellyGarion Dec 28, 2023
069a2bf
handle lint and docs errors in qsd
ShellyGarion Dec 28, 2023
ceeb96f
handle lint and docs errors in qsd
ShellyGarion Dec 28, 2023
2f23da3
handle lint and docs errors in qsd
ShellyGarion Dec 28, 2023
502118b
handle lint and docs errors in qsd
ShellyGarion Dec 28, 2023
671ad1e
handle cyclic imports in qsd
ShellyGarion Dec 28, 2023
5fe9353
minor
ShellyGarion Dec 28, 2023
e2a93ed
update qsd docs
ShellyGarion Dec 31, 2023
b410e58
move one_qubit_decompose from qiskit/quantum_info/synthesis to qiskit…
ShellyGarion Dec 31, 2023
b3f2e3e
move xx_decompose from qiskit/quantum_info/synthesis to qiskit/synthe…
ShellyGarion Dec 31, 2023
2ee51ff
handle cyclic imports
ShellyGarion Dec 31, 2023
209d95c
move two-qubit synthesis code from qiskit/quantum_info/synthesis to q…
ShellyGarion Dec 31, 2023
bbf40cb
update qsd docs
ShellyGarion Jan 1, 2024
7958c29
minor
ShellyGarion Jan 1, 2024
624ee28
add release notes
ShellyGarion Jan 1, 2024
1a8f17d
updates following review
ShellyGarion Jan 7, 2024
48ac742
add disable cyclic import to rv.py
ShellyGarion Jan 7, 2024
067f9ff
add deprecation warning in qiskit/quantum_info/__init__.py
ShellyGarion Jan 9, 2024
d9a2c91
fix links
ShellyGarion Jan 16, 2024
13e63a3
improve qsd docs following review
ShellyGarion Jan 18, 2024
166fcce
update qsd after review
ShellyGarion Jan 21, 2024
8ccfaa0
change pending deprecatrion to deprecation in ion_decompose
ShellyGarion Jan 21, 2024
5bfa6eb
update release notes following review
ShellyGarion Jan 21, 2024
3a9d0a5
update pending deprecation to deprecation
ShellyGarion Jan 21, 2024
0e1a9d7
add test for a deprecation
ShellyGarion Jan 21, 2024
1ae8f20
add more tests for deprecations
ShellyGarion Jan 22, 2024
26ee2e1
add another test for deprecation
ShellyGarion Jan 22, 2024
382ca44
handle lint errors
ShellyGarion Jan 22, 2024
f277b33
minor fix following review
ShellyGarion Jan 23, 2024
620924a
remove test for _cnot_rxx_decompose() private method
ShellyGarion Jan 23, 2024
7176d1c
fix conflict with qiskit/synthesis/__init__.py
ShellyGarion Jan 23, 2024
fac7d0f
fix conflict with main
ShellyGarion Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ShellyGarion marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -146,7 +146,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 (
ShellyGarion marked this conversation as resolved.
Show resolved Hide resolved
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}'")
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
27 changes: 26 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 @@ -94,8 +94,29 @@
Unitary Synthesis
=================
ShellyGarion marked this conversation as resolved.
Show resolved Hide resolved

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

"""

from .evolution import (
Expand Down Expand Up @@ -137,4 +158,8 @@
)
from .discrete_basis import SolovayKitaevDecomposition, generate_basic_approximations
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
15 changes: 15 additions & 0 deletions qiskit/synthesis/one_qubit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 2023.
#
# 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.

"""Module containing one qubit unitary synthesis methods."""

from .one_qubit_decompose import OneQubitEulerDecomposer
Loading