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

Compilation error on nested for-loop in OpenQASM 3 #240

Open
JunyiLiu1994 opened this issue Nov 9, 2021 · 0 comments
Open

Compilation error on nested for-loop in OpenQASM 3 #240

JunyiLiu1994 opened this issue Nov 9, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@JunyiLiu1994
Copy link

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.
@1tnguyen 1tnguyen added the bug Something isn't working label Nov 9, 2021
1tnguyen referenced this issue in 1tnguyen/qcor Nov 9, 2021
The unnecessary casting ops between integer and index types cause the Affine for validation failed. This only occurs when the constant values are created inside another affine scope.

Fixing the const index value builder to create the index const directly and the loop statement handler in the range-based case to create index type.

Added the test case (https://github.com/ORNL-QCI/qcor/issues/240)

Signed-off-by: Thien Nguyen <nguyentm@ornl.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants