Quirk icon indicating copy to clipboard operation
Quirk copied to clipboard

Incorrect simulation result

Open singular-value opened this issue 9 months ago • 1 comments

The chance display at the bottom-right of this circuit looks to be broken.

One way to see this is by noticing that the even-parity bitstrings have probability of 27.3+17.1+26.5+6.5=77.4%, which is inconsistent with the 50% individual-qubit probability.

image

Or alternatively, here is some cirq code to compare against

circuit = cirq.Circuit()
q = cirq.LineQubit.range(15)

circuit += cirq.H.on_each(q[0:3])

for bits in itertools.product([0,1], repeat=3):
    circuit += (cirq.Y(q[3]) ** (0.795 if bits[0] else 0.205)).controlled_by(*q[0:3], control_values=bits)
    circuit += (cirq.Y(q[4]) ** (0.795 if bits[1] else 0.205)).controlled_by(*q[0:3], control_values=bits)
    circuit += (cirq.Y(q[5]) ** (0.795 if bits[2] else 0.205)).controlled_by(*q[0:3], control_values=bits)

for i in range(3, 6):
    circuit += cirq.CX(q[i], q[i+3])

for bits in itertools.product([0,1], repeat=3):
    circuit += (cirq.Y(q[9]) ** (0.795 if bits[0] else 0.205)).controlled_by(*q[3:6], control_values=bits)
    circuit += (cirq.Y(q[10]) ** (0.795 if bits[1] else 0.205)).controlled_by(*q[3:6], control_values=bits)
    circuit += (cirq.Y(q[11]) ** (0.795 if bits[2] else 0.205)).controlled_by(*q[3:6], control_values=bits)

for i in range(9, 12):
    circuit += cirq.CX(q[i], q[i+3])

circuit += cirq.measure(q[6:9] + q[12:15])

result = cirq.Simulator().run(circuit, repetitions=100000)
fig, ax = plt.subplots(figsize=(25, 5))
_ = cirq.plot_state_histogram(result, ax)  # gives a uniform probability distribution over 000...111 

singular-value avatar May 10 '24 19:05 singular-value