Skip to content

Unexpected results in global register for kernels that both mx and mz #2684

@bmhowe23

Description

@bmhowe23

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

Putting both mx and mz in kernels can result in incomplete results in the __global__ register.

Steps to reproduce the bug

Consider the following kernel:

import cudaq

@cudaq.kernel
def kernel():
    qubits_a = cudaq.qvector(2)
    qubit_b = cudaq.qubit()
    mz(qubits_a)
    mx(qubit_b)

counts = cudaq.sample(kernel)
print(counts)

That will produce something like this:

{ 0:490 1:510 }

Expected behavior

The specification/docs say that

if a qubit is measured in the middle of a kernel and subsequent operations change the state of the qubit, the qubit will be implicitly re-measured at the end of the kernel, and that re-measured value is the value that will appear in the global register.

It is unclear if "re-measured" means measured in the same basis as the original measurement or not, but regardless, the example above shows that the measurements for qubits_a can be lost. They should be in the resulting global register.

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

Not a regression

Environment

  • CUDA-Q version: latest (fe1396b at the time of the creation of this issue)
  • Python version: 3.10
  • C++ compiler:
  • Operating system:

Suggestions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions