Provide workaround for TwoQubitWeylDecomposition error for large circuits#100
Provide workaround for TwoQubitWeylDecomposition error for large circuits#100garrison merged 10 commits intoQiskit:mainfrom
Conversation
|
Hi @GeorgePennington, thank you for the report and pull request. I much appreciate that it even includes a test case 🙂. Could you please provide some of the explicit matrices that have failed, either here or as a comment to Qiskit/qiskit#4159? Of course, the best place to fix this once and for all would be Qiskit. That said, if transpiling helps, then I think it's reasonable for qiskit-addon-aqc-tensor to transpile in cases where it might help. I opened a new PR, #101, which adjusts this to add logging and to only perform the transpilation after a failure. I don't want to introduce any additional failures with this change, and falling back to transpilation seemed the best way to do it. Also, it means only paying the performance penalty of transpilation when absolutely necessary. |
|
Thanks @garrison! An example matrix which failed is: This matrix has a maximum element-wise difference from the transpiled one (which doesn't throw the error) of only 8.7e-14, but it seems that this is enough to cause the error. I like your change of only performing the transpilation if an error is thrown, since it doesn't change the behaviour of any cases which don't fail. On a side note, I've found that rounding the matrix to ~12 decimal places using |
|
|
|
This looks good, the only thing left is it deserves a release note. Do you want to write one, or should I? |
|
I've added a release note for the fix. I wasn't sure if I should put it inside the |
That's not true actually. It can happen for very small circuits as well. I have had it for 3 qubit circuits. It's the floating point error that causes |
Rounding is objectively the worst way to go. The whole issue arises from floating point errors. Adding rounding may be harmless for small circuits, but as you scale it up at best it'll lead to considerable loss in fidelity, and at worst will just produce wrong results due to That's why it works without modification in Ubuntu and not in Windows or Mac Os. Please read the messages I sent in the qiskit issue thread. I have explained exactly where the issue arises from, and others have claimed Ubuntu doesn't cause errors for them whereas Windows and Mac does. This cannot and should not be fixed by rounding off. alexanderivirii said this as well. Transpilation is not gonna be a sustainable solution either (it likely works because it uses the unitary definition to define equivalent gates) for larger circuits. |
|
Best way to tackle this is via qiskit, and via deterministic approach by Jake Lishman. The current approach which was previously ported to rust in I believe 0.49 is using a randomized approach which falls victim to this issue same as Jake's approach, but at least Jake's is deterministic and more efficient. |
Yeah, that's correct. Typically the notes get moved to the release folder at the time of a release. |
To be clear, in every case of this current code, the transpilation will occur on a two-qubit circuit, and only when the KAK decomposition has already failed on that circuit. I am a bit concerned that the effect of the transpilation is really just to introduce some rounding in an indirect way. However, the nature of this addon is such that isolated rotations could be wrong during ansatz generation, and everything is fine as long as the variational optimizer can find a better solution. So if this helps more users be enabled by aqc-tensor, then I think it is a fine workaround until the Qiskit bug is fixed. I do wonder if the warning might be more visible if using |
Pull Request Test Coverage Report for Build 18100702563Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
…uits (#100) * add transpilation of couple_qc * unit test * rename * Update to transpile onlyu if a QiskitError has been thrown * add release note for TwoQubitWeylDecomposition fix * Show warning by default * Tweak the release note * Update warning message to clarify that it is not an error * Update qiskit_addon_aqc_tensor/ansatz_generation/from_connectivity.py --------- Co-authored-by: Jim Garrison <garrison@ibm.com> Co-authored-by: Jim Garrison <jim@garrison.cc> (cherry picked from commit e926eed)
…uits (backport #100) (#125) * Provide workaround for TwoQubitWeylDecomposition error for large circuits (#100) * add transpilation of couple_qc * unit test * rename * Update to transpile onlyu if a QiskitError has been thrown * add release note for TwoQubitWeylDecomposition fix * Show warning by default * Tweak the release note * Update warning message to clarify that it is not an error * Update qiskit_addon_aqc_tensor/ansatz_generation/from_connectivity.py --------- Co-authored-by: Jim Garrison <garrison@ibm.com> Co-authored-by: Jim Garrison <jim@garrison.cc> (cherry picked from commit e926eed) * Update test_development_versions.yml --------- Co-authored-by: GeorgePennington <156084027+GeorgePennington@users.noreply.github.com> Co-authored-by: Jim Garrison <garrison@ibm.com> Co-authored-by: Jim Garrison <jim@garrison.cc>
Hi!
When using the
generate_ansatz_from_circuitfunction with a large circuit, I've encountered an error with Qiskit'sTwoQubitWeylDecomposition. See the below error message.This originates from the lines:
in
from_connectivity.py(304-305). You can recreate the error using:Many of the calls to
TwoQubitWeylDecompositionoccur without error, but for large circuits, there comes a point where one of the matrices fails to diagonalise. Interestingly, this is reproducible behaviour, and always occurs at the same point for a given circuit.This error has been mentioned in quite a few issues on GitHub/StackExchange (Qiskit/qiskit#4159, Qiskit/qiskit#14233, Qiskit/qiskit#7120, https://quantumcomputing.stackexchange.com/questions/41866/twoqubitweyldecomposition-failed-to-diagonalize-m2). I believe it usually arises when the matrix being decomposed is not unitary, however in all the cases I tested, the matrix was unitary to numerical precision (and returned
Operator(couple_qc).is_unitary() = True. It seems others have had this issue as well.I found a work-around by transpiling
couple_qcbefore passing it toTwoQubitWeylDecomposition. From playing around, it looks like the matrices produced byOperator(couple_qc).dataare identical to numerical precision before and after this transpilation, however one causes an error, and the other doesn't. I'm not sure exactly why this is the case, or if it works all the time, but it seems to work for the cases I looked into.