Skip to content

Commit 6565fc5

Browse files
authored
CI - run pylint checks with dependencies installed (#6163)
* Install all cirq dependencies for pylint check so pylint can verify arguments in function calls. * Fix pylint complaints on too-many-function-args by using a single shape argument for numpy array.reshape(). * Remove obsolete pin of the dill version. The current release dill-0.3.6 seems OK w/r to #5383
1 parent 228c7e6 commit 6565fc5

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
python-version: '3.8'
9191
architecture: 'x64'
9292
- name: Install pylint
93-
run: pip install -r dev_tools/requirements/deps/pylint.txt
93+
run: pip install -r dev_tools/requirements/pylint.env.txt
9494
- name: Display version
9595
run: check/pylint --version
9696
- name: Lint

cirq-core/cirq/linalg/transformations_test.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -352,20 +352,20 @@ def test_sub_state_vector():
352352
a = np.arange(4) / np.linalg.norm(np.arange(4))
353353
b = (np.arange(8) + 3) / np.linalg.norm(np.arange(8) + 3)
354354
c = (np.arange(16) + 1) / np.linalg.norm(np.arange(16) + 1)
355-
state = np.kron(np.kron(a, b), c).reshape(2, 2, 2, 2, 2, 2, 2, 2, 2)
355+
state = np.kron(np.kron(a, b), c).reshape((2, 2, 2, 2, 2, 2, 2, 2, 2))
356356

357357
assert cirq.equal_up_to_global_phase(cirq.sub_state_vector(a, [0, 1], atol=1e-8), a)
358358
assert cirq.equal_up_to_global_phase(cirq.sub_state_vector(b, [0, 1, 2], atol=1e-8), b)
359359
assert cirq.equal_up_to_global_phase(cirq.sub_state_vector(c, [0, 1, 2, 3], atol=1e-8), c)
360360

361361
assert cirq.equal_up_to_global_phase(
362-
cirq.sub_state_vector(state, [0, 1], atol=1e-15), a.reshape(2, 2)
362+
cirq.sub_state_vector(state, [0, 1], atol=1e-15), a.reshape((2, 2))
363363
)
364364
assert cirq.equal_up_to_global_phase(
365-
cirq.sub_state_vector(state, [2, 3, 4], atol=1e-15), b.reshape(2, 2, 2)
365+
cirq.sub_state_vector(state, [2, 3, 4], atol=1e-15), b.reshape((2, 2, 2))
366366
)
367367
assert cirq.equal_up_to_global_phase(
368-
cirq.sub_state_vector(state, [5, 6, 7, 8], atol=1e-15), c.reshape(2, 2, 2, 2)
368+
cirq.sub_state_vector(state, [5, 6, 7, 8], atol=1e-15), c.reshape((2, 2, 2, 2))
369369
)
370370

371371
# 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():
485485

486486
assert mixtures_equal(
487487
cirq.partial_trace_of_state_vector_as_mixture(state, [0, 1], atol=1e-8),
488-
((1.0, a.reshape(2, 2)),),
488+
((1.0, a.reshape((2, 2))),),
489489
)
490490
assert mixtures_equal(
491491
cirq.partial_trace_of_state_vector_as_mixture(state, [2, 3, 4], atol=1e-8),
492-
((1.0, b.reshape(2, 2, 2)),),
492+
((1.0, b.reshape((2, 2, 2))),),
493493
)
494494
assert mixtures_equal(
495495
cirq.partial_trace_of_state_vector_as_mixture(state, [5, 6, 7, 8], atol=1e-8),
496-
((1.0, c.reshape(2, 2, 2, 2)),),
496+
((1.0, c.reshape((2, 2, 2, 2))),),
497497
)
498498
assert mixtures_equal(
499499
cirq.partial_trace_of_state_vector_as_mixture(state, [0, 1, 2, 3, 4], atol=1e-8),

cirq-core/cirq/ops/linear_combinations_test.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ def test_expectation_from_state_vector_two_qubit_states():
13181318
psum1 = cirq.Z(q[0]) + 3.2 * cirq.Z(q[1])
13191319
psum2 = -1 * cirq.X(q[0]) + 2 * cirq.X(q[1])
13201320
wf1 = np.array([0, 1, 0, 0], dtype=complex)
1321-
for state in [wf1, wf1.reshape(2, 2)]:
1321+
for state in [wf1, wf1.reshape((2, 2))]:
13221322
np.testing.assert_allclose(
13231323
psum1.expectation_from_state_vector(state, qubit_map=q_map), -2.2, atol=1e-7
13241324
)
@@ -1327,7 +1327,7 @@ def test_expectation_from_state_vector_two_qubit_states():
13271327
)
13281328

13291329
wf2 = np.array([1, 1, 1, 1], dtype=complex) / 2
1330-
for state in [wf2, wf2.reshape(2, 2)]:
1330+
for state in [wf2, wf2.reshape((2, 2))]:
13311331
np.testing.assert_allclose(
13321332
psum1.expectation_from_state_vector(state, qubit_map=q_map), 0, atol=1e-7
13331333
)
@@ -1338,7 +1338,7 @@ def test_expectation_from_state_vector_two_qubit_states():
13381338
psum3 = cirq.Z(q[0]) + cirq.X(q[1])
13391339
wf3 = np.array([1, 1, 0, 0], dtype=complex) / np.sqrt(2)
13401340
q_map_2 = {q0: 1, q1: 0}
1341-
for state in [wf3, wf3.reshape(2, 2)]:
1341+
for state in [wf3, wf3.reshape((2, 2))]:
13421342
np.testing.assert_allclose(
13431343
psum3.expectation_from_state_vector(state, qubit_map=q_map), 2, atol=1e-7
13441344
)
@@ -1352,7 +1352,7 @@ def test_expectation_from_density_matrix_invalid_input():
13521352
psum = cirq.X(q0) + 2 * cirq.Y(q1) + 3 * cirq.Z(q3)
13531353
q_map = {q0: 0, q1: 1, q3: 2}
13541354
wf = np.array([1, 0, 0, 0, 0, 0, 0, 0], dtype=np.complex64)
1355-
rho = np.kron(wf.conjugate().T, wf).reshape(8, 8)
1355+
rho = np.kron(wf.conjugate().T, wf).reshape((8, 8))
13561356

13571357
im_psum = (1j + 1) * psum
13581358
with pytest.raises(NotImplementedError, match='non-Hermitian'):
@@ -1459,24 +1459,24 @@ def test_expectation_from_density_matrix_two_qubit_states():
14591459
psum1 = cirq.Z(q[0]) + 3.2 * cirq.Z(q[1])
14601460
psum2 = -1 * cirq.X(q[0]) + 2 * cirq.X(q[1])
14611461
wf1 = np.array([0, 1, 0, 0], dtype=complex)
1462-
rho1 = np.kron(wf1, wf1).reshape(4, 4)
1463-
for state in [rho1, rho1.reshape(2, 2, 2, 2)]:
1462+
rho1 = np.kron(wf1, wf1).reshape((4, 4))
1463+
for state in [rho1, rho1.reshape((2, 2, 2, 2))]:
14641464
np.testing.assert_allclose(
14651465
psum1.expectation_from_density_matrix(state, qubit_map=q_map), -2.2
14661466
)
14671467
np.testing.assert_allclose(psum2.expectation_from_density_matrix(state, qubit_map=q_map), 0)
14681468

14691469
wf2 = np.array([1, 1, 1, 1], dtype=complex) / 2
1470-
rho2 = np.kron(wf2, wf2).reshape(4, 4)
1471-
for state in [rho2, rho2.reshape(2, 2, 2, 2)]:
1470+
rho2 = np.kron(wf2, wf2).reshape((4, 4))
1471+
for state in [rho2, rho2.reshape((2, 2, 2, 2))]:
14721472
np.testing.assert_allclose(psum1.expectation_from_density_matrix(state, qubit_map=q_map), 0)
14731473
np.testing.assert_allclose(psum2.expectation_from_density_matrix(state, qubit_map=q_map), 1)
14741474

14751475
psum3 = cirq.Z(q[0]) + cirq.X(q[1])
14761476
wf3 = np.array([1, 1, 0, 0], dtype=complex) / np.sqrt(2)
1477-
rho3 = np.kron(wf3, wf3).reshape(4, 4)
1477+
rho3 = np.kron(wf3, wf3).reshape((4, 4))
14781478
q_map_2 = {q0: 1, q1: 0}
1479-
for state in [rho3, rho3.reshape(2, 2, 2, 2)]:
1479+
for state in [rho3, rho3.reshape((2, 2, 2, 2))]:
14801480
np.testing.assert_allclose(psum3.expectation_from_density_matrix(state, qubit_map=q_map), 2)
14811481
np.testing.assert_allclose(
14821482
psum3.expectation_from_density_matrix(state, qubit_map=q_map_2), 0

cirq-core/cirq/ops/pauli_string_test.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1030,17 +1030,17 @@ def test_expectation_from_state_vector_entangled_states():
10301030
x0x1 = cirq.PauliString(x0x1_pauli_map)
10311031
q_map = {q0: 0, q1: 1}
10321032
wf1 = np.array([0, 1, 1, 0], dtype=complex) / np.sqrt(2)
1033-
for state in [wf1, wf1.reshape(2, 2)]:
1033+
for state in [wf1, wf1.reshape((2, 2))]:
10341034
np.testing.assert_allclose(z0z1.expectation_from_state_vector(state, q_map), -1)
10351035
np.testing.assert_allclose(x0x1.expectation_from_state_vector(state, q_map), 1)
10361036

10371037
wf2 = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2)
1038-
for state in [wf2, wf2.reshape(2, 2)]:
1038+
for state in [wf2, wf2.reshape((2, 2))]:
10391039
np.testing.assert_allclose(z0z1.expectation_from_state_vector(state, q_map), 1)
10401040
np.testing.assert_allclose(x0x1.expectation_from_state_vector(state, q_map), 1)
10411041

10421042
wf3 = np.array([1, 1, 1, 1], dtype=complex) / 2
1043-
for state in [wf3, wf3.reshape(2, 2)]:
1043+
for state in [wf3, wf3.reshape((2, 2))]:
10441044
np.testing.assert_allclose(z0z1.expectation_from_state_vector(state, q_map), 0)
10451045
np.testing.assert_allclose(x0x1.expectation_from_state_vector(state, q_map), 1)
10461046

@@ -1049,7 +1049,7 @@ def test_expectation_from_state_vector_qubit_map():
10491049
q0, q1, q2 = _make_qubits(3)
10501050
z = cirq.PauliString({q0: cirq.Z})
10511051
wf = np.array([0, 1, 0, 1, 0, 0, 0, 0], dtype=complex) / np.sqrt(2)
1052-
for state in [wf, wf.reshape(2, 2, 2)]:
1052+
for state in [wf, wf.reshape((2, 2, 2))]:
10531053
np.testing.assert_allclose(
10541054
z.expectation_from_state_vector(state, {q0: 0, q1: 1, q2: 2}), 1, atol=1e-8
10551055
)
@@ -1124,7 +1124,7 @@ def test_expectation_from_density_matrix_invalid_input():
11241124
q0, q1, q2, q3 = _make_qubits(4)
11251125
ps = cirq.PauliString({q0: cirq.X, q1: cirq.Y})
11261126
wf = cirq.testing.random_superposition(4)
1127-
rho = np.kron(wf.conjugate().T, wf).reshape(4, 4)
1127+
rho = np.kron(wf.conjugate().T, wf).reshape((4, 4))
11281128
q_map = {q0: 0, q1: 1}
11291129

11301130
im_ps = (1j + 1) * ps
@@ -1238,20 +1238,20 @@ def test_expectation_from_density_matrix_entangled_states():
12381238
q_map = {q0: 0, q1: 1}
12391239

12401240
wf1 = np.array([0, 1, 1, 0], dtype=complex) / np.sqrt(2)
1241-
rho1 = np.kron(wf1, wf1).reshape(4, 4)
1242-
for state in [rho1, rho1.reshape(2, 2, 2, 2)]:
1241+
rho1 = np.kron(wf1, wf1).reshape((4, 4))
1242+
for state in [rho1, rho1.reshape((2, 2, 2, 2))]:
12431243
np.testing.assert_allclose(z0z1.expectation_from_density_matrix(state, q_map), -1)
12441244
np.testing.assert_allclose(x0x1.expectation_from_density_matrix(state, q_map), 1)
12451245

12461246
wf2 = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2)
1247-
rho2 = np.kron(wf2, wf2).reshape(4, 4)
1248-
for state in [rho2, rho2.reshape(2, 2, 2, 2)]:
1247+
rho2 = np.kron(wf2, wf2).reshape((4, 4))
1248+
for state in [rho2, rho2.reshape((2, 2, 2, 2))]:
12491249
np.testing.assert_allclose(z0z1.expectation_from_density_matrix(state, q_map), 1)
12501250
np.testing.assert_allclose(x0x1.expectation_from_density_matrix(state, q_map), 1)
12511251

12521252
wf3 = np.array([1, 1, 1, 1], dtype=complex) / 2
1253-
rho3 = np.kron(wf3, wf3).reshape(4, 4)
1254-
for state in [rho3, rho3.reshape(2, 2, 2, 2)]:
1253+
rho3 = np.kron(wf3, wf3).reshape((4, 4))
1254+
for state in [rho3, rho3.reshape((2, 2, 2, 2))]:
12551255
np.testing.assert_allclose(z0z1.expectation_from_density_matrix(state, q_map), 0)
12561256
np.testing.assert_allclose(x0x1.expectation_from_density_matrix(state, q_map), 1)
12571257

@@ -1260,9 +1260,9 @@ def test_expectation_from_density_matrix_qubit_map():
12601260
q0, q1, q2 = _make_qubits(3)
12611261
z = cirq.PauliString({q0: cirq.Z})
12621262
wf = np.array([0, 1, 0, 1, 0, 0, 0, 0], dtype=complex) / np.sqrt(2)
1263-
rho = np.kron(wf, wf).reshape(8, 8)
1263+
rho = np.kron(wf, wf).reshape((8, 8))
12641264

1265-
for state in [rho, rho.reshape(2, 2, 2, 2, 2, 2)]:
1265+
for state in [rho, rho.reshape((2, 2, 2, 2, 2, 2))]:
12661266
np.testing.assert_allclose(
12671267
z.expectation_from_density_matrix(state, {q0: 0, q1: 1, q2: 2}), 1
12681268
)
-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
# for linting
2-
32
pylint~=2.13.0
4-
5-
# Bug with dill 0.3.5, see #5383
6-
dill==0.3.4

dev_tools/requirements/pylint.env.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# let pylint check arguments in dependency function calls
2+
-r deps/cirq-all.txt
3+
4+
-r deps/pylint.txt

0 commit comments

Comments
 (0)