Skip to content
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
9070fdf
add support for if else conversion
Dec 11, 2025
4916ea3
add initial support for scf while conversion
Dec 11, 2025
ff54901
add initial support for scf forOp conversion
Dec 11, 2025
e968570
add docstrings to QuartzToFlux conversion
Dec 12, 2025
27909af
add docstrings to FluxToQuartz conversion
Dec 12, 2025
b2ab37c
fix typo
Dec 12, 2025
0fc6bc4
add support for multiple functions
Dec 12, 2025
7c323c6
add more docstrings
Dec 12, 2025
f62fbcd
fix header
Dec 12, 2025
500431e
fix bug with multiple qubits
Dec 12, 2025
31ee7a1
minor fixes
Dec 12, 2025
183ffa7
fix linter issues
Dec 14, 2025
69269f7
prepare programBuilders
Dec 15, 2025
b38a9ce
add quartzProgramBuilder for scf operations
Dec 16, 2025
738daae
fix typing issue with converted function arguments
Dec 16, 2025
4e3306e
add missing headers
Dec 16, 2025
e58701f
start adding FluxProgramBuilders for scf operations
Dec 16, 2025
b3d10be
Merge remote-tracking branch 'upstream/dialect-implementation' into s…
Dec 16, 2025
92b556e
use region as key for validQubis mapt
Dec 16, 2025
660e191
Merge remote-tracking branch 'upstream/main' into scf-conversion
Dec 18, 2025
4f0a6c7
resolve merge conflicts
Dec 18, 2025
597f838
add qco builder for scfFor operation
Dec 18, 2025
7ad53d3
add qco builders for scf while and if
Dec 18, 2025
614f2f1
add stubs for docstrings
Dec 19, 2025
6ada604
add builders for func operations
Dec 19, 2025
7358d3b
correctly change the induction variable in scf for conversion
Dec 22, 2025
15a8dca
Merge remote-tracking branch 'upstream/main' into scf-conversion
Dec 22, 2025
010892b
add simple conversion tests
Dec 22, 2025
5a42a8d
fixing some tests
Dec 22, 2025
ad9acd2
remove redundant location
Dec 22, 2025
537f19f
add func conversion tests
Dec 22, 2025
bc278b9
add more docstrings
Dec 22, 2025
59edb8e
remove unnecessary print statements
Dec 22, 2025
b1e77ec
fix comments
Dec 22, 2025
abe1eef
fix linter issues
Dec 22, 2025
981c6e0
fix headers
Dec 22, 2025
5333f26
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 3, 2026
a8d71fa
apply codeRabbit feedback
Jan 3, 2026
dce760f
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 7, 2026
67ecea7
small fixes
Jan 10, 2026
7ebca1c
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 10, 2026
338b7ee
simplify body builders
Jan 10, 2026
7fb4191
fix docstrings
Jan 10, 2026
6fed246
change testnames
Jan 10, 2026
30cea55
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 10, 2026
7596d58
address coderabbit suggestions
Jan 10, 2026
b52fa7b
add explanation for nested qubit tracking
Jan 10, 2026
18487bc
fix linter issues
Jan 10, 2026
b4da26f
add checkFinalized() calls
Jan 10, 2026
d45f448
add headers
Jan 10, 2026
dbe805d
add additional assertions and fix builder parameters
Jan 10, 2026
c4a1d35
fix more wrong docstrings
Jan 10, 2026
9866d2a
add additional operation legality checks
Jan 10, 2026
b36f5ab
add insertionGuards in QCBuilders
Jan 10, 2026
e268089
smaller fixes
Jan 12, 2026
ee30cd5
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 12, 2026
4ea6c50
update scf builder signatures
Jan 12, 2026
7c03d28
fix signatures
Jan 12, 2026
7933d3b
simplify the builders
Jan 12, 2026
fb8b255
remove const from typeConverter
Jan 12, 2026
f81ea76
add test for nested operation
Jan 12, 2026
beb6ed6
simplify the building process with std::variant
Jan 12, 2026
65b2cbe
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 13, 2026
5abab32
remove constant builders
Jan 13, 2026
ce52deb
use more idiomatic way to build operations
Jan 13, 2026
551ff31
also change creation in QCO
Jan 13, 2026
fd4671b
fix linter issues
Jan 15, 2026
6334c98
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 15, 2026
5cab58b
make variantToValue generic
Jan 15, 2026
1ecbb48
Merge branch 'refactor-variant-to-value' into scf-conversion
Jan 15, 2026
ae3b6f8
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 17, 2026
7a32e1f
fix docstrings
Jan 17, 2026
f2963b2
reuse existing yield in scf for conversion
Jan 17, 2026
cafd34e
move type creation out of the loop
Jan 17, 2026
372a231
use more idiomatic way of building operations
Jan 17, 2026
470dfa9
update CHANGELOG.md
Jan 17, 2026
fb2e3cc
update conversion test structure
Jan 17, 2026
e6ff89a
fix more docstrings
Jan 17, 2026
8c5612d
use more idiomatic way to buld yieldOp in body
Jan 17, 2026
e1a8512
add missing header
Jan 17, 2026
ab8f74d
add additional asserts
Jan 17, 2026
9145b43
merge loops together
Jan 17, 2026
7ef1f7f
fix conversion direction in docstrings
Jan 17, 2026
3938420
apply codeRabbit feedback
Jan 17, 2026
ba0c481
add support for memref in dialects
Jan 21, 2026
d14aecd
add initial conversion of memref ops
Jan 21, 2026
86429c5
add memref to tensor conversion
Jan 21, 2026
aee2bca
fix multiple tensor inserts
Jan 21, 2026
686ebe3
fix order of values
Jan 22, 2026
aa2a70e
add tensor conversion from QCO to QC
Jan 22, 2026
7950efe
update the docstrings for the new conversions
Jan 22, 2026
b480801
add QC builders for memref
Jan 22, 2026
b320196
add QCO builders for tensor
Jan 22, 2026
ec8936b
fix order of users
Jan 22, 2026
4a70032
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 22, 2026
ca52bf3
add initial test for registers
Jan 23, 2026
6473046
trying to fix nested operations for qc conversion
Jan 23, 2026
9be2e7c
fix nested tensor conversion in QCO
Jan 23, 2026
ffb2313
fix issue with func arguments
Jan 23, 2026
8a411cf
add tests for qc to qco conversion with registers
Jan 23, 2026
fa1a938
add tests for qco conversion with tensor
Jan 23, 2026
a82c3d4
add docstrings to the builders
Jan 23, 2026
ef77113
smaller fixes
Jan 23, 2026
f24a768
only use arguments in the regionMap of func
Jan 23, 2026
2cb2766
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 24, 2026
46851b9
remove print statement
Jan 24, 2026
d6c6b94
apply coderabbit suggestion and fix smaller typos
Jan 24, 2026
d093ee7
fix more linter issues
Jan 24, 2026
aa6a890
refactor type checks
Jan 24, 2026
a6c3424
trying to fix extractOp
Jan 24, 2026
415b399
fix typeConverter
Jan 24, 2026
41e3c58
fix conversion test for scf operations
Jan 24, 2026
2f3731a
fix typo
Jan 24, 2026
b9d3e03
apply coderabbit suggestion for dealloc
Jan 24, 2026
7c4fe40
add failure when canonicalization fails
Jan 24, 2026
e712c98
refactor memref qubit tracking
Jan 24, 2026
6690227
improve extract op conversion
Jan 24, 2026
35a41ec
update comment
Jan 24, 2026
a62b91c
add missing header
Jan 24, 2026
1ad3e77
apply feedback from codereview
Jan 28, 2026
0d00c92
Merge remote-tracking branch 'upstream/main' into scf-conversion
Jan 29, 2026
254edb4
add mssing parameter in docstring
Jan 29, 2026
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
202 changes: 202 additions & 0 deletions mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,208 @@ class QCProgramBuilder final : public OpBuilder {
*/
QCProgramBuilder& dealloc(Value qubit);

//===--------------------------------------------------------------------===//
// SCF operations
//===--------------------------------------------------------------------===//

/**
* @brief Constructs a scf.for operation without iter args
*
* @param lowerbound Lowerbound of the loop
* @param upperbound Upperbound of the loop
* @param step Stepsize of the loop
* @param body Function that builds the body of the for operation
* @return Reference to this builder for method chaining
*
* @par Example:
* ```c++
* builder.scfFor(lb, ub, step, [&](auto& b) { b.x(q0); });
* ```
* ```mlir
* scf.for %iv = %lb to %ub step %step {
* qc.x %q0 : !qc.qubit
* }
* ```
*/
Comment on lines +915 to +933
Copy link
Member

Choose a reason for hiding this comment

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

The repeated application of a gate to the same qubit isn't particularly interesting. Can we extend this example to demonstrate the use of the loop variable? For example to apply a Hadamard gate to all qubits, which is really common in quantum algorithms.

QCProgramBuilder& scfFor(Value lowerbound, Value upperbound, Value step,
const std::function<void(OpBuilder&)>& body);

/**
* @brief Constructs a scf.while operation without return values
*
* @param beforeBody Function that builds the before body of the while
* operation
* @param afterBody Function that builds the after body of the while operation
* @return Reference to this builder for method chaining
*
* @par Example:
* ```c++
* builder.scfWhile([&](auto& b) {
* b.h(q0);
* auto res = b.measure(q0)
* b.condition(res)
* }, [&](auto& b) {
* b.x(q0);
* b.yield()
* });
* ```
* ```mlir
* scf.while : () -> () {
* qc.h %q0 : !qc.qubit
* %res = qc.measure %q0 : !qc.qubit -> i1
* scf.condition(%tres)
* } do {
* qc.x %q0 : !qc.qubit
* scf.yield
* }
Comment on lines +940 to +965
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to show both, a while as well as a doWhile loop here?

* ```
*/
QCProgramBuilder& scfWhile(const std::function<void(OpBuilder&)>& beforeBody,
const std::function<void(OpBuilder&)>& afterBody);

/**
* @brief Constructs a scf.if operation without return values
*
* @param condition Condition for the if operation
* @param thenBody Function that builds the then body of the if
* operation
* @param elseBody Function that builds the else body of the if operation
* @return Reference to this builder for method chaining
*
* @par Example:
* ```c++
* builder.scf.if(condition, [&](auto& b) {
* b.h(q0);
* }, [&](auto& b) {
* b.x(q0);
* });
* ```
* ```mlir
* scf.if %condition {
* qc.h %q0 : !qc.qubit
* } else {
* qc.x %q0 : !qc.qubit
* }
* ```
*/
Comment on lines +980 to +995
Copy link
Member

Choose a reason for hiding this comment

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

Given how it is very common in quantum to only have a then statement but no else, it's probably worth to show this in the example here.

QCProgramBuilder&
scfIf(Value condition, const std::function<void(OpBuilder&)>& thenBody,
const std::function<void(OpBuilder&)>& elseBody = nullptr);

/**
* @brief Constructs a scf.condition operation without any additional Values
*
* @param condition Condition for condition operation
* @return Reference to this builder for method chaining
*
* @par Example:
* ```c++
* builder.condition(condition);
* ```
* ```mlir
* scf.condition(%condition)
* ```
*/
QCProgramBuilder& scfCondition(Value condition);

//===--------------------------------------------------------------------===//
// Func operations
//===--------------------------------------------------------------------===//

/**
* @brief Constructs a func.return operation without return values
*
* @return Reference to this builder for method chaining
*
* @par Example:
* ```c++
* builder.funcReturn();
* ```
* ```mlir
* func.return
* ```
*/
QCProgramBuilder& funcReturn();

/**
* @brief Constructs a func.call operation without return values
*
* @param name Name of the function that is called
* @param operands ValueRange of the used operands
*
* @par Example:
* ```c++
* builder.funcCall("test", {q0});
* ```
* ```mlir
* func.call @test(%q0) : (!qco.qubit) -> ()
* ```
*/
QCProgramBuilder& funcCall(StringRef name, ValueRange operands);

/**
* @brief Constructs a func.func operation with return values
*
* @param name Name of the function that is called
* @param argTypes TypeRange of the arguments
* @param body Body of the function
* @return Reference to this builder for method chaining
*
* @par Example:
* ```c++
* builder.funcFunc("test", argTypes, [&](OpBuilder& b,
* ValueRange args) {
* b.h(args[0]);
* b.funcReturn();
* })
* ```
* ```mlir
* func.func @test(%arg0 : !qco.qubit) {
* qc.h %arg0 : !qc.qubit
* func.return
* }
* ```
*/
QCProgramBuilder&
funcFunc(StringRef name, TypeRange argTypes,
const std::function<void(OpBuilder&, ValueRange)>& body);

//===--------------------------------------------------------------------===//
// Arith operations
//===--------------------------------------------------------------------===//

/**
* @brief Constructs a arith.constant of type Index with a given value
*
* @param index Value of the constant operation
* @return Result of the constant operation
*
* @par Example:
* ```c++
* builder.arithConstantIndex(4);
* ```
* ```mlir
* arith.constant 4 : index
* ```
*/
Value arithConstantIndex(int index);

/**
* @brief Constructs a arith.constant of type i1 with a given bool value
*
* @param b Bool value of the constant operation
* @return Result of the constant operation
*
* @par Example:
* ```c++
* builder.arithConstantBool(true);
* ```
* ```mlir
* arith.constant 1 : i1
* ```
*/
Value arithConstantBool(bool b);

//===--------------------------------------------------------------------===//
// Finalization
//===--------------------------------------------------------------------===//
Expand Down
Loading
Loading