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

Expire deprecation on qargs=None in DAG appends #11190

Merged
merged 1 commit into from
Nov 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from collections import OrderedDict, defaultdict, deque, namedtuple
import copy
import math
import warnings
from typing import Dict, Generator, Any, List

import numpy as np
Expand Down Expand Up @@ -657,16 +656,8 @@ def apply_operation_back(self, op, qargs=(), cargs=(), *, check=True):
DAGCircuitError: if a leaf node is connected to multiple outputs

"""
if qargs is None:
_warn_none_args()
qargs = ()
else:
qargs = tuple(qargs)
if cargs is None:
_warn_none_args()
cargs = ()
else:
cargs = tuple(cargs)
qargs = tuple(qargs)
cargs = tuple(cargs)

if self._operation_may_have_bits(op):
# This is the slow path; most of the time, this won't happen.
Expand Down Expand Up @@ -710,16 +701,8 @@ def apply_operation_front(self, op, qargs=(), cargs=(), *, check=True):
Raises:
DAGCircuitError: if initial nodes connected to multiple out edges
"""
if qargs is None:
_warn_none_args()
qargs = ()
else:
qargs = tuple(qargs)
if cargs is None:
_warn_none_args()
cargs = ()
else:
cargs = tuple(cargs)
qargs = tuple(qargs)
cargs = tuple(cargs)

if self._operation_may_have_bits(op):
# This is the slow path; most of the time, this won't happen.
Expand Down Expand Up @@ -2116,12 +2099,3 @@ def draw(self, scale=0.7, filename=None, style="color"):
from qiskit.visualization.dag_visualization import dag_drawer

return dag_drawer(dag=self, scale=scale, filename=filename, style=style)


def _warn_none_args():
warnings.warn(
"Passing 'None' as the qubits or clbits of an operation to 'DAGCircuit' methods"
" is deprecated since Qiskit 0.45 and will be removed in Qiskit 1.0. Instead, pass '()'.",
DeprecationWarning,
stacklevel=3,
)
6 changes: 6 additions & 0 deletions releasenotes/notes/remove-dag-none-be220777dc246803.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
upgrade:
- |
It is no longer allowable to pass ``None`` as the ``qargs`` or ``cargs`` parameters in
:meth:`.DAGCircuit.apply_operation_back` and :meth:`~.DAGCircuit.apply_operation_front`. If you
want to explicitly pass an empty argument, use the empty tuple ``()`` instead.
12 changes: 0 additions & 12 deletions test/python/dagcircuit/test_dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,18 +487,6 @@ def test_apply_operation_back(self):
self.assertEqual(len(list(self.dag.nodes())), 16)
self.assertEqual(len(list(self.dag.edges())), 17)

def test_apply_operation_rejects_none(self):
"""Test that the ``apply_operation_*`` methods warn when given ``None``."""
noop = Instruction("noop", 0, 0, [])
with self.assertWarnsRegex(DeprecationWarning, "Passing 'None'"):
self.dag.apply_operation_back(noop, None, ())
with self.assertWarnsRegex(DeprecationWarning, "Passing 'None'"):
self.dag.apply_operation_back(noop, (), None)
with self.assertWarnsRegex(DeprecationWarning, "Passing 'None'"):
self.dag.apply_operation_front(noop, None, ())
with self.assertWarnsRegex(DeprecationWarning, "Passing 'None'"):
self.dag.apply_operation_front(noop, (), None)

def test_edges(self):
"""Test that DAGCircuit.edges() behaves as expected with ops."""
x_gate = XGate().c_if(*self.condition)
Expand Down