DAGCircuit replace subcircuit
See original GitHub issueWhat is the expected enhancement?
Currently it’s possible to replace a give node with a DAGCircuit using the substitute_node_with_dag
method. However, I’d like to be able to take a subcircuit of the full circuit and replace it with another subcircuit (given).
Consider template-based optimization where a subcircuit is matched to a template, to be replaced with some other subcircuit (maybe even the identity). E.g., see https://www.nature.com/articles/s41534-018-0072-4. It is currently unclear how one would implement such functionality given the API of DAGCircuit. Ideally, you’d identify a set of nodes in the case of a DAGCircuit or a set of gates in a QuantumCircuit that need to be removed, followed by the insertion of a new subcircuit that connects the right qubits to where the old nodes were attached.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
This looks like it’s covered by
DAGCircuit.replace_block_with_op
which was introduced in #7185: https://github.com/Qiskit/qiskit-terra/blob/df2a6ebdee904572d33a94a18d9362ee6e6c81f7/qiskit/dagcircuit/dagcircuit.py#L1040I pushed #3503 for an idea of how an interface for subcircuit replacement might look. There are a few open questions, chief among which is that a list of
DAGNode
s isn’t an ideal specification for a subcircuit. It’s clunky for the user to get, and requires us to validate that they form an uninterrupted subcircuit (unless they were already stored as composite instructions.)(Contracting down to a single node before replacing is obviously not great for performance, and is only temporary while we figure out the required interface/behavior.)