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

[WIP] Oxidize qubit tracker for HighLevelSynthesis #13180

Closed

Conversation

alexanderivrii
Copy link
Contributor

Summary

In #12911, we have added the QubitTracker class, which tracks the state of qubits for high-level synthesis. When HighLevelSynthesis runs non-trivially (i.e. does not take the "fast path", see #13070), this state tracking requires a large number of ssllllooooww Python set-based manipulations.

As an example, the following code

nq = 1000
qubits = tuple(range(nq))
qt = QubitTracker(qubits, set(qubits), set())
for i in range(nq // 2):
    for j in range(nq // 2):
        qt.used([i, j])

runs in about 3.2 seconds (on my laptop). The current PR almost verbatim reimplements QubitTracker in Rust, with the example above now running in 0.11 seconds (i.e. about 30x faster).

It also adds a few Python tests for QubitTracker.

This does not require release notes since QubitTracker is an internal class and should not be exposed to the users.

This is still work-in-progress because I would like to further revise QubitTracker's API and improve the internal data structures.

@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

@alexanderivrii alexanderivrii added this to the 1.3.0 milestone Sep 18, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10922540254

Details

  • 124 of 161 (77.02%) changed or added relevant lines in 4 files are covered.
  • 14 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.5%) to 88.804%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/qubit_tracker.rs 121 158 76.58%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 92.98%
crates/accelerate/src/two_qubit_decompose.rs 1 91.45%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 10919208944: 0.5%
Covered Lines: 73548
Relevant Lines: 82821

💛 - Coveralls

/// Track qubits by their state
#[pyclass]
pub struct QubitTracker {
qubits: Vec<Qubit>,
Copy link
Member

Choose a reason for hiding this comment

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

I think a simple optimization you can make here is to use num_qubits: u32 instead of a Vec. In rust the Qubit object is just an integer in 0..n so it'll always be contiguous so we don't need to store the entire list and can just store the max index and then either do a comparison if it's in the circuit or an iterator (0..self.num_qubits) depending on how you were using qubits here.

@alexanderivrii
Copy link
Contributor Author

Closed in favor of #13369.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants