dwavesystems / dwave-gate

dwave-gate is a software package for constructing, modifying and running quantum circuits on the provided state-vector simulator.
Apache License 2.0
15 stars 8 forks source link

Simulator accuracy #48

Open ACE07-Sev opened 9 months ago

ACE07-Sev commented 9 months ago

Greetings dear D-Wave team,

Hope you are well. So, I am having a bit of an issue with the simulator. It doesn't represent the small values like 0.002 amplitudes, which basically when used with algorithms like FRQI, makes it output a numpy array of all 0s. Anything I can do to fix this?

Here's what I get with Cirq for instance :

[0.125      0.125      0.125      0.125      0.125      0.125
 0.125      0.125      0.125      0.125      0.125      0.125
 0.125      0.1221966  0.12381981 0.125      0.125      0.125
 0.125      0.125      0.12480307 0.11370273 0.125      0.125
 0.125      0.125      0.125      0.12498055 0.1087806  0.125
 0.125      0.125      0.125      0.125      0.125      0.11108285
 0.12499628 0.125      0.125      0.125      0.125      0.125
 0.12250098 0.12246352 0.125      0.125      0.125      0.125
 0.125      0.125      0.10999145 0.12485503 0.125      0.125
 0.125      0.125      0.125      0.125      0.125      0.125
 0.125      0.125      0.125      0.125      0.         0.
 0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.0263247
 0.01713632 0.         0.         0.         0.         0.
 0.0070138  0.05192965 0.         0.         0.         0.
 0.         0.00220521 0.06157745 0.         0.         0.
 0.         0.         0.         0.05732016 0.00096478 0.
 0.         0.         0.         0.         0.02486988 0.02505364
 0.         0.         0.         0.         0.         0.
 0.05938755 0.00601839 0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.         0.        ]

And here's what I get with D-Wave :

[0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
 0.125 0.125 0.125 0.125 0.    0.    0.    0.    0.    0.    0.    0.
 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
 0.    0.    0.    0.    0.    0.    0.    0.   ]

You see the difference? This is causing my code to break as you can imagine. Is there a way I can fix this? Again, this is only in D-Wave, I tried the code with Qiskit, Cirq, TKET, and PennyLane, and they are running as expected, and can extract these smaller values. I'd appreciate the help on fixing this.

I don't think sharing the code would help really, since I am just passing a large circuit. I believe the issue is with the number of digits the simulator can generate for the result (I think it's limited to three digits?). Kindly let me know if you absolutely would need the code, and I will see if I can make a toy example to reproduce this.

thisac commented 9 months ago

Hi @ACE07-Sev. I see there's a difference between the two outputs, although it doesn't seem like the issue is the number of digits using to represent the output, as the precision in dwave-gate is higher than that. If you could post a minimal example of this where the outputs differ between e.g., dwave-gate and Cirq, I could look into what might be going on.

ACE07-Sev commented 9 months ago

Sure, I'll make a notebook. I'll send it here within 48 hours.

ACE07-Sev commented 9 months ago

Greetings!

Hope you are well. Apologies for the delay. Here is the notebook for your kind reference. https://drive.google.com/drive/folders/1rmKPaNygngx8pQVqjKrXTQEm-eegs4wS?usp=sharing

ACE07-Sev commented 9 months ago

So, if you have a look, you'll see the issue I mentioned with the FRQI encoder. I included Shende to show the circuit implementation is correct, and works for that instance. Kindly let me know if you have any questions!

ACE07-Sev commented 8 months ago

Greetings there,

Hope you are well. Any updates?

thisac commented 8 months ago

Thanks @ACE07-Sev. I'd appreciate it if you could either upload the notebook to a GitHub repository and reference it here (so that I can have a look at it directly without having to download it) or just post a minimal example which reproduces this issue directly in this issue.

ACE07-Sev commented 8 months ago

https://github.com/ACE07-Sev/D-Wave-issue-notebook

thisac commented 8 months ago

Thank you for uploading the notebook. I cannot see any issues after a brief look at it, and it's difficult to say if something isn't working as it should. I don't think it's a precision issue since the values that differ from between the two different outputs above don't seem to be rounding errors (but perhaps rather some issue either with the circuit or how it's simulated).

If you have the time to create a minimal example, using as little code as possible, either printing both outputs above for comparison or at least showing a discrepancy between identical circuits using different frameworks, this would be much easier to debug. Also, if you're able to compile the dwave-gate into OpenQASM 2.0 you could try running it using Qiskit and compare the outputs.