softwareQinc / staq

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

Inliner does not inline conditioned gates #76

Closed p51lee closed 7 months ago

p51lee commented 7 months ago

Hello, I'm working with the inliner and it does not inline gates with if conditions.

To reproduce this issue, inline the following bug.qasm:

❯ cat bug.qasm
OPENQASM 2.0;
include "qelib1.inc";
gate cx_o q0,q1 { x q0; cx q0,q1; x q0; }
qreg q[2];
creg c[2];
if (c==1) cx_o q[0], q[1];

cx_o gate is not inlined:

❯ staq --version
staq version 3.5
(c) 2019 - 2024 softwareQ Inc. All rights reserved.
❯ staq_inliner < bug.qasm
OPENQASM 2.0;
include "qelib1.inc";

gate cx_o q0,q1 {
        x q0;
        cx q0,q1;
        x q0;
}
qreg q[2];
creg c[2];
if (c==1) cx_o q[0],q[1];
vsoftco commented 7 months ago

@meamy Any idea?

meamy commented 7 months ago

Hi there!

This is the output I get with the latest commit

OPENQASM 2.0;
include "qelib1.inc";

gate cx_o q0,q1 {
    x q0;
    cx q0,q1;
    x q0;
}
qreg q[2];
creg c[2];
if (c==1) x q[0];
if (c==1) cx q[0],q[1];
if (c==1) x q[0];

which looks like the intended behaviour for this file. Note that we're constrained by the syntax of openQASM 2.0 to have an explicit if statement for each gate in cx_o.

Can you try pulling the latest source from the main branch and try? A little while back we fixed a missing feature which involved some code transformations inside if blocks, due to the issue above where an if block can only contain one command. I imagine what's happening is you have an older version of the inliner from before this was fixed.

p51lee commented 7 months ago

I'll check out the latest commit. Thanks for the support!