Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Sampling on wavefunction simulator #1788

Open
2 tasks done
glanzz opened this issue Jul 8, 2024 · 0 comments
Open
2 tasks done

Error in Sampling on wavefunction simulator #1788

glanzz opened this issue Jul 8, 2024 · 0 comments
Labels
bug 🐛 An issue that needs fixing.

Comments

@glanzz
Copy link

glanzz commented Jul 8, 2024

Pre-Report Checklist

  • I am running the latest versions of pyQuil and the Forest SDK
  • I checked to make sure that this bug has not already been reported

Issue Description

The sample_bitstrings(n) of the wave function is not working as expected. Even when tried sampling with 100 samples as well as the 1000 samples the wave function provides the same state bitstrings.
I was building a testing framework and found these issue when i had to compare results between different compilers.

How to Reproduce

Code Snippet

from pyquil import Program
from pyquil.api import get_qc
from pyquil.api import WavefunctionSimulator

def result_dict(resarray):
    # Function to provide result array as counts dictionary
    res_dict = {}
    for val in resarray:
      key = "".join([str(v) for v in val])
      res_dict[key] = res_dict.get(key, 0) + 1
    return res_dict

qc = get_qc("9q-square-qvm")
wf_sim = WavefunctionSimulator()

prog = Program('''DECLARE ro BIT[2]
H 0
MEASURE 1 ro[1]
MEASURE 0 ro[0]
''') # Simple program with H gate

result = qc.run(qc.compile(prog).wrap_in_numshots_loop(1000))
print(result_dict(result.readout_data.get("ro")))

print(result_dict(wf_sim.wavefunction(prog).sample_bitstrings(1000))) # Gives only one state
print(result_dict(wf_sim.run_and_measure(prog, trials=1000))) # Gives only one state

Error Output

{'00': 501, '10': 499}
{'00': 1000}
{'00': 1000}

If i manually run the loop and measure 100 times it works but the number of requests hitting the QVM slows it down. This was my temporary fix which i am working with.

results = []
for i in range(100):
  results.append(wf_sim.run_and_measure(prog, qubits=sorted(get_measured_qubits(prog)))[0])
print(result_dict(results))

Environment Context

Operating System:

Python Version (python -V): 3.11.9

Quilc Version (quilc --version): 1.23.0

QVM Version (qvm --version): 1.17.1

@glanzz glanzz added the bug 🐛 An issue that needs fixing. label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue that needs fixing.
Projects
None yet
Development

No branches or pull requests

1 participant