NVIDIA / NVIDIA/cuQuantum

Qiskit statevector simulator returns wrong result when skipping classical bits.

Open
#142 3 comments 0 reactions 1 assignee View on GitHub

@ymagchi is already working on this.

Since Jun 26, 2024.

Dominant language
Jupyter Notebook
Stars
499
Forks
102
PR merge metrics
No merged PRs in 30d

Description

Hi!

I noticed that when "skipping" a classical bit, meaning not measuring to some bit $x$ but to bit $y$ with $ind(x) < ind(y)$, the cusvaer-enabled statevector simulator returns the wrong result, simply ignoring the result on bit $y$. This does not happen when not enabling cusvaer.

See the example below:

from qiskit.circuit import QuantumCircuit
from qiskit_aer import Aer

sim = Aer.get_backend("aer_simulator_statevector")
sim.set_option("cusvaer_enable", True)

circuit = QuantumCircuit(4, 5)
circuit.h(0)
circuit.cx(range(3), range(1, 4))
circuit.measure([0, 1, 2, 3], [0, 1, 2, 4])

print(circuit)

wrong_result = sim.run(circuit, shots=10000).result().get_counts()
print("Wrong:", wrong_result)

sim.set_option("cusvaer_enable", False)

correct_result = sim.run(circuit, shots=10000).result().get_counts()
print("Correct:", correct_result)
     ┌───┐          ┌─┐              
q_0: ┤ H ├──■───────┤M├──────────────
     └───┘┌─┴─┐     └╥┘     ┌─┐      
q_1: ─────┤ X ├──■───╫──────┤M├──────
          └───┘┌─┴─┐ ║      └╥┘┌─┐   
q_2: ──────────┤ X ├─╫───■───╫─┤M├───
               └───┘ ║ ┌─┴─┐ ║ └╥┘┌─┐
q_3: ────────────────╫─┤ X ├─╫──╫─┤M├
                     ║ └───┘ ║  ║ └╥┘
c: 5/════════════════╩═══════╩══╩══╩═
                     0       1  2  4 
Wrong: {'00000': 4993, '00111': 5007}
Correct: {'10111': 5026, '00000': 4974}

I suspect there might be some missing bookkeeping of the indices of classical registers in the cusvaer backend.

Thanks!
Nate

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.