Skip to content
Open
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
cf2d1a0
Add pass to find subcircuits with phase polynomials
atgeller Jun 27, 2025
92655f0
Formatting
atgeller Jun 27, 2025
24b846a
Split subcircuits into separate functions
atgeller Jun 30, 2025
b87bd77
Remove debug code
atgeller Jun 30, 2025
1a63aa0
A bit of cleanup on subcircuit logic
atgeller Jul 2, 2025
6e1aa1f
Initial working prototype of phase polynomial calculations and rotati…
atgeller Jul 4, 2025
45d28c9
Make classical values arguments to subcircuit functions to allow non-…
atgeller Jul 4, 2025
21b071e
Some cleanup
atgeller Jul 7, 2025
6f3fc63
Remove incorrectly placed braces
atgeller Jul 7, 2025
3816fa0
Add tests for circuit breaking ops in preprocessing
atgeller Jul 7, 2025
2955445
Don't run phase polynomial based rotation merging opt on illegal circ…
atgeller Jul 7, 2025
9c340b4
Avoid some possible memory leaks
atgeller Jul 8, 2025
4ec517f
Track inversion when combining phases, handle swaps
atgeller Jul 8, 2025
d142f2f
Myriad fixes and improvements to work on phase_estimation example
atgeller Jul 9, 2025
36a9aa9
Formatting
atgeller Jul 9, 2025
5cc6c3c
Various performance fixes
atgeller Jul 10, 2025
04ffa7b
Update tests
atgeller Jul 10, 2025
9fb8768
Update tests
atgeller Jul 10, 2025
7659447
Add opt pipeline and test using CircuitCheck
atgeller Jul 11, 2025
4bd269b
Fix bug in sort function
atgeller Jul 15, 2025
ac81de4
Add preliminary code to detect phase invariant loops
atgeller Jul 15, 2025
a6f57ce
Subcircuit analysis working with memory semantics
atgeller Jul 16, 2025
121b13d
Working implementation of phase folding with memory semantics
atgeller Jul 18, 2025
3d472ac
Build netlist from walking function to ensure order
atgeller Jul 18, 2025
b58a9e4
Update tests
atgeller Jul 18, 2025
59c6ea6
Some minor fixes
atgeller Jul 18, 2025
f786f53
Fail to preprocess subcircuits where there is no legal function call …
atgeller Jul 21, 2025
ea653d9
No need for continues
atgeller Jul 21, 2025
c93a6f4
Fixes to handle swaps and subcircuit rotation arguments properly
atgeller Jul 22, 2025
d0e933d
Do phase folding all in one go instead of separating into functions
atgeller Jul 24, 2025
e980cc6
Fix bug with pruning and add test case
atgeller Jul 24, 2025
a522b1f
Add more documentation/comments and test file
atgeller Jul 24, 2025
cbf2561
Various fixes to avoid illegal values in subcircuits, refactor Netlist.
atgeller Jul 25, 2025
3ac6605
Only allow a control qubit for NOT in subcircuits
atgeller Jul 31, 2025
7ab2818
Add phase folding unittest setup and random test generator from templ…
atgeller Jul 31, 2025
2e9d465
Formatting
atgeller Jul 31, 2025
44da379
Make python script work with default libraries
atgeller Jul 31, 2025
93a4014
More tests, improved generation script
atgeller Aug 1, 2025
d7c140f
Add a test and more comments
atgeller Aug 1, 2025
9318f8e
Improve pass documentation
atgeller Aug 5, 2025
0934dbc
Fix nits
atgeller Aug 6, 2025
51514a8
Merge branch 'main' into phase-folding
atgeller Aug 7, 2025
90c244e
Merge branch 'main' into phase-folding
atgeller Aug 7, 2025
1a6b464
Remove unused code
atgeller Aug 8, 2025
14144c5
Merge branch 'main' into phase-folding
atgeller Aug 13, 2025
cb5d2f6
Merge branch 'main' into phase-folding
bettinaheim Aug 13, 2025
5eca978
Merge branch 'main' into phase-folding
atgeller Aug 13, 2025
81fd7af
Make phase_folding unittests be targettests instead
atgeller Aug 15, 2025
1d18c09
Merge branch 'main' into phase-folding
atgeller Aug 15, 2025
76eed18
Adjust test to ensure optimization is being applied
atgeller Aug 16, 2025
22bf477
Merge
atgeller Aug 16, 2025
4be7d63
Merge branch 'main' into phase-folding
atgeller Aug 16, 2025
e7c9c2e
Add timing setup for phase folding
atgeller Aug 19, 2025
e755d9e
Merge branch 'main' into phase-folding
atgeller Aug 21, 2025
278298b
Fix test
atgeller Aug 22, 2025
de202a2
Merge branch 'main' into phase-folding
atgeller Aug 22, 2025
5d34251
Merge with main
atgeller Aug 25, 2025
d759fa9
Merge branch 'main' into phase-folding
atgeller Aug 25, 2025
164123a
Add a couple of subcircuit metrics
atgeller Aug 26, 2025
d301e53
Add todo
atgeller Aug 26, 2025
d3ced28
Apply suggestions from code review
atgeller Aug 26, 2025
18ab2a2
Address review comments
atgeller Aug 26, 2025
2e915e1
Merge branch 'main' into phase-folding
atgeller Aug 27, 2025
7c98691
Fix order in constructors
atgeller Aug 27, 2025
f4f009e
Tweak passes, run phase folding by default
atgeller Aug 27, 2025
431906e
Add canonicalize/CSE passes back
atgeller Aug 28, 2025
0973af7
Disable outdated test
atgeller Aug 28, 2025
6892df4
Merge branch 'main' into phase-folding
atgeller Aug 28, 2025
c897e02
Fix bug with aliased side-effects not being recognized to break subci…
atgeller Aug 28, 2025
786d39e
Merge
atgeller Aug 28, 2025
72d9c4f
Some cleanup
atgeller Aug 28, 2025
f26cc3b
Update IR test
atgeller Aug 28, 2025
97eb4af
Merge branch 'main' into phase-folding
atgeller Aug 28, 2025
60af1a1
Add test that intermixes valid and invalid refs
atgeller Aug 28, 2025
b9c96dd
Merge
atgeller Aug 28, 2025
19e5a1d
Recombine allocs
atgeller Aug 29, 2025
8cabc61
Merge branch 'main' into phase-folding
atgeller Aug 29, 2025
b60f84e
Merge branch 'main' into phase-folding
atgeller Aug 29, 2025
06ced8f
Some revisions
atgeller Aug 29, 2025
6d6340b
Use processed set instead of attribute
atgeller Aug 29, 2025
7d40312
Generate random tests from CMake instead of running templates
atgeller Aug 29, 2025
1907a1a
Remove old substitution
atgeller Aug 29, 2025
6ff129b
Merge branch 'main' into phase-folding
atgeller Aug 29, 2025
d602b3e
Fix cmake
atgeller Aug 29, 2025
702f36d
Merge
atgeller Aug 29, 2025
f8371f2
Add some more aliasing tests
atgeller Aug 29, 2025
852dc36
Add thresholds for running phase folding optimization
atgeller Aug 29, 2025
7ba38d3
Add timing to JIT construction
atgeller Aug 29, 2025
958f186
Add bypass envvar for optimization thresholds
atgeller Aug 29, 2025
cb16062
Fix test commands
atgeller Aug 29, 2025
5e8539f
moving tests around
bettinaheim Sep 5, 2025
35434fe
enabling select
bettinaheim Sep 16, 2025
cd41404
removing accidental commit
bettinaheim Sep 16, 2025
b6fb394
formatting
bettinaheim Sep 16, 2025
3e2f635
enabling the commented out test (currently failing)
bettinaheim Sep 16, 2025
7cb830c
Merge branch 'conversion' into phase-folding
bettinaheim Sep 16, 2025
3b45c2c
making sure the test is determinstic
bettinaheim Sep 17, 2025
b1e6d63
Merge branch 'main' into phase-folding
bettinaheim Sep 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ docs/sphinx/_mdgen
**/_build/*
_version.py

# Generated files
targettests/generated

# third party integrations
simulators/
apps/
Expand Down
1 change: 1 addition & 0 deletions include/cudaq/Optimizer/InitAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ inline void registerCudaqPassesAndPipelines() {
// CUDA-Q pipelines
opt::registerAggressiveEarlyInliningPipeline();
opt::registerUnrollingPipeline();
opt::registerPhaseFoldingPipeline();
opt::registerClassicalOptimizationPipeline();
opt::registerToExecutionManagerCCPipeline();
opt::registerToQIRAPIPipeline();
Expand Down
1 change: 1 addition & 0 deletions include/cudaq/Optimizer/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void addAggressiveEarlyInlining(mlir::OpPassManager &pm,
bool fatalCheck = false);
void registerAggressiveEarlyInliningPipeline();

void registerPhaseFoldingPipeline();
void registerUnrollingPipeline();
void registerClassicalOptimizationPipeline();
void registerMappingPipeline();
Expand Down
38 changes: 38 additions & 0 deletions include/cudaq/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,44 @@ def ObserveAnsatz : Pass<"observe-ansatz", "mlir::func::FuncOp"> {
];
}

def PhaseFolding: Pass<"phase-folding", "mlir::func::FuncOp"> {
let summary = "Perform phase based rotation merging.";

let description = [{
Multiple `quake.rz` ops can be merged into a single gate if they occur
at the same phase. In a circuit with only Swap, NOT, CNOT, and Rz gates, a
phase represents the state of a qubit based on the Swap, NOT, and CNOT
operations applied to it.

First, a preprocessing step identifies each subcircuit consisting only of
Swap, NOT, CNOT, and Rz gates. Currently, we restrict this subcircuit to
only working with `!quake.ref` types directly from `quake.alloca`s, as
values extraced from `quake.veq`s via `extract_ref` may have hidden side
effects that could cause the subcircuits to be incorrect.

At the beginning of the subcircuit, each qubit is assigned a unique phase
variable. A phase is an exclusive sum of the phase variables determining
the current state of a qubit, calculated as follows. While walking the
subcircuit:
* A Swap gate swaps the phases for two qubits.
* A NOT gate inverts the phase for a qubit by (un)setting a flag.
* A CNOT gate sets the phase of the target to the exclusive sum of the
phase variables in the phases for the control and target qubits.
* If multiple `rz` ops are found at the same phase, they will be combined
by replacing the rotation angle of the latter occuring op to the sum of
the rotation angles of both ops, and removing the prior op.
}];

let options = [
Option<"minimumBlockLength", "min-length", "unsigned", /*default=*/"20",
"Minimumn subcircuit length to run phase folding">,
Option<"minimumrzWeight", "min-rz-weight", "double", /*default=*/"20",
"Minimumn percentage of rz ops in subcircuit to run phase folding">,
];

let dependentDialects = ["cudaq::cc::CCDialect", "quake::QuakeDialect"];
}

def PromoteRefToVeqAlloc : Pass<"promote-qubit-allocation"> {
let summary = "Promote single qubit allocations.";
let description = [{
Expand Down
1 change: 1 addition & 0 deletions lib/Optimizer/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ add_cudaq_library(OptTransforms
DependencyAnalysis.cpp
MultiControlDecomposition.cpp
ObserveAnsatz.cpp
PhaseFolding.cpp
PruneCtrlRelations.cpp
PySynthCallableBlockArgs.cpp
QuakeAddMetadata.cpp
Expand Down
Loading