Skip to content

Commit

Permalink
Use rust gates for Optimize1QGatesDecomposition (#12650)
Browse files Browse the repository at this point in the history
* Use rust gates for Optimize1QGatesDecomposition

This commit moves to using rust gates for the Optimize1QGatesDecomposition
transpiler pass. It takes in a sequence of runs (which are a list of
DAGOpNodes) from the python side of the transpiler pass which are
generated from DAGCircuit.collect_1q_runs() (which in the future should
be moved to rust after #12550 merges). The rust portion of the pass now
iterates over each run, performs the matrix multiplication to compute the
unitary of the run, then synthesizes that unitary, computes the
estimated error of the circuit synthesis and returns a tuple of the
circuit sequence in terms of rust StandardGate enums. The python portion
of the code then takes those sequences and does inplace substitution of
each run with the sequence returned from rust.

Once #12550 merges we should be able to move the input collect_1q_runs()
call and perform the output node substitions in rust making the full
pass execute in the rust domain without any python interaction.

Additionally, the OneQubitEulerDecomposer class is updated to use
rust for circuit generation instead of doing this python side. The
internal changes done to use rust gates in the transpiler pass meant we
were half way to this already by emitting rust StandardGates instead of
python gate objects. The dag handling is still done in Python however
until #12550 merges.

This also includes an implementation of the r gate, I temporarily added
this to unblock this effort as it was the only gate missing needed to
complete this. We can rebase this if a standalone implementation of the
gate merges before this.

* Cache target decompositions for each qubit

Previously this PR was re-computing the target bases to synthesize with
for each run found in the circuit. But in cases where there were
multiple runs repeated on a qubit this was unecessary work. Prior to
moving this code to rust there was already caching code to make this
optimization, but the rust path short circuited around this. This commit
fixes this so we're caching the target bases for each qubit and only
computing it once.

* Optimize rust implementation slightly

* Avoid extra allocations by inlining matrix multiplication

* Remove unnecessary comment

* Remove stray code block

* Add import path for rust gate

* Use rust gate in circuit constructor

* Remove duplicated op_name getter and just use existing name getter

* Apply suggestions from code review

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Simplify construction of target_basis_vec

* Fix rebase issue

* Update crates/accelerate/src/euler_one_qubit_decomposer.rs

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Update crates/accelerate/src/euler_one_qubit_decomposer.rs

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
  • Loading branch information
mtreinish and jlapeyre authored Jul 3, 2024
1 parent 3fb1753 commit bfc69a4
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 157 deletions.
Loading

0 comments on commit bfc69a4

Please sign in to comment.