quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.27k stars 1.01k forks source link

QSimcirq does not implement measurement noise #6305

Open bramathon opened 1 year ago

bramathon commented 1 year ago

When simulating circuits with the qsimcirq simulator, measurement confusion maps are ignored. If this is expected behaviour, I have no been able to find it in the documentation.

How to reproduce the issue

import numpy as np
import cirq
import qsimcirq

print("Cirq: " + cirq.__version__)
print("QSimCirq: " + qsimcirq.__version__)

qubit = cirq.LineQubit(0)

cmap = {(0,): np.array([[0.8, 0.2], [0.2, 0.8]])}

circuit = cirq.Circuit()
circuit += cirq.X(qubit)
circuit += cirq.MeasurementGate(1, confusion_map=cmap)(qubit)

print(circuit)

results = cirq.Simulator(seed=0).run(circuit, repetitions=100)
print("Cirq Simulator: " + str(results))

results = qsimcirq.QSimSimulator(seed=0).run(circuit, repetitions=100)
print("QSim Simulator: " + str(results))

Output:

Cirq: 1.2.0
QSimCirq: 0.16.3
0: ───X───?M('')───
Cirq Simulator: =1111111111111111111111111101111101111111111111011101010111101111110110100011111001111111111101111101
QSim Simulator: =1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

Cirq version

Cirq: 1.2.0 QSimCirq: 0.16.3

pavoljuhas commented 1 year ago

cirq cynque - let us add confusion_map support to QSimSimulator. Contributors welcome. :)

nishitkshah commented 1 year ago

I can take a look. Will sync with Angelo after doing some exploration.

nishitkshah commented 11 months ago

Created a draft version of code change for the fix: https://github.com/quantumlib/qsim/compare/master...nishitkshah:qsim:measurement_noise

Trying to figure out how to write unit tests for this.

nishitkshah commented 10 months ago

Haven't been able to give time to this. Will try to pick it up in the coming week.