qir-alliance/qcor

Compilation error on nested for-loop in OpenQASM 3

JunyiLiu1994 opened this issue · 0 comments

A nested for-loop in OpenQASM 3 will cause compilation error of qcor.

Example:

//example.qasm
OPENQASM 3;

qubit q;
bit b;

measure q -> b;
print(b);

for i in [0:2] {
    for j in [0:2] {
        x q;
        measure q -> b;
        print(b);
    }
}

Command:

qcor example.qasm

Error:

[qcor-mlir] Reported Error: see current operation: "affine.for"(%11, %10) ( {
^bb0(%arg1: index):  // no predecessors
  %12 = "std.index_cast"(%arg1) : (index) -> i64
  %13 = "quantum.value_inst"(%1) {name = "x", operand_segment_sizes = dense<[1, 0]> : vector<2xi32>} : (!quantum.Qubit) -> !quantum.Qubit
  %14 = "quantum.inst"(%13) {name = "mz", operand_segment_sizes = dense<[1, 0]> : vector<2xi32>} : (!quantum.Qubit) -> !quantum.Result
  %c0_i64_3 = "std.constant"() {value = 0 : i64} : () -> i64
  %15 = "std.index_cast"(%c0_i64_3) : (i64) -> index
  %16 = "quantum.resultCast"(%14) : (!quantum.Result) -> i1
  "std.store"(%16, %3) : (i1, memref<i1>) -> ()
  "quantum.print"(%3) : (memref<i1>) -> ()
  "affine.yield"() : () -> ()
}) {lower_bound = affine_map<(d0) -> (d0)>, step = 1 : index, upper_bound = affine_map<(d0) -> (d0)>} : (index, index) -> ()
loc("example":7:4): error: 'affine.for' op operand cannot be used as a dimension id
[qcor-mlir-tool] MLIR-to-LLVM_MLIR lowering failed.
[qcor-exec] fatal error.