-
Notifications
You must be signed in to change notification settings - Fork 127
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
BatchExperiment of QV Experiments with Too Many Trials Produces LinAlgError on Some Devices #846
Comments
Running the QV experiments individually, the error occurs consistently for qubit group [12, 13, 14, 15, 16] but not any other groups in the code above. The error also occurs on other devices for the exact same qubits (Hanoi). |
Can you try to narrow it down to a specific SU(4) that triggers the error? Presumably the randomization occasionally draws a particular SU(4) that fails in |
By changing the seed around, I've been able agle to trigger the error with the following 2 SU(4)s:
and
However, I've seen the first SU(4) above get generated in an experiment with a different seed and the error did not get triggered |
THanks @albertzhu01 when I try to use those SU(4) I don't have any problem. I'm not sure if this is something about my setup vs yours, or if its an issue with the rounding of the array for the printout above. The way I tested was with: qiskit.quantum_info.two_qubit_cnot_decompose.num_basis_gates(np.array([
[-0.02645613-0.07057715j, 0. +0.j , -0.16789715-0.98291886j, 0. +0.j ],
[-0.16789715+0.98291886j, 0. +0.j , 0.02645613-0.07057715j, 0. +0.j ],
[ 0. +0.j , -0.02645613-0.07057715j, 0. +0.j , -0.16789715-0.98291886j],
[ 0. +0.j , -0.16789715+0.98291886j, 0. +0.j , 0.02645613-0.07057715j]]) Can you try it and see if it fails for you? And if not maybe you can dump the failing matrices with enough digits of precision so we can load recreate them bitwise-identical. |
The above works for me (I get
(This has 15 digits of precision) However, if I just run For the second SU(4) in my comment above, I'm able to consistently get the error, but similarly it does not result in an error if I just run
|
Update: The following lines give the error when I run them on my computer, but Helena does not get the error. We both have the same qiskit-terra version, so we're not sure what could be the discrepancy (besides potential differences in the versions of other packages).
|
The above lines do not error for me. I note that all the failing cases are SWAP.(U()*I) which is a high-symmetry corner of the Weyl chamber. The reason for all the complexities of the It would be good to nail down which difference between @albertzhu01 setup and my/Helena's is sufficient to trigger the error. |
You might try something like the following to see how common these failures can be for you for _ in range(100_000):
TwoQubitWeylDecomposition(np.kron(random_unitary(2), random_unitary(2)) @ swap) on my setup I've tested millions of cases and they all pass. The terra testsuite exercises a bunch of the pathological cases. It would be interesting to see if the testsuite passes on your setup. Something like |
The following test case reliably reproduces the error:
Output:
|
@albertzhu01 , regarding your last example, where you call How did you find In the stack trace, where do you see the call to Up = transform_to_magic_basis(U, reverse=True)
# We only need the eigenvalues of `M2 = Up.T @ Up` here, not the full diagonalization.
D = la.eigvals(Up.T @ Up) |
Yes,
And yes, that's where I always see the call to |
It's still not working for me. This is what I see: Just, to be clear, This example also fails on my machine with python and openblas. I reports the same error that you report. I can run your most recent example and get the expected result, 3: import qiskit
import numpy as np
unitary_bad = np.array([[(0.23662360703125174+0.9668410896909799j), 0j, (0.03464874399189194-0.08959375212849645j), 0j],
[(0.03464874399189194+0.08959375212849645j), 0j, (-0.23662360703125174+0.9668410896909799j), 0j],
[0j, (0.23662360703125174+0.9668410896909799j), 0j, (0.03464874399189194-0.08959375212849645j)],
[0j, (0.03464874399189194+0.08959375212849645j), 0j, (-0.23662360703125174+0.9668410896909799j)]])
n_basis_gates = qiskit.quantum_info.two_qubit_cnot_decompose.num_basis_gates(unitary_bad)
print(n_basis_gates) So the call to from scipy import linalg as la
import qiskit
import numpy as np
from qiskit.quantum_info.synthesis.weyl import transform_to_magic_basis
unitary_bad = np.array([[(0.23662360703125174+0.9668410896909799j), 0j, (0.03464874399189194-0.08959375212849645j), 0j],
[(0.03464874399189194+0.08959375212849645j), 0j, (-0.23662360703125174+0.9668410896909799j), 0j],
[0j, (0.23662360703125174+0.9668410896909799j), 0j, (0.03464874399189194-0.08959375212849645j)],
[0j, (0.03464874399189194+0.08959375212849645j), 0j, (-0.23662360703125174+0.9668410896909799j)]])
def prepare_for_eigvals(U):
U = U / la.det(U) ** (0.25)
Up = transform_to_magic_basis(U, reverse=True)
return Up.T @ Up
result = prepare_for_eigvals(unitary_bad)
print(result) But, the result printed is [[-1.60267025e-16+1.00000000e+00j -9.37283027e-18-1.36181701e-17j
2.01085786e-18+1.50590401e-18j 1.11730739e-18-1.02267756e-18j]
[-9.37283027e-18-1.36181701e-17j -1.96188399e-16+1.00000000e+00j
1.39257162e-18+1.70219515e-18j 1.60107009e-19-9.09467378e-19j]
[ 2.01085786e-18+1.50590401e-18j 1.39257162e-18+1.70219515e-18j
-1.57938885e-16+1.00000000e+00j 9.45852359e-18+1.35987928e-17j]
[ 1.11730739e-18-1.02267756e-18j 1.60107009e-19-9.09467378e-19j
9.45852359e-18+1.35987928e-17j -1.94216235e-16+1.00000000e+00j]] Which is different from the bad matrix. In fact array([-1.60267025e-16+1.j, -2.22044605e-16+1.j, -2.22044605e-16+1.j,
-1.94289029e-16+1.j]) So, I'm still unable to get a failing example. We need to find one in order to fix the problem. And we need to put it in the test suite to prevent a regression in the future. EDIT: I wrote "fix the problem". But, it may be more than one problem, as well. |
Informations
What is the current behavior?
If QV experiments with too many trials (example below shows 800 trials run on IBMQ Toronto) are run in a BatchExperiment, the following error occurs:
This varies from device to device.
Steps to reproduce the problem
What is the expected behavior?
A job should be successfully created and run
Suggested solutions
The text was updated successfully, but these errors were encountered: