-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
What should we add?
The problem:
We crurrently have to methods that allow us to add an operation to the DAGCircuit
from rust.
DAGCircuit::push_back
andDAGCircuit::push_front
which accepts aPackedInstruction
instance as an argument and must have valid interned qargs and cargs.DAGCircuit::py_apply_operation_back
andDAGCircuit::py_apply_operation_front
which performs the addition of instructions in a similar way to what was done before, however this is only with python types and is not exposed to the rest of the rust api.
In each case we're either required to re-intern the qargs/cargs, or have an already valid instance of PackedInstruction
that could work in this circuit, which is what I ultimately did for #13032. But now that we are building transpiler passes in Rust alone, having to own mutable access to the DAGCircuit
and inserting qargs directly seems very unsafe.
The solution
Adding rust-native apply_operation_back
and apply_operation_front
to DAGCircuit
that is exposed to the rest of the crates.
Having said methods would allow us to:
- Insert a
PackedOperation
of any type and insert qargs and cargs by index (Qubit
orClbit
as defined by thecircuit
crate), since that's how it is registered in theDAGCircuit
. - Avoid having mutable access to private methods in the
DAGCircuit
, such as the interners orBitData
. - Overall make it easier to modify and create
DAGCircuit
instances from transpiler passes that need it, such as theBasisTranslator
.
This shouldn't be too hard to implement and would be of great help to all of the developers currently working on transpiler passes.
Discussion
Feel free to start an educated discussion in the comments, I'd love to hear what the rest of the team thinks about this.
### Tasks
- [ ] https://github.com/Qiskit/qiskit/pull/13127
- [ ] https://github.com/Qiskit/qiskit/pull/13143