Unexpected sampling outcome with reset operation
Nobody has claimed this yet.
- 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
Some differences in the results from the cudaq.sample call are observed when the reset operation is involved,
Ex. Single kernel execution for N shots vs. N kernel executions for single shot
Even when the kernel and its arguments are the same. The statistics of the bitstring distributions should be similar.
Steps to reproduce the bug
HOW TO REPRODUCE
The script mimics the dephasing behavior of the 1st qubit (reset is applied to the 2nd qubit in each time step):
import cudaq
import numpy as np
import matplotlib.pyplot as plt
@cudaq.kernel
def dephasing_channel(theta:float, t: int):
q = cudaq.qvector(2)
h(q[0])
for _ in range(t):
ry.ctrl(theta,q[0],q[1])
reset(q[1]) # reset the target qubit
h(q[0])
# measure the ctrl qubit
mz(q[0])
p = 0.1 # dephasing probability
theta = float(2*np.arccos(np.sqrt(1-p))) # transform the dephasing probability to the rotation angle
shots = 2048
steps = 20 # number of time steps
"""# Try 2048 shots"""
prob_0 = [] # list to store the probability of measuring 0
for t in range(steps):
counts = cudaq.sample(dephasing_channel, theta, t, shots_count=shots)
counts = dict(counts.items())
prob_0.append(counts['0']/shots)
fig, ax = plt.subplots(figsize=(4,3), dpi=128)
plt.title("Try 2048 shots")
plt.plot(prob_0)
plt.ylabel("Probability")
plt.xlabel("Time")
plt.ylim(0,1.05)
plt.show()
"""# Try 1 shot 2048 times"""
prob_0 = np.zeros(steps)
for t in range(steps):
for i in range(shots):
counts = cudaq.sample(dephasing_channel, theta, t, shots_count=1)
if '0' in counts:
prob_0[t] += 1
fig, ax = plt.subplots(figsize=(4,3), dpi=128)
plt.title("Try 1 shot 2048 times")
plt.plot(prob_0/shots)
plt.ylabel("Probability")
plt.xlabel("Time")
plt.ylim(0,1.05)
plt.show()
Expected behavior
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA Quantum version: 0.8.0
- Python version: 3.10
Suggestions
Another note, cudaq.draw currently can not visualize the reset even for the simple example:
@cudaq.kernel
def kernel():
q = cudaq.qubit()
x(q)
reset(q)
mz(q)
print(cudaq.draw(kernel))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided Python reproduction with cudaq.sample using 2048 shots versus repeated single-shot executions, then compare the resulting distributions when reset is used. Also run the cudaq.draw example to confirm how reset is rendered. Done means the sampling outcomes are consistent within expected statistical variation and reset is visualized correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- quantum-computing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100