NVIDIA / NVIDIA/cuda-quantum

Noisy simulation on tensornet-mps backend is not deterministic when manually setting random seed

Open
#2,961 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement simulation 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 repeatedly doing a noisy simulation using the tensornet-mps backend on the same quantum circuit C with the same random seed r, the sampling results are different. This shows that setting a random seed does not guarantee that the simulation is deterministic and reproducable.

Steps to reproduce the bug

In order to reproduce the bug you just need to create a simple kernel that applies x gate on a qubit. Add a DepolarizationChannel to the x gate on said qubit, set a random seed and sample the kernel. You will observe that consecutive runs of this program will give different results/histograms. I have attached a sample program to reproduce this issue. I used a for loop in my example, but same issue occurs when you just sample once and rerun the python file.

import cudaq

cudaq.set_target("tensornet-mps")


@cudaq.kernel
def my_kernel():
    qubits = cudaq.qvector(1)
    x(qubits[0])
    mz(qubits)


noise_model = cudaq.NoiseModel()
noise_model.add_channel("x", [0], cudaq.DepolarizationChannel(0.1))

for i in range(5):
    cudaq.set_random_seed(42)
    result = cudaq.sample(my_kernel, shots_count=1000, noise_model=noise_model)
    print(result)
Expected behavior

Expected behaviour would be that we get the same sampling result 5 times. Instead, we get this:

{ 0:56 1:944 }
{ 0:72 1:928 }
{ 0:57 1:943 }
{ 0:67 1:933 }
{ 0:59 1:941 }
Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment
  • CUDA-Q version: 0.11.0
  • Python version: 3.12.9
  • C++ compiler: -
  • Operating system: Ubuntu 22.04.5 LTS on WSL
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

Start with the reproducible Python entry points: cudaq.set_target("tensornet-mps"), cudaq.set_random_seed, and cudaq.sample using the provided noisy kernel. Run the five-iteration example and compare the histograms across repeated executions. Done means repeated sampling with the same seed produces the same results on the tensornet-mps backend, with coverage for the reproduced case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
quantum-computing, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.