Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

measure_all assigns surplus classical resources #1806

Open
2 tasks done
glanzz opened this issue Oct 11, 2024 · 0 comments
Open
2 tasks done

measure_all assigns surplus classical resources #1806

glanzz opened this issue Oct 11, 2024 · 0 comments
Labels
bug 🐛 An issue that needs fixing.

Comments

@glanzz
Copy link

glanzz commented Oct 11, 2024

Pre-Report Checklist

  • I am running the latest versions of pyQuil and the Forest SDK
  • I checked to make sure that this bug has not already been reported

Issue Description

program.measure_all() defines classical bits more than required based on the highest qubit index value in the circuit. Instead it should use max(qubitindex) - min(qubitindex) + 1 (Suggestion).

The following circuit has only one gate on one qubit but is assigned 6555 classical bits.

from pyquil import get_qc, Program

p = Program('X 65555')

p.measure_all()

print(p)

qc = get_qc("9q-square-qvm")
result = qc.run(p.wrap_in_numshots_loop(1000))
result.readout_data.get("ro")
print(result)

The bug is also a potential security issue where it could crash the quantum device / simulator. For example the same circuit with any arbitrary integer for the qubit index.

I was able to crash the QVM by running the following circuit in parallel which resulted in following state:
from pyquil import get_qc, Program

p = Program('X 65537')

p.measure_all()

qc = get_qc("9q-square-qvm")
result = qc.run(p.wrap_in_numshots_loop(1000))
result.readout_data.get("ro")
print(result)
<135>1 2024-10-11T02:30:39Z lux.local qvm 12260 - - [127.0.0.1 Session:26] Got "multishot" request from API key/User ID: NIL / NIL
<135>1 2024-10-11T02:30:39Z lux.local qvm 12260 - - [127.0.0.1 Session:26] Mapping qubits: 65537 -> 0
<135>1 2024-10-11T02:30:39Z lux.local qvm 12260 - - [127.0.0.1 Session:26] Making qvm of 1 qubit
<135>1 2024-10-11T02:30:39Z lux.local qvm 12260 - - [127.0.0.1 Session:26] Running experiment with 1000 trials on PURE-STATE-QVM
<135>1 2024-10-11T02:30:42Z lux.local qvm 12260 - - [127.0.0.1 Session:27] Got "version" request from API key/User ID: NIL / NIL
<134>1 2024-10-11T02:30:42Z lux.local qvm 12260 - - 127.0.0.1 - [2024-10-10 22:30:42] "POST / HTTP/1.1" 200 16 "-" "-"

<135>1 2024-10-11T02:30:42Z lux.local qvm 12260 - - [127.0.0.1 Session:28] Got "multishot" request from API key/User ID: NIL / NIL
<135>1 2024-10-11T02:30:42Z lux.local qvm 12260 - - [127.0.0.1 Session:28] Mapping qubits: 65537 -> 0
<135>1 2024-10-11T02:30:42Z lux.local qvm 12260 - - [127.0.0.1 Session:28] Making qvm of 1 qubit
<135>1 2024-10-11T02:30:42Z lux.local qvm 12260 - - [127.0.0.1 Session:28] Running experiment with 1000 trials on PURE-STATE-QVM
assertion failed: state update should occur from waiters' queue
(ThreadContextRegisterState.cpp:992 host_fpr_state_from_guest_state)

With qvm stuck in unresponsive state.

Environment Context

Operating System:

Python Version (python -V): 3.11

Quilc Version (quilc --version): 1.23.0

QVM Version (qvm --version): 1.17.1

Latest version of pyquil.

@glanzz glanzz added the bug 🐛 An issue that needs fixing. label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue that needs fixing.
Projects
None yet
Development

No branches or pull requests

1 participant