Skip to content

Fix some mypy --next numpy typing errors #5581

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 4 commits into from
Jun 23, 2022

Conversation

pavoljuhas
Copy link
Collaborator

  • Fix return value type error for measure_density_matrix()
  • Replace type spec Type[np.number] --> np.typing.DTypeLike

@pavoljuhas pavoljuhas requested review from a team, vtomole and cduck as code owners June 22, 2022 23:10
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jun 22, 2022
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

Nice!

@MichaelBroughton MichaelBroughton self-assigned this Jun 23, 2022
@MichaelBroughton MichaelBroughton 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
Copy link
Collaborator

CirqBot commented Jun 23, 2022

Automerge cancelled: A status check is failing.

@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
@vtomole
Copy link
Collaborator

vtomole commented Jun 23, 2022

Another flake cc @dabacon

E         =================================== FAILURES ===================================
E         _ test_decompose_two_qubit_interaction_into_four_fsim_gates_equivalence[obj113-fsim_gate113] _
E         
E         obj = cirq.ISWAP
E         fsim_gate = cirq.FSimGate(theta=1.511761740437375, phi=0.00019081760422245964)
E         
E             @pytest.mark.parametrize('obj,fsim_gate', itertools.product(UNITARY_OBJS, FEASIBLE_FSIM_GATES))
E             def test_decompose_two_qubit_interaction_into_four_fsim_gates_equivalence(
E                 obj: Any, fsim_gate: cirq.FSimGate
E             ):
E                 qubits = obj.qubits if isinstance(obj, cirq.Operation) else cirq.LineQubit.range(2)
E                 circuit = cirq.decompose_two_qubit_interaction_into_four_fsim_gates(obj, fsim_gate=fsim_gate)
E                 desired_unitary = obj if isinstance(obj, np.ndarray) else cirq.unitary(obj)
E                 for operation in circuit.all_operations():
E                     assert len(operation.qubits) < 2 or operation.gate == fsim_gate
E                 assert len(circuit) <= 4 * 3 + 5
E         >       assert cirq.approx_eq(circuit.unitary(qubit_order=qubits), desired_unitary, atol=2e-4)
E         E       assert False
E         E        +  where False = <function approx_eq at 0x7f859b580c10>(array([[ 9.9999988e-01+5.0663948e-07j,  3.3753872e-07+1.5762454e-07j,  3.5567297e-07-2.1532583e-07j,  5.9372034e-08+5....0e-08j, -3.0437056e-07-2.2733417e-07j,  3.0149198e-07-3.0524998e-07j,  9.9999994e-01-5.6624413e-07j]], dtype=complex64), array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],\n       [0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j],\n       [0.+0.j, 0.+1.j, 0.+0.j, 0.+0.j],\n       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]]), atol=0.0002)
E         E        +    where <function approx_eq at 0x7f859b580c10> = cirq.approx_eq
E         E        +    and   array([[ 9.9999988e-01+5.0663948e-07j,  3.3753872e-07+1.5762454e-07j,  3.5567297e-07-2.1532583e-07j,  5.9372034e-08+5....0e-08j, -3.0437056e-07-2.2733417e-07j,  3.0149198e-07-3.0524998e-07j,  9.9999994e-01-5.6624413e-07j]], dtype=complex64) = <bound method AbstractCircuit.unitary of cirq.Circuit([\n    cirq.Moment(\n        cirq.MatrixGate(np.array([[(-0.640690...746901229944e-17j), (0.9060735868811878-0.4231201426973904j)]], dtype=np.complex128)).on(cirq.LineQubit(1)),\n    ),\n])>(qubit_order=[cirq.LineQubit(0), cirq.LineQubit(1)])
E         E        +      where <bound method AbstractCircuit.unitary of cirq.Circuit([\n    cirq.Moment(\n        cirq.MatrixGate(np.array([[(-0.640690...746901229944e-17j), (0.9060735868811878-0.4231201426973904j)]], dtype=np.complex128)).on(cirq.LineQubit(1)),\n    ),\n])> = cirq.Circuit([\n    cirq.Moment(\n        cirq.MatrixGate(np.array([[(-0.6406907775377064+0.2991911221579444j), (0.64069...7746901229944e-17j), (0.9060735868811878-0.4231201426973904j)]], dtype=np.complex128)).on(cirq.LineQubit(1)),\n    ),\n]).unitary
E         
E         cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py:120: AssertionError
E         _ test_decompose_two_qubit_interaction_into_four_fsim_gates_equivalence[obj132-fsim_gate132] _
E         
E         obj = cirq.SWAP
E         fsim_gate = cirq.FSimGate(theta=1.511761740437375, phi=0.00019081760422245964)
E         
E             @pytest.mark.parametrize('obj,fsim_gate', itertools.product(UNITARY_OBJS, FEASIBLE_FSIM_GATES))
E             def test_decompose_two_qubit_interaction_into_four_fsim_gates_equivalence(
E                 obj: Any, fsim_gate: cirq.FSimGate
E             ):
E                 qubits = obj.qubits if isinstance(obj, cirq.Operation) else cirq.LineQubit.range(2)
E                 circuit = cirq.decompose_two_qubit_interaction_into_four_fsim_gates(obj, fsim_gate=fsim_gate)
E                 desired_unitary = obj if isinstance(obj, np.ndarray) else cirq.unitary(obj)
E                 for operation in circuit.all_operations():
E                     assert len(operation.qubits) < 2 or operation.gate == fsim_gate
E                 assert len(circuit) <= 4 * 3 + 5
E         >       assert cirq.approx_eq(circuit.unitary(qubit_order=qubits), desired_unitary, atol=2e-4)
E         E       assert False
E         E        +  where False = <function approx_eq at 0x7f859b580c10>(array([[ 9.9999988e-01-7.45058060e-08j,  2.4655461e-04-1.01402402e-04j,  4.1902065e-05-1.02013350e-04j, -6.7055225e-08...08j,  2.4649501e-04+1.01476908e-04j,  4.2043626e-05+1.02020800e-04j,  9.9999964e-01-8.94069672e-08j]], dtype=complex64), array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],\n       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],\n       [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],\n       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]]), atol=0.0002)
E         E        +    where <function approx_eq at 0x7f859b580c10> = cirq.approx_eq
E         E        +    and   array([[ 9.9999988e-01-7.45058060e-08j,  2.4655461e-04-1.01402402e-04j,  4.1902065e-05-1.02013350e-04j, -6.7055225e-08...08j,  2.4649501e-04+1.01476908e-04j,  4.2043626e-05+1.02020800e-04j,  9.9999964e-01-8.94069672e-08j]], dtype=complex64) = <bound method AbstractCircuit.unitary of cirq.Circuit([\n    cirq.Moment(\n        cirq.MatrixGate(np.array([[(-1.012275...4999999992842133j), (0.5000000007157869+0.5000000007157869j)]], dtype=np.complex128)).on(cirq.LineQubit(1)),\n    ),\n])>(qubit_order=[cirq.LineQubit(0), cirq.LineQubit(1)])
E         E        +      where <bound method AbstractCircuit.unitary of cirq.Circuit([\n    cirq.Moment(\n        cirq.MatrixGate(np.array([[(-1.012275...4999999992842133j), (0.5000000007157869+0.5000000007157869j)]], dtype=np.complex128)).on(cirq.LineQubit(1)),\n    ),\n])> = cirq.Circuit([\n    cirq.Moment(\n        cirq.MatrixGate(np.array([[(-1.0122753614557024e-09-0.7071067811865476j), (0.7....4999999992842133j), (0.5000000007157869+0.5000000007157869j)]], dtype=np.complex128)).on(cirq.LineQubit(1)),\n    ),\n]).unitary
E         
E         cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py:120: AssertionError

Re-running.

@vtomole vtomole 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 2adb34f 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
@pavoljuhas pavoljuhas deleted the fix-mypy-numpy-errors branch June 23, 2022 22:29
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
- Fix return value type error for `measure_density_matrix()`
- Replace type spec Type[np.number] --> np.typing.DTypeLike
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
- Fix return value type error for `measure_density_matrix()`
- Replace type spec Type[np.number] --> np.typing.DTypeLike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants