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 dep-analysis pass (a.k.a. features/qubit-mgmt) #2163

Merged
merged 116 commits into from
Sep 13, 2024

Conversation

bmhowe23
Copy link
Collaborator

@bmhowe23 bmhowe23 commented Aug 27, 2024

Description and code from @atgeller. Thanks, Adam!

Description

DependencyAnalysis assigns physical qubits to virtual qubits and reorders the quake code to better reflect the ordering of operations implicit in the quake code, to try to open up additional parallelism. First, it constructs a data structure representing the quake code with explicit operation ordering constraints (in the form of dependency relations between operations) and performs several analyses/optimizations on it to try to reduce the total number of physical qubits used and the overall cycle-length of the circuit.

The first optimization is to lower virtual qubits allocation/deallocation pairs into the inner-most blocks they are used (deleting them in branches where they are not used). This opens up more physical qubit reuse opportunities within inner scopes and gives the other analyses/optimizations more flexibility.

The second optimization is to lift common operations at the beginning/end of the then and else blocks within an if to the parent scope. This optimization can reduce the circuit length. Also, because DependencyAnalysis currently treats ifs as a "solid barrier" that the analyses cannot look inside (for scalability), also gives the parent context more flexibility in reusing qubits, since it has more information available that was previously "hidden" within the if.
The first analysis is scheduling: assigning a cycle to every quantum operation, such that the cycle respects the explicit ordering constraints. That is, an operation must be scheduled at a cycle after each of its dependencies, and any operation that depends on it must be likewise be scheduled after it.

The second analysis calculates lifetimes for virtual qubits. The lifetime of a qubit is from the first cycle in which it is used through the last cycle it is used in.

The third and final analysis assigns physical qubits to virtual allocations, using the lifetime information to find opportunities to assign the same physical qubit to two different virtual qubits. Because this may reduce the number of qubits used, this is also an optimization.

Currently, the second optimization and the three analyses are run together in an inside-out optimization pass. In this pass, inner ifs are first resolved, then the three analyses are run on the block. Parent ifs combine the physical allocations between the then and else blocks, respecting the reuse decisions they make. After the inner physical qubit assignments are combined, common operations are lifted from the inner blocks of the if. There are more opportunities to lift operations from the if at this point, since different virtual qubits may have been assigned the same physical qubit, so more operations will be "common". Finally, now that the inner if is resolved, the pass now runs on the parent block of the if.

After the analyses and optimizations are performed, new quake code is generated based on the resulting data structure.

…ncludes some fixes for bugs revealed by validation.
… cases

* quake.discriminate was incorrectly classified as a quantum op and would add a cycle
* Reusing a wire didn't properly handle the case where the wire wasn't the first result
* DependencyNodes were incorrectly put into the same graphs based on non-quantum-dependent classical values
* Successors were ordered lists, but classical values are not linear types, so successors became sets

Also removes the validate method for DependencyNodes as the remaining check are already asserted elsewhere.
@bmhowe23
Copy link
Collaborator Author

bmhowe23 commented Sep 9, 2024

/ok to test

Command Bot: Processing...

github-actions bot pushed a commit that referenced this pull request Sep 9, 2024
Copy link

github-actions bot commented Sep 9, 2024

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@bmhowe23
Copy link
Collaborator Author

bmhowe23 commented Sep 10, 2024

/ok to test

Command Bot: Processing...

Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 10, 2024
@bmhowe23
Copy link
Collaborator Author

bmhowe23 commented Sep 11, 2024

/ok to test

Command Bot: Processing...

@bmhowe23 bmhowe23 enabled auto-merge (squash) September 11, 2024 15:57
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 11, 2024
@bmhowe23
Copy link
Collaborator Author

bmhowe23 commented Sep 11, 2024

/ok to test

Command Bot: Processing...

Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 11, 2024
@bmhowe23
Copy link
Collaborator Author

bmhowe23 commented Sep 13, 2024

/ok to test

Command Bot: Processing...

Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 13, 2024
@bmhowe23 bmhowe23 merged commit 176f1e7 into NVIDIA:main Sep 13, 2024
129 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2024
@bmhowe23 bmhowe23 deleted the pr-qubit-mgmt branch September 13, 2024 12:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants