-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SingleQubitOperation
trait and speedup to Optimize1qGatesDecomposition
pass
#14020
base: main
Are you sure you want to change the base?
Conversation
… of optimize_1q_gates_decomposition
One or more of the following people are relevant to this code:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no Rust expert, so it's very possible I'm wrong, but I'm not sure this is how Trait
should be used here. I would expect something like a SingleQubitOperation
would only be implemented for single-qubit gates, but here it is implemented for all standard gates. Typically I expect a trait to allow me to write something like
fn my_special_function_for_1q(gate: impl SingleQubitOperation) {
// now I am certain that ``gate`` is indeed a 1q operation
}
but this is not the case, since any StandardGate
variant fulfills this trait (and just returns a None
matrix).
If I understand correctly, the thing you want to enable is for matrix
to return a slice instead of an owned Array
, right? If that's so, would another solution be to add something like a matrix_view
or matrix_as_slice
to the Operation
interface instead?
Pull Request Test Coverage Report for Build 13909937100Details
💛 - Coveralls |
Thanks @Cryoris. As we have discussed offline, there are indeed several different ways to implement the required functionality, with some decisions to be made about (1) should this be a part of the Operation trait or should this be a part of a different trait, (2) should this new trait be called I don't think we can implement different traits for different variants of the same |
Summary
This PR implements a new trait
SingleQubitOperation
forStandardGate
,PyGate
,UnitaryGate
andPackedOperation
. The trait currently defines a single methodfn get_mat_static_1q(&self, params: &[Param]) -> Option<[[Complex64; 2]; 2]>
which returns a matrix for single-qubit gates (andNone
otherwise). This is analogous to thematrix
method inOperation
except that it's tuned for single-qubit matrices, allowing to represent these as[[Complex64; 2]; 2]
instead ofArray2<Complex64>
.This is used to speed up matrix multiplication inside
optimize_1q_gates_decomposition
, leading to an about 10% performance improvement for theOptimize1qGatesDecomposition
transpiler pass.