PhilippAumann / circuitq

Toolbox for the simulation and analysis of superconducting circuits.
MIT License
39 stars 9 forks source link

circuitq uses deprecated np.complex #11

Closed caspar-iqm closed 1 year ago

caspar-iqm commented 1 year ago

Hi Philipp!

I noticed CirquitQ breaks with the most recent numpy due to the np.complex attribute being deprecated. From what I understand np.complex128 is available to explicitly specify the datatype.

Relevant part of the traceback:

circuitq\core.py in transform_charge_to_flux(self)
   1207         reversed_subspace_pos = dict(map(reversed, self.subspace_pos.items()))
   1208         length = len(self.estates[:,0])
-> 1209         T = np.ones((length, length), dtype=np.complex)
   1210         for i in range(length):
   1211             for j in range(length):
PhilippAumann commented 1 year ago

Hi Caspar,

thank you for opening this issue. Unfortunately I haven't been able to reproduce this issue with numpy 1.23.5, which is the most recent version available via Anaconda. Could you maybe specify the version of numpy you are using and maybe also provide a minimal working example, so that I can reproduce the issue?

Best, Philipp

caspar-iqm commented 1 year ago

Hi Philipp,

I checked the versions now, indeed this appears only as an error with numpy 1.24 (in particular I tested 1.24.1 and 1.24.2). In numpy 1.23.5 it does trigger a warning, you can test on that version by forcing warnings to be treated as errors:

import warnings
warnings.filterwarnings("error")

I also noticed the full error message has quite clear instructions, np.complex should just be replaced with complex to preserve the same behavior.

AttributeError: module 'numpy' has no attribute 'complex'. np.complex was a deprecated alias for the builtin complex. To avoid this error in existing code, use complex by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.complex128 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

PhilippAumann commented 1 year ago

Hi,

thanks for coming back to this. I have changed np.complex to complex. It should now be resolved with the latest commit. Can you confirm this?

caspar-iqm commented 1 year ago

Hi Philipp,

I tested it now (finally), it works as it should. Thanks!