qir-alliance / qcor

C++ compiler for heterogeneous quantum-classical computing built on Clang and XACC
http://docs.aide-qc.org
MIT License
97 stars 39 forks source link

[OpenQASM3] SSA use-def bug with ctrl/pow modified blocks #223

Closed 1tnguyen closed 3 years ago

1tnguyen commented 3 years ago

In the following example:

qubit target;
qubit control;

z target;
ctrl @ z control, target;

The generated MLIR looks like:

    %1 = q.extract(%0, %c0_i64) : !quantum.Qubit
    %2 = q.qalloc(1) { name = control } : !quantum.Array
    %3 = q.extract(%2, %c0_i64) : !quantum.Qubit
    %4 = qvs.z(%1) : !quantum.Qubit
    q.ctrl_region {
    %5 = qvs.z(%4) : !quantum.Qubit
    } (ctrl_bit = %3) // END CTRL

The SSA value %4 accidentally links the two QVS ops leading to wrong gate cancellation.

Related to: https://github.com/ORNL-QCI/qcor/issues/216