softwareQinc / qpp

Modern C++ quantum computing library

Home Page:https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0208073

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conditional measurement problem

DevelopDaily opened this issue · comments

Here is a test case:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
creg c[2];

h q;
measure q[1] -> c[0];
if(c==1) measure q[0] -> c[1];

The if statement does not take effect no matter what the c value is. In other words, the measure q[0] -> c[1]; is executed always.

The Open QASM spec seems vague on whether conditional measurements should be allowed. I can't see why not. The qpp does compile them, but just doesn't execute them correctly.

@meamy Any idea if conditional measurements are implemented in OpenQASM? Thanks!!

Reading the Open QASM spec again, I have found it is actually clear on the if and I quote:

Only quantum operations, i.e. builtin gates, gate (and opaque) subroutines, preparation, and measurement, can be prefaced by if.

Yes, that's exactly right. It's actually explicitly ruled out in the concrete syntax as well.

Do we want to implement if measurement? Do any of you know if it is implemented in the new OpenQASM 3?

It looks like it might be, but I haven't looked too closely at the proposed spec just yet. This doesn't seem particularly high-priority to me, but maybe there's some use cases I'm not aware of.

I tested the case on the online IBM Quantum Experience (based on OPENQASM 2.0; 3.0 unsupported yet) and the Qiskit API directly. The former crashes and the latter works. It seems they haven't figured out how to deal with it or whether they want to have it.

I don't have any strong use cases for or against it.

I have a minor argument for the qpp API clarity. If it does not want to support it, it should throw an exception during compilation. Otherwise, the API user may get some wrong expectations.

Let's keep it open for now and decide later, thanks @meamy !

decided to stuck to OpenQSAM2 for now