Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.11k stars 2.34k forks source link

Potential Bug in Statevector.measure() When Measuring a Subset of Qubits #13043

Closed habtie-phys closed 1 month ago

habtie-phys commented 1 month ago

Environment

What is happening?

Bug Description

I encountered unexpected behavior when using the Statevector.measure() function in Qiskit to measure a subset of qubits in a 3-qubit state vector. Specifically, the new state vector (nw_sv) returned by Qiskit after the measurement does not match the expected collapsed state.

How can we reproduce the issue?

Here is a minimal example to reproduce the issue:

from qiskit.quantum_info import Statevector as sv
import numpy as np

# Initialize a 3-qubit state vector
w = sv([0, 1, 1, 0, 1, 0, 0, 0] / np.sqrt(3))
w.draw("latex")

$$\frac{\sqrt{3}}{3} |001\rangle+\frac{\sqrt{3}}{3} |010\rangle+\frac{\sqrt{3}}{3} |100\rangle$$

# Measure the last two qubits (qubits 1 and 2)
result, nw_sv = w.measure([1, 2])

# Print the result and new state vector
print("Measurement Result:", result)
print("New Statevector:", nw_sv)

Measurement Result: 00 New Statevector:

$$ |001\rangle$$

What should happen?

the expected new state vector, if I am not mistaken, should be

$$ |100\rangle$$

Any suggestions?

No response

jakelishman commented 1 month ago

@habtie-phys: I didn't see the comment you're referring to in your reply, but that's a scam.

For your actual issue, Qiskit numbers bits starting with the least-significant bit at 0 (like in regular place-value for numbers), so "bit 0" is the rightmost one, and in your example, "bit 2" is the leftmost one.

habtie-phys commented 1 month ago

@habtie-phys: I didn't see the comment you're referring to in your reply, but that's a scam.

For your actual issue, Qiskit numbers bits starting with the least-significant bit at 0 (like in regular place-value for numbers), so "bit 0" is the rightmost one, and in your example, "bit 2" is the leftmost one.

Thank you so much! It make sense now