Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Investigate Possible Numerical Instability in 2q and 3q analytical decompositions

Open NoureldinYosri opened this issue 1 year ago • 5 comments

After adding two_qubit_matrix_to_cz_operations and three_qubit_matrix_to_operations as base cases for quantum_shannon_decomposition, some tests started to become flaky #6765. The tests pass with new versions of numpy and fail with older versions. For now I marked those tests with xfail until we are in state where we run tests with only newer numpy versions. however there might be some numerical instabilities in those methods that we may be able to fix.

NoureldinYosri avatar Oct 15 '24 17:10 NoureldinYosri

Hi, I would like to take this up.

RahilJain1366 avatar Oct 15 '24 18:10 RahilJain1366

@RahilJain1366 thanks for offering to help. I assigned the task to you

NoureldinYosri avatar Oct 15 '24 18:10 NoureldinYosri

Thank you @NoureldinYosri for assigning it me. I wanted to confirm my understanding. I need to replicate the two_qubit_matrix_to_cz_operations and three_qubit_matrix_to_operations on quantum_shannon_decomposition in an older version of numpy? Am I right?

RahilJain1366 avatar Oct 15 '24 19:10 RahilJain1366

this is a start ... see if you can use an old version of numpy to make the tests marked in #6767 fail ... then if you can propose a fix

NoureldinYosri avatar Oct 15 '24 19:10 NoureldinYosri

@NoureldinYosri Could you please assign me to this issue as well?

dv8081 avatar Oct 16 '24 17:10 dv8081

@RahilJain1366 For planning purposes, could you let us know the status of this? Are you still working on this?

mhucka avatar Sep 24 '25 16:09 mhucka

Hi @mhucka

I remember seeing that the fix was provided for the issue as it was completed with [#7390 (https://github.com/quantumlib/Cirq/pull/7390). If not, I will try it out.

RahilJain1366 avatar Sep 26 '25 00:09 RahilJain1366

@RahilJain1366 I think you're right. I just tested it in Python 3.11.9 on Linux by

  • commenting out the xfail annotations in cirq-core/cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py
  • installing NumPy 1.26 instead of 2.x
  • running check/pytest

and it passed.

@NoureldinYosri is it time to remove those two xfail annotations in that file? Or are there additional tests to do (perhaps more specifically about numerical stability)?

mhucka avatar Sep 26 '25 22:09 mhucka

@NoureldinYosri Very gentle ping …

mhucka avatar Oct 21 '25 18:10 mhucka