diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf6f44ff5c3..bd3b32c581b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: python-version: '3.8' architecture: 'x64' - name: Install pylint - run: pip install -r dev_tools/requirements/deps/pylint.txt + run: pip install -r dev_tools/requirements/pylint.env.txt - name: Display version run: check/pylint --version - name: Lint diff --git a/cirq-core/cirq/linalg/transformations_test.py b/cirq-core/cirq/linalg/transformations_test.py index b92ff5faa13..160537045fa 100644 --- a/cirq-core/cirq/linalg/transformations_test.py +++ b/cirq-core/cirq/linalg/transformations_test.py @@ -352,20 +352,20 @@ def test_sub_state_vector(): a = np.arange(4) / np.linalg.norm(np.arange(4)) b = (np.arange(8) + 3) / np.linalg.norm(np.arange(8) + 3) c = (np.arange(16) + 1) / np.linalg.norm(np.arange(16) + 1) - state = np.kron(np.kron(a, b), c).reshape(2, 2, 2, 2, 2, 2, 2, 2, 2) + state = np.kron(np.kron(a, b), c).reshape((2, 2, 2, 2, 2, 2, 2, 2, 2)) assert cirq.equal_up_to_global_phase(cirq.sub_state_vector(a, [0, 1], atol=1e-8), a) assert cirq.equal_up_to_global_phase(cirq.sub_state_vector(b, [0, 1, 2], atol=1e-8), b) assert cirq.equal_up_to_global_phase(cirq.sub_state_vector(c, [0, 1, 2, 3], atol=1e-8), c) assert cirq.equal_up_to_global_phase( - cirq.sub_state_vector(state, [0, 1], atol=1e-15), a.reshape(2, 2) + cirq.sub_state_vector(state, [0, 1], atol=1e-15), a.reshape((2, 2)) ) assert cirq.equal_up_to_global_phase( - cirq.sub_state_vector(state, [2, 3, 4], atol=1e-15), b.reshape(2, 2, 2) + cirq.sub_state_vector(state, [2, 3, 4], atol=1e-15), b.reshape((2, 2, 2)) ) assert cirq.equal_up_to_global_phase( - cirq.sub_state_vector(state, [5, 6, 7, 8], atol=1e-15), c.reshape(2, 2, 2, 2) + cirq.sub_state_vector(state, [5, 6, 7, 8], atol=1e-15), c.reshape((2, 2, 2, 2)) ) # Output state vector conforms to the shape of the input state vector. @@ -485,15 +485,15 @@ def test_partial_trace_of_state_vector_as_mixture_pure_result(): assert mixtures_equal( cirq.partial_trace_of_state_vector_as_mixture(state, [0, 1], atol=1e-8), - ((1.0, a.reshape(2, 2)),), + ((1.0, a.reshape((2, 2))),), ) assert mixtures_equal( cirq.partial_trace_of_state_vector_as_mixture(state, [2, 3, 4], atol=1e-8), - ((1.0, b.reshape(2, 2, 2)),), + ((1.0, b.reshape((2, 2, 2))),), ) assert mixtures_equal( cirq.partial_trace_of_state_vector_as_mixture(state, [5, 6, 7, 8], atol=1e-8), - ((1.0, c.reshape(2, 2, 2, 2)),), + ((1.0, c.reshape((2, 2, 2, 2))),), ) assert mixtures_equal( cirq.partial_trace_of_state_vector_as_mixture(state, [0, 1, 2, 3, 4], atol=1e-8), diff --git a/cirq-core/cirq/ops/linear_combinations_test.py b/cirq-core/cirq/ops/linear_combinations_test.py index 6e2c3a647b5..24dfa0655c9 100644 --- a/cirq-core/cirq/ops/linear_combinations_test.py +++ b/cirq-core/cirq/ops/linear_combinations_test.py @@ -1318,7 +1318,7 @@ def test_expectation_from_state_vector_two_qubit_states(): psum1 = cirq.Z(q[0]) + 3.2 * cirq.Z(q[1]) psum2 = -1 * cirq.X(q[0]) + 2 * cirq.X(q[1]) wf1 = np.array([0, 1, 0, 0], dtype=complex) - for state in [wf1, wf1.reshape(2, 2)]: + for state in [wf1, wf1.reshape((2, 2))]: np.testing.assert_allclose( psum1.expectation_from_state_vector(state, qubit_map=q_map), -2.2, atol=1e-7 ) @@ -1327,7 +1327,7 @@ def test_expectation_from_state_vector_two_qubit_states(): ) wf2 = np.array([1, 1, 1, 1], dtype=complex) / 2 - for state in [wf2, wf2.reshape(2, 2)]: + for state in [wf2, wf2.reshape((2, 2))]: np.testing.assert_allclose( psum1.expectation_from_state_vector(state, qubit_map=q_map), 0, atol=1e-7 ) @@ -1338,7 +1338,7 @@ def test_expectation_from_state_vector_two_qubit_states(): psum3 = cirq.Z(q[0]) + cirq.X(q[1]) wf3 = np.array([1, 1, 0, 0], dtype=complex) / np.sqrt(2) q_map_2 = {q0: 1, q1: 0} - for state in [wf3, wf3.reshape(2, 2)]: + for state in [wf3, wf3.reshape((2, 2))]: np.testing.assert_allclose( psum3.expectation_from_state_vector(state, qubit_map=q_map), 2, atol=1e-7 ) @@ -1352,7 +1352,7 @@ def test_expectation_from_density_matrix_invalid_input(): psum = cirq.X(q0) + 2 * cirq.Y(q1) + 3 * cirq.Z(q3) q_map = {q0: 0, q1: 1, q3: 2} wf = np.array([1, 0, 0, 0, 0, 0, 0, 0], dtype=np.complex64) - rho = np.kron(wf.conjugate().T, wf).reshape(8, 8) + rho = np.kron(wf.conjugate().T, wf).reshape((8, 8)) im_psum = (1j + 1) * psum with pytest.raises(NotImplementedError, match='non-Hermitian'): @@ -1459,24 +1459,24 @@ def test_expectation_from_density_matrix_two_qubit_states(): psum1 = cirq.Z(q[0]) + 3.2 * cirq.Z(q[1]) psum2 = -1 * cirq.X(q[0]) + 2 * cirq.X(q[1]) wf1 = np.array([0, 1, 0, 0], dtype=complex) - rho1 = np.kron(wf1, wf1).reshape(4, 4) - for state in [rho1, rho1.reshape(2, 2, 2, 2)]: + rho1 = np.kron(wf1, wf1).reshape((4, 4)) + for state in [rho1, rho1.reshape((2, 2, 2, 2))]: np.testing.assert_allclose( psum1.expectation_from_density_matrix(state, qubit_map=q_map), -2.2 ) np.testing.assert_allclose(psum2.expectation_from_density_matrix(state, qubit_map=q_map), 0) wf2 = np.array([1, 1, 1, 1], dtype=complex) / 2 - rho2 = np.kron(wf2, wf2).reshape(4, 4) - for state in [rho2, rho2.reshape(2, 2, 2, 2)]: + rho2 = np.kron(wf2, wf2).reshape((4, 4)) + for state in [rho2, rho2.reshape((2, 2, 2, 2))]: np.testing.assert_allclose(psum1.expectation_from_density_matrix(state, qubit_map=q_map), 0) np.testing.assert_allclose(psum2.expectation_from_density_matrix(state, qubit_map=q_map), 1) psum3 = cirq.Z(q[0]) + cirq.X(q[1]) wf3 = np.array([1, 1, 0, 0], dtype=complex) / np.sqrt(2) - rho3 = np.kron(wf3, wf3).reshape(4, 4) + rho3 = np.kron(wf3, wf3).reshape((4, 4)) q_map_2 = {q0: 1, q1: 0} - for state in [rho3, rho3.reshape(2, 2, 2, 2)]: + for state in [rho3, rho3.reshape((2, 2, 2, 2))]: np.testing.assert_allclose(psum3.expectation_from_density_matrix(state, qubit_map=q_map), 2) np.testing.assert_allclose( psum3.expectation_from_density_matrix(state, qubit_map=q_map_2), 0 diff --git a/cirq-core/cirq/ops/pauli_string_test.py b/cirq-core/cirq/ops/pauli_string_test.py index 05d972e532a..40b82fb65a0 100644 --- a/cirq-core/cirq/ops/pauli_string_test.py +++ b/cirq-core/cirq/ops/pauli_string_test.py @@ -1030,17 +1030,17 @@ def test_expectation_from_state_vector_entangled_states(): x0x1 = cirq.PauliString(x0x1_pauli_map) q_map = {q0: 0, q1: 1} wf1 = np.array([0, 1, 1, 0], dtype=complex) / np.sqrt(2) - for state in [wf1, wf1.reshape(2, 2)]: + for state in [wf1, wf1.reshape((2, 2))]: np.testing.assert_allclose(z0z1.expectation_from_state_vector(state, q_map), -1) np.testing.assert_allclose(x0x1.expectation_from_state_vector(state, q_map), 1) wf2 = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2) - for state in [wf2, wf2.reshape(2, 2)]: + for state in [wf2, wf2.reshape((2, 2))]: np.testing.assert_allclose(z0z1.expectation_from_state_vector(state, q_map), 1) np.testing.assert_allclose(x0x1.expectation_from_state_vector(state, q_map), 1) wf3 = np.array([1, 1, 1, 1], dtype=complex) / 2 - for state in [wf3, wf3.reshape(2, 2)]: + for state in [wf3, wf3.reshape((2, 2))]: np.testing.assert_allclose(z0z1.expectation_from_state_vector(state, q_map), 0) np.testing.assert_allclose(x0x1.expectation_from_state_vector(state, q_map), 1) @@ -1049,7 +1049,7 @@ def test_expectation_from_state_vector_qubit_map(): q0, q1, q2 = _make_qubits(3) z = cirq.PauliString({q0: cirq.Z}) wf = np.array([0, 1, 0, 1, 0, 0, 0, 0], dtype=complex) / np.sqrt(2) - for state in [wf, wf.reshape(2, 2, 2)]: + for state in [wf, wf.reshape((2, 2, 2))]: np.testing.assert_allclose( z.expectation_from_state_vector(state, {q0: 0, q1: 1, q2: 2}), 1, atol=1e-8 ) @@ -1124,7 +1124,7 @@ def test_expectation_from_density_matrix_invalid_input(): q0, q1, q2, q3 = _make_qubits(4) ps = cirq.PauliString({q0: cirq.X, q1: cirq.Y}) wf = cirq.testing.random_superposition(4) - rho = np.kron(wf.conjugate().T, wf).reshape(4, 4) + rho = np.kron(wf.conjugate().T, wf).reshape((4, 4)) q_map = {q0: 0, q1: 1} im_ps = (1j + 1) * ps @@ -1238,20 +1238,20 @@ def test_expectation_from_density_matrix_entangled_states(): q_map = {q0: 0, q1: 1} wf1 = np.array([0, 1, 1, 0], dtype=complex) / np.sqrt(2) - rho1 = np.kron(wf1, wf1).reshape(4, 4) - for state in [rho1, rho1.reshape(2, 2, 2, 2)]: + rho1 = np.kron(wf1, wf1).reshape((4, 4)) + for state in [rho1, rho1.reshape((2, 2, 2, 2))]: np.testing.assert_allclose(z0z1.expectation_from_density_matrix(state, q_map), -1) np.testing.assert_allclose(x0x1.expectation_from_density_matrix(state, q_map), 1) wf2 = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2) - rho2 = np.kron(wf2, wf2).reshape(4, 4) - for state in [rho2, rho2.reshape(2, 2, 2, 2)]: + rho2 = np.kron(wf2, wf2).reshape((4, 4)) + for state in [rho2, rho2.reshape((2, 2, 2, 2))]: np.testing.assert_allclose(z0z1.expectation_from_density_matrix(state, q_map), 1) np.testing.assert_allclose(x0x1.expectation_from_density_matrix(state, q_map), 1) wf3 = np.array([1, 1, 1, 1], dtype=complex) / 2 - rho3 = np.kron(wf3, wf3).reshape(4, 4) - for state in [rho3, rho3.reshape(2, 2, 2, 2)]: + rho3 = np.kron(wf3, wf3).reshape((4, 4)) + for state in [rho3, rho3.reshape((2, 2, 2, 2))]: np.testing.assert_allclose(z0z1.expectation_from_density_matrix(state, q_map), 0) np.testing.assert_allclose(x0x1.expectation_from_density_matrix(state, q_map), 1) @@ -1260,9 +1260,9 @@ def test_expectation_from_density_matrix_qubit_map(): q0, q1, q2 = _make_qubits(3) z = cirq.PauliString({q0: cirq.Z}) wf = np.array([0, 1, 0, 1, 0, 0, 0, 0], dtype=complex) / np.sqrt(2) - rho = np.kron(wf, wf).reshape(8, 8) + rho = np.kron(wf, wf).reshape((8, 8)) - for state in [rho, rho.reshape(2, 2, 2, 2, 2, 2)]: + for state in [rho, rho.reshape((2, 2, 2, 2, 2, 2))]: np.testing.assert_allclose( z.expectation_from_density_matrix(state, {q0: 0, q1: 1, q2: 2}), 1 ) diff --git a/dev_tools/requirements/deps/pylint.txt b/dev_tools/requirements/deps/pylint.txt index 2f3154f65e8..7ab33f7bb20 100644 --- a/dev_tools/requirements/deps/pylint.txt +++ b/dev_tools/requirements/deps/pylint.txt @@ -1,6 +1,2 @@ # for linting - pylint~=2.13.0 - -# Bug with dill 0.3.5, see #5383 -dill==0.3.4 diff --git a/dev_tools/requirements/pylint.env.txt b/dev_tools/requirements/pylint.env.txt new file mode 100644 index 00000000000..2bc8c490773 --- /dev/null +++ b/dev_tools/requirements/pylint.env.txt @@ -0,0 +1,4 @@ +# let pylint check arguments in dependency function calls +-r deps/cirq-all.txt + +-r deps/pylint.txt