softwareQinc / staq

Full-stack quantum processing toolkit
https://iopscience.iop.org/article/10.1088/2058-9565/ab9359/pdf
MIT License
154 stars 28 forks source link

The final states of the output from staq mismatch those of the input #43

Closed DevelopDaily closed 2 years ago

DevelopDaily commented 2 years ago

I just notice your update on the #34 and thank you for the effort.

But, it still does not produce the correct results.

I attach an input.qasm and you can do this to produce two output files.

./staq -S -O2 -o out2.qasm input.qasm
./staq -S -O3 -o out3.qasm input.qasm

Then, you can run each of the input.qasm, out2.qasm, out3.qasm with qppexample program qpp_qasm.

The final states from executing the three files are different from each other. The phases are different.

I tried both qppand staqwithout USE_QISKIT_SPECS. The problem exists.

Then, I tried both qppand staqwith USE_QISKIT_SPECS. The problem still exists.

input.zip

vsoftco commented 2 years ago

@DevelopDaily Thanks! Will take a look and fix asap. btw, do you have any "minimal" (shorter) example that reproduces the issue?

DevelopDaily commented 2 years ago

Here is the minimal version:

OPENQASM 2.0;
include "qelib1.inc";
gate ccc ctrl, ctrl_1, ctrl_2, q0, q1, q2
{
    crz(((pi/2)/2)+(pi/2)) ctrl, q0;
}

qreg q[3];
qreg ctrl_0[1];
qreg ctrl_1[1];
qreg ctrl_2[1];

x ctrl_0[0];

ccc ctrl_0[0], ctrl_1[0], ctrl_2[0], q[0], q[1], q[2];
525125 commented 2 years ago

This should be fixed as of https://github.com/softwareQinc/staq/commit/c56c95890e16eb85e18bff6356f4476101732c9a and https://github.com/softwareQinc/qpp/commit/470e38628facfb572605ddb7ea1ddec4e5e7fb00, both with and without USE_QISKIT_SPECS.

The issue was a difference between qelib1.inc's crz definition and the corresponding matrix in qpp's lookup table.

525125 commented 2 years ago

FYI: We've now changed the option to USE_OPENQASM2_SPECS, and it is OFF by default.

DevelopDaily commented 2 years ago

Great. Thanks. Working like a charm now.

May I suggest you review these two sample qelib1.inc files too? Are they consistent with what you fixed today? Sometimes, people may want to add more gates to the files to do testing or something. If they reference them, they may get confused.

https://github.com/softwareQinc/qpp/blob/main/qasmtools/qasm/generic/qelib1.inc https://github.com/softwareQinc/staq/blob/main/qasmtools/qasm/generic/qelib1.inc

525125 commented 2 years ago

We have two versions of qelib1.inc (see https://github.com/softwareQinc/staq/blob/main/qasmtools/include/qasmtools/parser/preprocessor.hpp).

One is for USE_OPENQASM2_SPECS=ON, which is the same as the official OpenQASM 2 standard library, and is the same as the two linked files. The other is for USE_OPENQASM2_SPECS=OFF, which is the one that was changed.