qiskit.dagcircuit.DAGCircuit.replace_block_with_op¶
- DAGCircuit.replace_block_with_op(node_block, op, wire_pos_map, cycle_check=True)[source]¶
Replace a block of nodes with a single node.
This is used to consolidate a block of DAGOpNodes into a single operation. A typical example is a block of gates being consolidated into a single
UnitaryGate
representing the unitary matrix of the block.- Parameters
node_block (List[DAGNode]) -- A list of dag nodes that represents the node block to be replaced
op (qiskit.circuit.Operation) -- The operation to replace the block with
wire_pos_map (Dict[Qubit, int]) -- The dictionary mapping the qarg to the position. This is necessary to reconstruct the qarg order over multiple gates in the combined single op node.
cycle_check (bool) -- When set to True this method will check that replacing the provided
node_block
with a single node would introduce a cycle (which would invalidate theDAGCircuit
) and will raise aDAGCircuitError
if a cycle would be introduced. This checking comes with a run time penalty. If you can guarantee that your inputnode_block
is a contiguous block and won't introduce a cycle when it's contracted to a single node, this can be set toFalse
to improve the runtime performance of this method.
- Raises
DAGCircuitError -- if
cycle_check
is set toTrue
and replacing the specified block introduces a cycle or ifnode_block
is empty.- Returns
The op node that replaces the block.
- Return type