3636from qiskit .dagcircuit .exceptions import DAGCircuitError
3737from qiskit .dagcircuit .dagnode import DAGNode , DAGOpNode , DAGInNode , DAGOutNode
3838from qiskit .utils import optionals as _optionals
39+ from qiskit .utils .deprecation import deprecate_function
3940
4041
4142class DAGCircuit :
@@ -491,8 +492,28 @@ def _add_op_node(self, op, qargs, cargs):
491492 self ._increment_op (op )
492493 return node_index
493494
495+ @deprecate_function (
496+ """The DAGCircuit._copy_circuit_metadata method is deprecated as of 0.20.0. It will be removed
497+ no earlier than 3 months after the release date. You should use the DAGCircuit.copy_empty_like
498+ method instead, which acts identically.
499+ """
500+ )
494501 def _copy_circuit_metadata (self ):
495- """Return a copy of source_dag with metadata but empty."""
502+ """DEPRECATED"""
503+ return self .copy_empty_like ()
504+
505+ def copy_empty_like (self ):
506+ """Return a copy of self with the same structure but empty.
507+
508+ That structure includes:
509+ * name and other metadata
510+ * global phase
511+ * duration
512+ * all the qubits and clbits, including the registers.
513+
514+ Returns:
515+ DAGCircuit: An empty copy of self.
516+ """
496517 target_dag = DAGCircuit ()
497518 target_dag .name = self .name
498519 target_dag ._global_phase = self ._global_phase
@@ -1550,7 +1571,7 @@ def layers(self):
15501571 return
15511572
15521573 # Construct a shallow copy of self
1553- new_layer = self ._copy_circuit_metadata ()
1574+ new_layer = self .copy_empty_like ()
15541575
15551576 for node in op_nodes :
15561577 # this creates new DAGOpNodes in the new_layer
@@ -1570,7 +1591,7 @@ def serial_layers(self):
15701591 same structure as in layers().
15711592 """
15721593 for next_node in self .topological_op_nodes ():
1573- new_layer = self ._copy_circuit_metadata ()
1594+ new_layer = self .copy_empty_like ()
15741595
15751596 # Save the support of the operation we add to the layer
15761597 support_list = []
0 commit comments