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

Set num_qubits kwarg when building UnitaryGate from Rust #13282

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

mtreinish
Copy link
Member

Summary

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.

Details and comments

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.
@mtreinish mtreinish added performance Changelog: None Do not include in changelog labels Oct 4, 2024
@mtreinish mtreinish requested a review from a team as a code owner October 4, 2024 20:38
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11186666538

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • 6 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.01%) to 88.885%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/accelerate/src/two_qubit_decompose.rs 1 91.45%
crates/qasm2/src/lex.rs 4 92.23%
Totals Coverage Status
Change from base Build 11181214888: 0.01%
Covered Lines: 74473
Relevant Lines: 83786

💛 - Coveralls

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! One question out of curiosity, did you get to test how much faster the creation is when you give the number of qubits upfront?

@mtreinish
Copy link
Member Author

I did a quick test just now with quantum_volume(), and it's not really measurable outside of the error margin on the benchmarks I've run. Realistically all we're saving here is skipping:

math.log2(matrix.shape[0])

for each unitary which isn't that expensive.

@ElePT ElePT added this pull request to the merge queue Oct 7, 2024
Merged via the queue into Qiskit:main with commit 6abf660 Oct 7, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants