-
Notifications
You must be signed in to change notification settings - Fork 184
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
Conversation
…er AST to reflect these reuses
…m into dependency_analysis
…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.
…m into dependency_analysis
Command Bot: Processing... |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Command Bot: Processing... |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Command Bot: Processing... |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Command Bot: Processing... |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Command Bot: Processing... |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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 treatsif
s 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 theif
.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
if
s are first resolved, then the three analyses are run on the block. Parentif
s 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 theif
. There are more opportunities to lift operations from theif
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 innerif
is resolved, the pass now runs on the parent block of theif
.After the analyses and optimizations are performed, new quake code is generated based on the resulting data structure.