Skip to content

sv-sim and dm-sim run circuits with classical conditional gates giving wrong shots statistics #12

@nkcxliu2

Description

@nkcxliu2

When there are classically conditioned gates in the middle of the circuits, the shot distribution calculated from either sv-sim or dm-sim shows wrong statistics.

Taking the following teleportation circuit as an example,

OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
creg c1[1];
creg c2[1];
creg c3[1];
sx q[1];
rz(pi/2) q[1];
cx q[1],q[2];
cx q[0],q[1];
rz(pi/2) q[0];
sx q[0];
rz(pi/2) q[0];
measure q[0] -> c1[0];
measure q[1] -> c2[0];
if(c1==1) z q[2];
if(c2==1) x q[2];
measure q[2] -> c3[0];

This is a circuit that prepares a Bell state between qubit q[1] and q[2], while teleporting the state of q[0], which is in the 0 state, to the q[2]. The measurements on qubits q[0] and q[1] should have an equal probability to get either 0 or 1.

Runing noiseless sv-sim with 1024 shots to simulate this qasm code with CPU backend (macOS 14.3), the resulting shots are

===============  Measurement (tests=1024) ================
"0 0 0" : 1024

We expect the outcomes should be equally distributed shots among 000, 010, 100, and 110. The simulation result using ibmq circuit composer is attached.

In order to make this circuit implementable using dm-sim, the conditional z gate is changed to rz(pi), which will add a global phase to the state and not affect the shots. The simulation from dm-sim is

===============  Measurement (tests=1024) ================
"0 0 0" : 955
"0 0 1" : 69

which is also not consistent with the correct result.

ibmq

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions