Skip to content
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

Add rust representation of the UnitaryGate class #13272

Open
Tracked by #13264
mtreinish opened this issue Oct 3, 2024 · 0 comments
Open
Tracked by #13264

Add rust representation of the UnitaryGate class #13272

mtreinish opened this issue Oct 3, 2024 · 0 comments
Labels
performance Rust This PR or issue is related to Rust code in the repository
Milestone

Comments

@mtreinish
Copy link
Member

The UnitaryGate class is defined in Python and that means that when we need to work with it from Rust (either for transpiler passes or circuit construction) we treat it as a PyInstruction and that requires that we use Python for interacting with it. For the most part for reading this isn't a huge overhead because a UnitaryGate is a gate defined around a unitary matrix as a numpy array and we typically just need to inspect that matrix which can be done by reference without any copying or conversion. However, on writing (typically creation), which we do a fair amount of in the transpiler and the circuit library, the python overhead is significant. In rust it will be easy to build a UnitaryGate struct that implements the Operation trait and owns an Array2<Complex64>. We might need to think a bit about the python interface and split of responsibilities between the languages because we can generate a numpy array from a owned array but the traits in rust-numpy for doing that either consume the array or copy it.

This weakly depends on #12966 as we'll need to figure out the best way to expand PackedOperation to support this and the pattern we establish in #12966 will inform this.

@mtreinish mtreinish added performance Rust This PR or issue is related to Rust code in the repository labels Oct 3, 2024
@mtreinish mtreinish added this to the 2.0.0 milestone Oct 3, 2024
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Oct 4, 2024
In the accelerate crate we currently have two places that are building
`UnitaryGate`, the quantum_volume() function that builds a quantum
volume model circuit and the Split2QUnitaries transpiler pass. Currently
this can only be done by calling Python (until Qiskit#13272 is implemented)
and there was a potential optimization we could make to specify the
number of qubits as an argument to the Python constructor. This skipss
the need for a few python operations to compute the number of qubits
from the size of the matrix. These operations are not exceedingly slow,
but as these Python space constructors are often the bottleneck so it
should help runtime performance of these two functions.
github-merge-queue bot pushed a commit that referenced this issue Oct 7, 2024
In the accelerate crate we currently have two places that are building
`UnitaryGate`, the quantum_volume() function that builds a quantum
volume model circuit and the Split2QUnitaries transpiler pass. Currently
this can only be done by calling Python (until #13272 is implemented)
and there was a potential optimization we could make to specify the
number of qubits as an argument to the Python constructor. This skipss
the need for a few python operations to compute the number of qubits
from the size of the matrix. These operations are not exceedingly slow,
but as these Python space constructors are often the bottleneck so it
should help runtime performance of these two functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

No branches or pull requests

1 participant