-
Notifications
You must be signed in to change notification settings - Fork 163
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
simulate_expectation_values issue with qsimcirq simulator when the initial_state is a vector #568
Comments
I reinstall cirq and qsimcirq and now it is working fine. |
Running It many times, it randomly switchs between the correct answer and nan+nanj |
Hi @Hosseinberg, I'm unable to reproduce this locally with Sample script to print versions: import cirq, qsimcirq
print("cirq version:", cirq.__version__)
print("qsimcirq version:", qsimcirq.__version__) # May fail on particularly old versions of qsimcirq |
Hi @95-martin-orion , I have the same versions: I'm using WSL2 and I suspect that might be the problem because I tried it on other machines and got the correct result. |
That seems plausible to me. Unfortunately we don't have the resources to put towards solving this specific case, but if you're able to confirm this (or better yet, find a workaround), sharing your notes here would be greatly appreciated. |
I happen to see the issue as well - I have tested in two fresh virtual environments with Python 3.9.13 and Python 3.10.8 running 50 repeats of the sample script. Both environments behaved in a similar way - here are the counts of the unique qsimcirq results with Python 3.9.13:
I am testing with cirq 1.0.0 and qsimcirq 0.14.0 as well. |
Thanks, @pavoljuhas for running the script. Do you also run Python on WSL2? |
I am using a recent Debian Linux running directly on the hardware. Perhaps it works for @95-martin-orion because of a different numpy version? |
My guess is that it is related to the pybind11 and cmake |
@pavoljuhas My previous test was with @Hosseinberg Are you installing the wheels with |
@95-martin-orion I have tried both building from source locally and installing from pip |
Hmm. The only remaining difference between stable and flaky versions seems to be Python version: the Colab I'm running in is on Python 3.8.16. |
I have tried Python 3.10.5 and 3.8.15 |
I have tracked this to the Lines 150 to 161 in 0041775
I have verified For now, you can work around this issue by using
which ensures out-of-bound values exist and are all zero. |
Thanks for tracking this down, @pavoljuhas! Some links to the code involved here:
Notably, the The fact that this isn't working suggests that there may be an error in one of the |
@95-martin-orion and @pavoljuhas import qsimcirq
qsimcirq._load_simd_qsim().__name__ |
I'm getting |
I'm getting |
That's a reasonable lead to start from. @sergeisakov, do you know of any differences between the AVX2 and AVX512 implementations that might cause AVX512 to fail on this while AVX2 succeeds? Specifically, it seems like AVX512 isn't initializing all of the memory it needs for 2-qubit expectation values on a 2-qubit circuit. |
The comment here is misleading: Lines 150 to 152 in 0041775
The second line should be // Impl::MinSize(dest.num_qubits()) elements.
|
I don't think the issue has been resolved. I just compiled it from the source that includes the recent merge and still get |
I can't reproduce that after the recent merge. @Hosseinberg Do you also get |
I am now getting the correct answer with both methods of installation. Not sure why it didn't work the other day. Anyway, I think the issue is resolved and we can close it. Thank you |
Glad to hear it @Hosseinberg! Thanks for your assistance in tracking this issue down. |
I'm seeing some weird results when running the following simple code. I am trying to calculate the expectation value of an observable in three different ways.
It seems that qsimcirq acts strangely when specifying the initial_state as a vector array. There seems to be no problem when the initial state is an integer. Here is the simple code showing the problem
which returns
0: ───H───@───
│
1: ───────X───
(nan+nanj)
(0.9999999403953552+0j)
(0.9999999403953552+0j)
The text was updated successfully, but these errors were encountered: