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

Draft of dependency graph generation algorithm #1848

Closed
wants to merge 40 commits into from

Conversation

atgeller
Copy link
Contributor

Description

This is a draft of an analysis to determine dependency information between qubit operations in a quake program.

Copy link

copy-pr-bot bot commented Jun 24, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Copy link

github-actions bot commented Jun 24, 2024

CLA Assistant Lite bot All Contributors have signed the CLA.

@atgeller
Copy link
Contributor Author

I have read the Contributor License Agreement and I hereby accept the Terms.

Copy link
Collaborator

@schweitzpgi schweitzpgi left a comment

Choose a reason for hiding this comment

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

I'll have to try this out.

lib/Optimizer/Transforms/DependencyAnalysis.cpp Outdated Show resolved Hide resolved
@atgeller
Copy link
Contributor Author

atgeller commented Jul 10, 2024

Can be used like so: cudaq-quake FILE | cudaq-opt --add-dealloc --factor-quantum-alloc --memtoreg --cse --canonicalize --assign-ids --dep-analysis. Use --debug to see lifetime info printed. An example test case can be found in test/Quake/dependency-1.qke.

The additional assign-ids pass is a necessary first step to assign matching unique identifiers to each qubit alloc/dealloc.

The dep-analysis pass builds dependency graphs for straightline code, performs scheduling, determines lifetimes and finds reuse opportunities, and then emits a new program based on the new schedule and reuses.

@schweitzpgi
Copy link
Collaborator

schweitzpgi commented Jul 11, 2024

/ok to test

Command Bot: Processing...

lib/Optimizer/Transforms/AssignIDs.cpp Outdated Show resolved Hide resolved
ConversionTarget target(*ctx);
target.addLegalDialect<quake::QuakeDialect>();
target.addDynamicallyLegalOp<quake::NullWireOp>(
[&](quake::NullWireOp alloc) { return alloc->hasAttr("qid"); });
Copy link
Collaborator

Choose a reason for hiding this comment

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

The attribute approach is brittle as other transformations will not necessarily keep the information. We should really use WireSet, BorrowWire, ReturnWire for explicitly mapping the identity of a qubit from an infinite space (virtual registers) to a finite space (physical registers).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, right now Assign IDs and Dependency Analysis are very tangled passes, so they pretty much have to be run one right after another, and Dependency Analysis has to check that the attributes are present.

@schweitzpgi
Copy link
Collaborator

schweitzpgi commented Jul 18, 2024

/ok to test

Command Bot: Processing...

… 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.
@atgeller
Copy link
Contributor Author

Closing in lieu of #2163

@atgeller atgeller closed this Aug 28, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2024
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.

2 participants