Skip to content

Use np.complexfloating for dtypes that should be complex #5488

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

Merged
merged 12 commits into from
Jun 23, 2022

Conversation

dabacon
Copy link
Collaborator

@dabacon dabacon commented Jun 11, 2022

This changes the type signature for dtypes that should only be np.complex64 or np.complex128.

There are also dtypes in qis.states.py but I've not changed these over, as they are often called the dtype of a np.array, and so they will often need to be cast.

This fixes some check/mypy --next errors.

Technically a breaking change in type signature (more restrictive), but we yell when types are not complex.

@dabacon dabacon requested review from a team, vtomole and cduck as code owners June 11, 2022 15:38
@dabacon dabacon requested a review from MichaelBroughton June 11, 2022 15:38
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jun 11, 2022
@dabacon dabacon added the kind/health For CI/testing/release process/refactoring/technical debt items label Jun 11, 2022
@dabacon
Copy link
Collaborator Author

dabacon commented Jun 15, 2022

#3767

Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. much better type info

@@ -170,7 +171,7 @@ def get_result(state: np.ndarray, sample: float):
qubits=cirq.LineQubit.range(4),
prng=mock_prng,
initial_state=np.copy(state),
dtype=state.dtype,
dtype=cast(Type[np.complexfloating], state.dtype),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can change this cast to an assert earlier?

@dabacon dabacon added the BREAKING CHANGE For pull requests that are important to mention in release notes. label Jun 22, 2022
@dabacon dabacon added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 23, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 23, 2022
@CirqBot CirqBot merged commit 3c8b036 into quantumlib:master Jun 23, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jun 23, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…5488)

This changes the type signature for dtypes that should only be `np.complex64` or `np.complex128`.

There are also dtypes in `qis.states.py` but I've not changed these over, as they are often called the `dtype` of a `np.array`, and so they will often need to be cast.

This fixes some `check/mypy --next` errors.

Technically a breaking change in type signature (more restrictive), but we yell when types are not complex.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…5488)

This changes the type signature for dtypes that should only be `np.complex64` or `np.complex128`.

There are also dtypes in `qis.states.py` but I've not changed these over, as they are often called the `dtype` of a `np.array`, and so they will often need to be cast.

This fixes some `check/mypy --next` errors.

Technically a breaking change in type signature (more restrictive), but we yell when types are not complex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE For pull requests that are important to mention in release notes. kind/health For CI/testing/release process/refactoring/technical debt items size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants