Required prerequisites
Describe the bug
When a kernel contains an mx measurement after an earlier measurement such as mz, cudaq.sample(...) only reports the measurement outcomes collected after the mx instruction instead of returning the full bitstring for all measurements in the kernel.
For example, in a 2-qubit kernel that measures qubit 0 with mz and qubit 1 with mx, the sampled result should contain 2-bit outcomes, but instead only a 1-bit outcome is returned.
Steps to reproduce the bug
Python example:
import cudaq
@cudaq.kernel
def kernel_mx():
qubits = cudaq.qvector(2)
x(qubits[0])
h(qubits[1])
mz(qubits[0])
mx(qubits[1])
result = cudaq.sample(kernel_mx, shots_count=10)
print(result)
Observed output:
Expected output shape:
or, more generally, a 2-bit result that includes both the mz outcome for qubit 0 and the mx outcome for qubit 1.
C++ example:
#include <cudaq.h>
__qpu__ void kernel() {
cudaq::qvector qubits(2);
x(qubits[0]);
h(qubits[1]);
mz(qubits[0]);
mx(qubits[1]);
}
int main() {
auto result = cudaq::sample(kernel);
result.dump();
}
This appears to reproduce in C++ as well.
Expected behavior
cudaq.sample(...) should return bitstrings that include all measurement outcomes performed in the kernel, regardless of whether those measurements are in the Z basis, X basis, or mixed bases.
For the reproducer above, the result should include both measured bits, not just the measurements that occur after the mx instruction.
Is this a regression? If it is, put the last known working version (or commit) here.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q version: 0.14.0
- Python version: 3.12.3
- C++ compiler: g++ 13.3.0
- Operating system: ubuntu (wsl)
Suggestions
This looks like sampled measurement aggregation may be dropping previously recorded measurement results once an mx instruction is encountered, or only collecting results from a later measurement register/path. It would be worth checking how mixed-basis measurement results are appended into the final sampled bitstring.
Required prerequisites
Describe the bug
When a kernel contains an mx measurement after an earlier measurement such as mz, cudaq.sample(...) only reports the measurement outcomes collected after the mx instruction instead of returning the full bitstring for all measurements in the kernel.
For example, in a 2-qubit kernel that measures qubit 0 with mz and qubit 1 with mx, the sampled result should contain 2-bit outcomes, but instead only a 1-bit outcome is returned.
Steps to reproduce the bug
Python example:
Observed output:
Expected output shape:
or, more generally, a 2-bit result that includes both the mz outcome for qubit 0 and the mx outcome for qubit 1.
C++ example:
This appears to reproduce in C++ as well.
Expected behavior
cudaq.sample(...) should return bitstrings that include all measurement outcomes performed in the kernel, regardless of whether those measurements are in the Z basis, X basis, or mixed bases.
For the reproducer above, the result should include both measured bits, not just the measurements that occur after the mx instruction.
Is this a regression? If it is, put the last known working version (or commit) here.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
This looks like sampled measurement aggregation may be dropping previously recorded measurement results once an mx instruction is encountered, or only collecting results from a later measurement register/path. It would be worth checking how mixed-basis measurement results are appended into the final sampled bitstring.