Skip to content

Got different probabilities if not placing measurement at the end #98

Open
@wangzbo

Description

@wangzbo

I am not quite sure if this is an issue, or it's working as design, or a use problem. I'll try to make it clear using an example:

I create a 4-qubit GHZ state circuit and measure all at the end of the circuit(import from openqasm), then call probabilities and measureAllMultishot:

  const circuit = new QuantumCircuit(4);
  circuit.importQASM('OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[4];\ncreg c[4];\nh q[0];\ncx q[0], q[1];\ncx q[1], q[2];\ncx q[2], q[3];\nmeasure q[0] -> c[0];\nmeasure q[1] -> c[1];\nmeasure q[2] -> c[2];\nmeasure q[3] -> c[3];', function(errors: any) {
    console.log(errors);
  }, true);
  circuit.run();
  console.log(circuit.probabilities());
  console.log(circuit.measureAllMultishot(1024));

This is the result and it looks correct:
[0.5, 0.5, 0.5, 0.5]
{1111: 520, 0000: 504}

If change the circuit a little bit, and move some measurements to the front, the circuilt will be something like:

Image

Then I import the circuit and call probabilities and measureAllMultishot:

  const circuit1 = new QuantumCircuit(4);
  circuit1.importQASM('OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[4];\ncreg c[4];\nh q[0];\ncx q[0], q[1];\nmeasure q[0] -> c[0];\ncx q[1], q[2];\nmeasure q[1] -> c[1];\ncx q[2], q[3];\nmeasure q[2] -> c[2];\nmeasure q[3] -> c[3];', function(errors: any) {
    console.log(errors);
  }, true);
  circuit1.run();
  console.log(circuit1.probabilities());
  console.log(circuit1.measureAllMultishot(1024));

I got a different result from above:
[0, 0, 0, 0]
{0000: 1024}

Every run only produce one result.

As a comparison I also had a try with the second circuit using qiskit:

from qiskit import QuantumCircuit
from qiskit_aer.primitives import SamplerV2
qc1 = QuantumCircuit.from_qasm_str('OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[4];\ncreg c[4];\nh q[0];\ncx q[0],q[1];\nmeasure q[0] -> c[0];\ncx q[1],q[2];\nmeasure q[1] -> c[1];\ncx q[2],q[3];\nmeasure q[2] -> c[2];\nmeasure q[3] -> c[3];')
sampler = SamplerV2()
job = sampler.run([qc1], shots=1024)
job_result = job.result()
print(f"counts : {job_result[0].data.c.get_counts()}")

counts : {'0000': 480, '1111': 544}
It returns almost half 0000 and half 1111.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions