Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

RuntimeWarning: invalid value encountered in det

Open mpharrigan opened this issue 1 year ago • 3 comments

This warning gets emitted a lot and is really unhelpful.

  • Track down where this is coming from
  • See if we can change code paths so it doesn't happen

I suspect this may be coming from cirq somewhere?

mpharrigan avatar Apr 18 '24 23:04 mpharrigan

An example:

import qualtran.testing as qlt_testing
from qualtran.bloqs.block_encoding import (
    _black_box_block_bloq,
)
qlt_testing.assert_bloq_example_serializes(_black_box_block_bloq)

mpharrigan avatar May 02 '24 20:05 mpharrigan

This does it too

from qualtran.bloqs.block_encoding import _black_box_block_bloq

bloq = _black_box_block_bloq.make()
bloq.t_complexity()

mpharrigan avatar May 02 '24 20:05 mpharrigan

in dev_tools/bloq_report_card.ipynb these are the bloq examples that raise the det warning

  • pair_potential
  • black_box_block_bloq
  • potential_energy
  • hubbard_time_evolution_by_gqsp
  • approx_cswap_large

mpharrigan avatar May 02 '24 20:05 mpharrigan

Ok, this is an issue with numpy on Mac ARM. You can reproduce it by doing the determinant of any complex matrix, such as:

mat = [[1,0],[0,1]]
mat = np.asarray(mat, dtype="complex128")
np.linalg.det(mat)

I will fix in upstream cirq, but I recommend executing np.seterr(all='ignore') on any affected Macs.

dstrain115 avatar May 13 '24 23:05 dstrain115

See https://github.com/quantumlib/Cirq/pull/6599

dstrain115 avatar May 14 '24 01:05 dstrain115

This will be fixed as soon as cirq version gets upgraded. In the meantime, add np.seterr(all='ignore') if it annoys you.

dstrain115 avatar May 15 '24 17:05 dstrain115