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

Remove gate argument from qiskit.transpiler.passes.Decompose #9325

Merged
merged 6 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
41 changes: 1 addition & 40 deletions qiskit/transpiler/passes/basis/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,30 @@
# that they have been altered from the originals.

"""Expand a gate in a circuit using its decomposition rules."""
import warnings
from typing import Type, Union, List, Optional
from fnmatch import fnmatch

from qiskit.transpiler.basepasses import TransformationPass
from qiskit.dagcircuit.dagcircuit import DAGCircuit
from qiskit.converters.circuit_to_dag import circuit_to_dag
from qiskit.circuit.gate import Gate
from qiskit.utils.deprecation import deprecate_arguments


class Decompose(TransformationPass):
"""Expand a gate in a circuit using its decomposition rules."""

@deprecate_arguments({"gate": "gates_to_decompose"})
def __init__(
self,
gate: Optional[Type[Gate]] = None,
gates_to_decompose: Optional[Union[Type[Gate], List[Type[Gate]], List[str], str]] = None,
) -> None:
"""Decompose initializer.

Args:
gate: DEPRECATED gate to decompose.
gates_to_decompose: optional subset of gates to be decomposed,
identified by gate label, name or type. Defaults to all gates.
"""
super().__init__()

if gate is not None:
self.gates_to_decompose = gate
else:
self.gates_to_decompose = gates_to_decompose

@property
def gate(self) -> Gate:
"""Returns the gate"""
warnings.warn(
"The gate argument is deprecated as of qiskit-terra 0.19.0, and "
"will be removed no earlier than 3 months after that "
"release date. You should use the gates_to_decompose argument "
"instead.",
DeprecationWarning,
stacklevel=2,
)
return self.gates_to_decompose

@gate.setter
def gate(self, value):
"""Sets the gate

Args:
value (Gate): new value for gate
"""
warnings.warn(
"The gate argument is deprecated as of qiskit-terra 0.19.0, and "
"will be removed no earlier than 3 months after that "
"release date. You should use the gates_to_decompose argument "
"instead.",
DeprecationWarning,
stacklevel=2,
)
self.gates_to_decompose = value
self.gates_to_decompose = gates_to_decompose

def run(self, dag: DAGCircuit) -> DAGCircuit:
"""Run the Decompose pass on `dag`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
upgrade:
- |
The ``gate`` argument to the transpiler pass :class:`~.Decompose` was deprecated in Terra 0.19 and is now removed.
4 changes: 1 addition & 3 deletions test/python/transpiler/test_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def test_decompose_none(self):
circuit = QuantumCircuit(qr)
circuit.h(qr[0])
dag = circuit_to_dag(circuit)
pass_ = Decompose(HGate)
with self.assertWarns(DeprecationWarning):
pass_.gate = None
pass_ = Decompose()
after_dag = pass_.run(dag)
op_nodes = after_dag.op_nodes()
self.assertEqual(len(op_nodes), 1)
Expand Down