NVIDIA / NVIDIA/cuda-quantum

`get_sequential_data` returns disordered results

Open
#3,377 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

runtime stale-notified
Dominant language
C++
Stars
1.1k
Forks
456
Avg merge
1d 22h
Merged PRs (30d)
165

Description

Required prerequisites
  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!
Describe the bug

When using registers to get multiple measurements from a shot, if one uses get_sequential_data to process the results, the positions of measurement outcomes are not consistent with the shot index. This makes it hard to group different measurements of a single shot together. For example, when one runs

cudaq_counts = cudaq.sample(test_kernel,  shots_count=3)
count_lists = [cudaq_counts.get_sequential_data(f'r_{r}') for r in range(3)]

The ideal results should be

[
[results_for_shot1_r1, results_for_shot2_r1, results_for_shot3_r1],
[results_for_shot1_r2, results_for_shot2_r2, results_for_shot3_r2],
[results_for_shot1_r3, results_for_shot2_r3, results_for_shot3_r3],
]

But instead, one can get

[
[results_for_shot1_r1, results_for_shot2_r1, results_for_shot3_r1],
[results_for_shot1_r2, results_for_shot2_r2, results_for_shot3_r2],
[results_for_shot3_r3, results_for_shot1_r3, results_for_shot2_r3],
]
Steps to reproduce the bug
import cudaq

k = cudaq.make_kernel()
q = k.qalloc(2)
k.h(q)
k.mz(q[0], 'r_0')
k.x(q[0])
k.mz(q, 'r_1')

counts = cudaq.sample(k, shots_count=5)
count_lists = [counts.get_sequential_data(f'r_{r}') for r in range(2)]
print(count_lists)
Expected behavior

The 1st measurement result (r_0) is random on q[0]. Then the 2nd measurement (r_1) should be deterministic on q[0] but random on q[1]. But actually I got

[['1', '1', '0', '0', '0'], ['11', '11', '00', '00', '10']]

The two shots where q[0] measured to be '1' in r_0 should give '0x' in r_1, and the position are mismatched (index 0,1 and index 2,3)

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment
  • CUDA-Q version: amd64-cu12-0.12.0
  • Python version: 3.10.12
  • Operating system: Linux(from the official docker image ghcr.io/nvidia/cudaqx:latest)
Suggestions

No response

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.

Research direction

Reproduce the issue with the provided Python kernel and the get_sequential_data calls. Start by tracing get_sequential_data and compare the returned lists with the shot order shown in the expected behavior. Done means measurements from each register remain aligned by shot index across sequential results.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.