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 ExtractCircuitsPass #284

Merged
merged 24 commits into from
Mar 8, 2024
Merged

Conversation

bcdonovan
Copy link
Contributor

This PR adds a new ExtractCircuitsPass. This pass will walk the main function and extract quantum operations into quir.circuits. It is intended to be run after all reordering and merging has been completed. The pass currently requires
--enable-circuits=true in order to have effect.

Circuit formation during QUIRGen has been deprecated. This form of circuit generation is now controlled by the --enable-circuits-from-qasm command line option.

@bcdonovan bcdonovan requested a review from a team as a code owner March 6, 2024 19:50
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@mbhealy
Copy link
Contributor

mbhealy commented Mar 7, 2024

Needs a merge with main. Reviewing now.

Copy link
Contributor

@mbhealy mbhealy left a comment

Choose a reason for hiding this comment

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

Couple minor things, but mostly LGTM. Also please update the copyright year in all the files you touched.

include/Dialect/QUIR/Transforms/ExtractCircuits.h Outdated Show resolved Hide resolved
lib/Dialect/QUIR/Transforms/ExtractCircuits.cpp Outdated Show resolved Hide resolved
lib/Dialect/QUIR/Transforms/ExtractCircuits.cpp Outdated Show resolved Hide resolved
lib/Dialect/QUIR/Transforms/ExtractCircuits.cpp Outdated Show resolved Hide resolved
using namespace mlir;
using namespace mlir::quir;

namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

LLVM style recommends anonymous namespaces only for class definitions and to use static for objects and functions. This localizes the information to where in the file it is useful to quickly understand while reading the code and reduces indentation overall generally (though I know you haven't indented here).

lib/Dialect/QUIR/Transforms/ExtractCircuits.cpp Outdated Show resolved Hide resolved
currentOp = currentOp->getNextNode()->getNextNode();
}

while (currentOp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a few comments in the body of this loop would help in understanding the flow.

Copy link
Contributor Author

@bcdonovan bcdonovan Mar 7, 2024

Choose a reason for hiding this comment

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

Added comments with 41febe7.
Also removed special handling of qcs.DelayCycleOp and verified test case binary output vs without circuits.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@bcdonovan
Copy link
Contributor Author

Copyrights updated with def120c

I have also support for scf.while and expanded the unit test with 95d12e0. @mbhealy Is there any control flow operations we currently support that I have missed?

@bcdonovan bcdonovan requested a review from mbhealy March 7, 2024 20:34
@bcdonovan
Copy link
Contributor Author

@mbhealy This should be ready for your re-review.

mbhealy
mbhealy previously approved these changes Mar 7, 2024
Copy link
Contributor

@mbhealy mbhealy left a comment

Choose a reason for hiding this comment

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

LGTM

reza-j
reza-j previously approved these changes Mar 8, 2024
Copy link
Contributor

@reza-j reza-j left a comment

Choose a reason for hiding this comment

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

Generally LGTM, just a few questions. The arguments for extracting circuits after reordering/merging makes sense and I think this is really nice

// control flow found, no next quantum op
return std::nullopt;
}
if (isa<qcs::ParallelControlFlowOp>(nextOp))
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we need a case here for if/else ops as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we do not as they are covered but the RegionBranchOpInterface

lib/Dialect/QUIR/Transforms/ExtractCircuits.cpp Outdated Show resolved Hide resolved

// if firstQuantumOp is still set then there is an in progress circuit to be
// ended
if (firstQuantumOp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this condition ever true? because line 281 set firstQuantumOp = nullptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right, I removed with d6b699b.

@bcdonovan bcdonovan dismissed stale reviews from reza-j and mbhealy via 5368c63 March 8, 2024 19:43
Copy link
Contributor

@reza-j reza-j left a comment

Choose a reason for hiding this comment

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

LGTM

@bcdonovan bcdonovan merged commit 4c4d55a into openqasm:main Mar 8, 2024
3 checks passed
bcdonovan added a commit to bcdonovan/qe-compiler that referenced this pull request Mar 8, 2024
This PR adds a new ExtractCircuitsPass. This pass will walk the main
function and extract quantum operations into `quir.circuit`s. It is
intended to be run after all reordering and merging has been completed.
The pass currently requires  --enable-circuits=true in order to have effect.

Circuit formation during QUIRGen has been deprecated. This form of
circuit generation is now controlled by the --enable-circuits-from-qasm
command line option.

---------

Co-authored-by: mbhealy <[email protected]>
Co-authored-by: reza-j <[email protected]>
bcdonovan added a commit that referenced this pull request Mar 9, 2024
This PR adds a new ExtractCircuitsPass. This pass will walk the main
function and extract quantum operations into `quir.circuit`s. It is
intended to be run after all reordering and merging has been completed.
The pass currently requires --enable-circuits=true in order to have
effect.

Circuit formation during QUIRGen has been deprecated. This form of
circuit generation is now controlled by the --enable-circuits-from-qasm
command line option.

---------

Co-authored-by: mbhealy <[email protected]>
Co-authored-by: reza-j <[email protected]>
@bcdonovan bcdonovan deleted the bd-add-extract-circuits branch March 13, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants