Skip to content
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

Numpy 1.24 breaks master. #5967

Closed
tanujkhattar opened this issue Dec 19, 2022 · 7 comments · Fixed by #6149
Closed

Numpy 1.24 breaks master. #5967

tanujkhattar opened this issue Dec 19, 2022 · 7 comments · Fixed by #6149
Labels
area/ci area/dependencies kind/health For CI/testing/release process/refactoring/technical debt items priority: high This is something that should get done soon, e.g. within a month. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@tanujkhattar
Copy link
Collaborator

Description of the issue
Numpy 1.24 was released recently (see release notes) and it breaks master branch.

Using alias for built-in types was deprecated in Numpy 1.20 (See https://numpy.org/doc/stable/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated) and was finally removed in the 1.24 release. As a result, all cirq code that uses aliases for built-in types like np.bool breaks.

Specifically, we'd need to fix the the proper_repr function to use bool instead of np.bool, which would end up changing the repr of a bunch a Cirq classes.

return f'np.array({value.tolist()!r}, dtype=np.{value.dtype})'

Other occurrences of np.bool are in repr and repr_inward files, which can be updated directly to use bool instead of np.bool. Specifically, the following two files:

cirq_google.EngineResult(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), records={'m': np.array([[[True, True, False, True, False]], [[False, True, True, False, False]], [[True, False, True, False, True]]], dtype=np.bool)}, job_id='my_job_id', job_finished_time=datetime.datetime(2022, 4, 1, 8, 23, 45, tzinfo=datetime.timezone.utc))

[cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[True, True, False, True, False], [False, True, True, False, False], [True, False, True, False, True]], dtype=np.bool)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[1, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 1, 0, 1]], dtype=np.uint8)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int8)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int16)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int32)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int64)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint8)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint16)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint32)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint64)}), cirq.ResultDict(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[1, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 1, 0, 1]], dtype=np.uint8), 'n': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int64)})]

Cirq version

1.1.0.dev
@tanujkhattar tanujkhattar added kind/health For CI/testing/release process/refactoring/technical debt items priority: high This is something that should get done soon, e.g. within a month. labels Dec 19, 2022
@tanujkhattar
Copy link
Collaborator Author

Another source of conflict is that numba (a Cirq dependency due to cirq-contrib) supports numpy only upto 1.23; so we are blocked on them before we can upgrade to 1.24. See https://numba.readthedocs.io/en/stable/user/installing.html#compatibility

For now, I will limit numpy version to 1.23 and then we can work on the upgrade once numba adds support for 1.24.

@viathor viathor added triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add area/ci area/dependencies labels Dec 20, 2022
pavoljuhas added a commit to pavoljuhas/Cirq that referenced this issue Mar 14, 2023
Keep numpy version in the isolated Python environment at 1.23
as numpy-1.24 is incompatible with cirq and numba.

Fixes stuck notebook tests which import numba.

Related to quantumlib#5967
pavoljuhas added a commit that referenced this issue Mar 21, 2023
Keep numpy version in the isolated Python environment at 1.23
as numpy-1.24 is incompatible with cirq and numba.

Fixes stuck notebook tests which import numba.

Related to #5967
@mpharrigan
Copy link
Collaborator

can we add a comment to the requirements.txt linking to this issue so it's clear why we're restricting the version

@mpharrigan
Copy link
Collaborator

Is anyone assigned to this high priority issue?

@tanujkhattar
Copy link
Collaborator Author

I think this should be unblocked by #5991 and a new release of numba that now supports numpy 1.24 (https://numba.readthedocs.io/en/stable/user/installing.html#compatibility)

@mpharrigan
Copy link
Collaborator

sweeeet! Regardless of what numba is doing, we can un-pin it in our dependencies, yes?

@tanujkhattar
Copy link
Collaborator Author

I think so, let's find out - #6149

@ChrisPattison
Copy link

Is there a plan to release soon with numpy 1.24 support?

pavoljuhas added a commit to pavoljuhas/Cirq that referenced this issue Jul 6, 2023
- remove numpy version pinning, but require major version 1
- remove warning filters not relevant after numpy-1.24

Follow up to quantumlib#5967
pavoljuhas added a commit that referenced this issue Jul 7, 2023
- remove numpy version pinning, but require major version 1
- remove warning filters not relevant after numpy-1.24

Follow up to #5967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci area/dependencies kind/health For CI/testing/release process/refactoring/technical debt items priority: high This is something that should get done soon, e.g. within a month. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants