question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DAGCircuit replace subcircuit

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Cryoriscommented, Apr 5, 2022

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#L1040

0reactions
kdkcommented, Nov 20, 2019

I 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 DAGNodes 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.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

DAGCircuit.substitute_node_with_dag - Qiskit documentation
Replace one node with dag. Parameters. node (DAGOpNode) – node to substitute. input_dag (DAGCircuit) – circuit that will substitute the node. wires ( ......
Read more >
Qucs - Working with Subcircuits
Now change to a schematic where you want to use the subcircuit. Then press on the subcircuit name (content listview). By entering the...
Read more >
Commuting Compositions for Quantum Circuit Reduction
This technique searches a circuit for a subcircuit matching a template of gates, then replaces the subcircuit with an optimized version.
Read more >
Technology Mapping for Circuit Optimization using Content ...
Each transformation effectively replaces a subcircuit with an equivalent ... A DAG circuit representation is used in FlowMap, where Boolean.
Read more >
qiskit.circuit.quantumregister.QuantumRegister Example
target_dag = DAGCircuit() target_dag.name = source_dag.name for creg in ... If a gate is conditioned, we expect the replacement subcircuit # to depend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found