You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add infrastructure for gates, instruction, and operations in Rust
This commit adds a native representation of Gates, Instruction, and
Operations to rust's circuit module. At a high level this works by
either wrapping the Python object in a rust wrapper struct that tracks
metadata about the operations (name, num_qubits, etc) and then for other
details it calls back to Python to get dynamic details like the
definition, matrix, etc. For standard library gates like Swap, CX, H,
etc this replaces the on circuit representation with a new enum
StandardGate. The enum representation is much more efficient and has a
minimal memory footprint as all the gate properties are defined in code
based on the enum variant (which represents the gate).
The use of an enum to represent standard gates does mean a change in
what we store on a CircuitInstruction. To represent a standard gate
fully we need to store the mutable properties of the existing Gate class
on the circuit instruction as the gate by itself doesn't contain this
detail. That means, the parameters, label, unit, duration, and condition
are added to the rust side of circuit instrucion. However no Python side
access methods are added for these as they're internal only to the rust
code and hopefully in Qiskit 2.0 we'll be able to drop, unit, duration,
and condition from the api leaving only label and parameters.
When an object is added to a CircuitInstruction the operation field is
translated to it's internal representation automatically. For standard
gates this translates it to the enum form, and for Python defined gates
this involves just wrapping them. Then whenever the operation field of
a circuit instruction object is read from python it converts it back to
the normal Python object representation.
This commit does not translate the full standard library of gates as
that would make the pull request huge, instead this adds the basic
infrastructure for having a more efficient standard gate representation
on circuits. There will be follow up pull requests to add the missing
gates and round out support in rust.
The goal of this pull request is primarily to add the infrastructure for
representing the full circuit model (and dag model in the future) in
rust. By itself this is not expected to improve runtime performance (if
anything it will probably hurt performance because of extra type
conversions) but it is intended to enable writing native circuit
manipulations in rust, including transpiler passes without needing
involvement from Python.
TODO:
- [ ] Fix parameter handling on copy (might involve moving parameter
table to rust)
- [ ] Handle global phase in definitions (might mean moving a
QuantumCircuit struct to rust instead of just CircuitData)
- [ ] Add definitions for gates migrated so far
Fixes: Qiskit#12205
0 commit comments