Skip to content

Commit 0537811

Browse files
paul0403rniczhAlex-Preciado
authored
Update to Pylint 4.0.0 (#2121)
**Context:** Update to Pylint 4.0.0. This needs to be coordinated cross the ecosystem, to determine the target pylint version we're going to. For now, I'm saving the work I have done so far on trying to update catalyst to pylint 4.0.0. I am handing this off to @rniczh **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Hong-Sheng Zheng <[email protected]> Co-authored-by: Alex Preciado <[email protected]>
1 parent f0207be commit 0537811

27 files changed

+122
-111
lines changed

.github/workflows/check-formatting.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
steps:
1616
- name: Install dependencies
17-
run: pip install black isort pylint==3.3.9
17+
run: pip install black==25.9.0 isort~=7.0.0 pylint~=4.0.0
1818

1919
- name: Checkout code
2020
uses: actions/checkout@v4

frontend/test/lit/test_autograph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def if_assign_partial(x: float):
240240
if x < 3:
241241
y = 4
242242

243-
return y
243+
return y # pylint: disable=possibly-used-before-assignment
244244

245245
except AutoGraphError as e:
246246
# CHECK: Some branches did not define a value for variable 'y'

frontend/test/lit/test_from_plxpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def captured_circuit():
7171
def loop_fn(_):
7272
qml.Hadamard(0)
7373

74-
loop_fn()
74+
loop_fn() # pylint: disable=no-value-for-parameter
7575

7676
return qml.state()
7777

frontend/test/lit/test_function_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def qnode(x):
3333
# The entry point has no internal linkage.
3434
# CHECK-DAG: func.func public @jit_workload(%arg0: tensor<f64>) -> tensor<4xcomplex<f64>> attributes {llvm.emit_c_interface} {
3535
def workload(x: float):
36-
y = x * qml.numpy.pi
36+
y = x * qml.numpy.pi # pylint: disable=no-member
3737
return qnode(y)
3838

3939

frontend/test/lit/test_measurements.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ def expval5(x: float, y: float):
370370
print(expval5.mlir)
371371

372372

373-
# CHECK-LABEL: public @expval5(
373+
# CHECK-LABEL: public @expval6(
374374
@qjit(target="mlir")
375375
@qml.qnode(qml.device("lightning.qubit", wires=3))
376-
def expval5(x: float, y: float):
376+
def expval6(x: float, y: float):
377377
# CHECK: [[q0:%.+]] = quantum.custom "RX"
378378
qml.RX(x, wires=0)
379379
# CHECK: [[q1:%.+]] = quantum.custom "RY"
@@ -395,13 +395,13 @@ def expval5(x: float, y: float):
395395
return qml.expval(qml.Hamiltonian(coeffs, obs))
396396

397397

398-
print(expval5.mlir)
398+
print(expval6.mlir)
399399

400400

401-
# CHECK-LABEL: public @expval6(
401+
# CHECK-LABEL: public @expval7(
402402
@qjit(target="mlir")
403403
@qml.qnode(qml.device("lightning.qubit", wires=2))
404-
def expval6(x: float):
404+
def expval7(x: float):
405405
# CHECK: [[q0:%.+]] = quantum.custom "RX"
406406
qml.RX(x, wires=0)
407407

@@ -424,27 +424,27 @@ def expval6(x: float):
424424
return qml.expval(qml.Hamiltonian(coeff, [obs, qml.PauliX(0)]))
425425

426426

427-
print(expval6.mlir)
427+
print(expval7.mlir)
428428

429429

430-
# CHECK-LABEL: public @expval7(
430+
# CHECK-LABEL: public @expval8(
431431
@qjit(target="mlir")
432432
@qml.qnode(qml.device("lightning.qubit", wires=2))
433-
def expval7():
433+
def expval8():
434434
A = np.array([[complex(1.0, 0.0), complex(2.0, 0.0)], [complex(2.0, 0.0), complex(1.0, 0.0)]])
435435

436436
# CHECK: [[obs:%.+]] = quantum.hermitian
437437
# CHECK: quantum.expval [[obs]] : f64
438438
return qml.expval(qml.Hermitian(A, wires=0))
439439

440440

441-
print(expval7.mlir)
441+
print(expval8.mlir)
442442

443443

444-
# CHECK-LABEL: public @expval8(
444+
# CHECK-LABEL: public @expval9(
445445
@qjit(target="mlir")
446446
@qml.qnode(qml.device("lightning.qubit", wires=2))
447-
def expval8():
447+
def expval9():
448448
B = np.array(
449449
[
450450
[complex(1.0, 0.0), complex(2.0, 0.0), complex(1.0, 0.0), complex(2.0, 0.0)],
@@ -459,13 +459,13 @@ def expval8():
459459
return qml.expval(qml.Hermitian(B, wires=[0, 1]))
460460

461461

462-
print(expval8.mlir)
462+
print(expval9.mlir)
463463

464464

465-
# CHECK-LABEL: public @expval9(
465+
# CHECK-LABEL: public @expval10(
466466
@qjit(target="mlir")
467467
@qml.qnode(qml.device("lightning.qubit", wires=3))
468-
def expval9(x: float, y: float):
468+
def expval10(x: float, y: float):
469469
# CHECK: [[q0:%.+]] = quantum.custom "RX"
470470
qml.RX(x, wires=0)
471471
# CHECK: [[q1:%.+]] = quantum.custom "RY"
@@ -481,13 +481,13 @@ def expval9(x: float, y: float):
481481
return qml.expval(qml.PauliX(0) @ qml.PauliZ(1) @ qml.Hadamard(2))
482482

483483

484-
print(expval9.mlir)
484+
print(expval10.mlir)
485485

486486

487-
# CHECK-LABEL: public @expval10(
487+
# CHECK-LABEL: public @expval11(
488488
@qjit(target="mlir")
489489
@qml.qnode(qml.device("lightning.qubit", wires=3))
490-
def expval10(x: float, y: float):
490+
def expval11(x: float, y: float):
491491
# CHECK: [[q0:%.+]] = quantum.custom "RX"
492492
qml.RX(x, wires=0)
493493
# CHECK: [[q1:%.+]] = quantum.custom "RY"
@@ -511,12 +511,12 @@ def expval10(x: float, y: float):
511511
return qml.expval(qml.PauliX(1) @ qml.Hermitian(B, wires=[0, 2]))
512512

513513

514-
print(expval10.mlir)
514+
print(expval11.mlir)
515515

516516

517-
# CHECK-LABEL: @expval11
517+
# CHECK-LABEL: @expval12
518518
@qjit(target="mlir")
519-
def expval11(num_qubits):
519+
def expval12(num_qubits):
520520
# CHECK: func.func public @circ(%arg0: tensor<i64>) -> tensor<f64>
521521
@qml.qnode(qml.device("lightning.qubit", wires=num_qubits))
522522
def circ():
@@ -542,8 +542,8 @@ def circ():
542542
return circ()
543543

544544

545-
_ = expval11(10)
546-
print(expval11.mlir)
545+
_ = expval12(10)
546+
print(expval12.mlir)
547547

548548

549549
# CHECK-LABEL: public @var1(

frontend/test/lit/test_multi_qubit_gates.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Tests for multi-qubit gate compilation in Catalyst."""
16+
1517
# RUN: %PYTHON %s | FileCheck %s
1618

1719
import os
@@ -34,6 +36,7 @@
3436
@qjit(target="mlir")
3537
@qml.qnode(qml.device("lightning.qubit", wires=5))
3638
def circuit(x: float):
39+
"""Test circuit with various multi-qubit gates."""
3740
# CHECK: {{%.+}} = quantum.custom "Identity"() {{.+}} : !quantum.bit
3841
qml.Identity(0)
3942
# CHECK: {{%.+}} = quantum.custom "CNOT"() {{.+}} : !quantum.bit, !quantum.bit
@@ -53,10 +56,11 @@ def circuit(x: float):
5356
print(circuit.mlir)
5457

5558

56-
# CHECK-LABEL: public @jit_circuit
59+
# CHECK-LABEL: public @jit_circuit_unitary
5760
@qjit(target="mlir")
5861
@qml.qnode(qml.device("lightning.qubit", wires=3))
59-
def circuit():
62+
def circuit_unitary():
63+
"""Test circuit with unitary gates."""
6064
U1 = 1 / np.sqrt(2) * np.array([[1.0, 1.0], [1.0, -1.0]], dtype=complex)
6165
# CHECK: {{%.+}} = quantum.unitary({{%.+}} : tensor<2x2xcomplex<f64>>) {{%.+}} : !quantum.bit
6266
qml.QubitUnitary(U1, wires=0)
@@ -69,13 +73,14 @@ def circuit():
6973
[0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 0.99500417 - 0.09983342j],
7074
]
7175
)
76+
# pylint: disable=line-too-long
7277
# CHECK: {{%.+}} = quantum.unitary({{%.+}} : tensor<4x4xcomplex<f64>>) {{%.+}}, {{%.+}} : !quantum.bit, !quantum.bit
7378
qml.QubitUnitary(U2, wires=[0, 2])
7479

7580
return measure(wires=0), measure(wires=1)
7681

7782

78-
print(circuit.mlir)
83+
print(circuit_unitary.mlir)
7984

8085

8186
def get_custom_qjit_device(num_wires, discards, additions):
@@ -114,20 +119,21 @@ def execute(self, circuits, execution_config):
114119
return CustomDevice(wires=num_wires)
115120

116121

117-
# CHECK-LABEL: public @jit_circuit
122+
# CHECK-LABEL: public @jit_circuit_iswap_pswap
118123
@qjit(target="mlir")
119124
@qml.qnode(
120125
get_custom_qjit_device(2, (), {"ISWAP": OperatorProperties(), "PSWAP": OperatorProperties()})
121126
)
122-
def circuit(x: float):
127+
def circuit_iswap_pswap(x: float):
128+
"""Test circuit with ISWAP and PSWAP gates."""
123129
# CHECK: {{%.+}} = quantum.custom "ISWAP"() {{.+}} : !quantum.bit, !quantum.bit
124130
qml.ISWAP(wires=[0, 1])
125131
# CHECK: {{%.+}} = quantum.custom "PSWAP"({{%.+}}) {{.+}} : !quantum.bit, !quantum.bit
126132
qml.PSWAP(x, wires=[0, 1])
127133
return qml.probs()
128134

129135

130-
print(circuit.mlir)
136+
print(circuit_iswap_pswap.mlir)
131137

132138

133139
# CHECK-LABEL: public @jit_isingZZ_circuit

frontend/test/lit/test_snapshot_mlir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def single_qubit_circuit():
4747
# CHECK: [[snapshot2:%.+]] = quantum.state [[compbasis]] : tensor<2xcomplex<f64>>
4848
qml.Snapshot() # |->
4949

50-
qml.PhaseShift(np.pi / 2, wires=0)
50+
qml.PhaseShift(np.pi / 2, wires=0) # pylint: disable=no-member
5151

5252
# CHECK: [[compbasis:%.+]] = quantum.compbasis qreg {{%.+}} : !quantum.obs
5353
# CHECK: [[snapshot3:%.+]] = quantum.state [[compbasis]] : tensor<2xcomplex<f64>>
@@ -59,7 +59,7 @@ def single_qubit_circuit():
5959
# CHECK: [[snapshot4:%.+]] = quantum.state [[compbasis]] : tensor<2xcomplex<f64>>
6060
qml.Snapshot() # |+i>
6161

62-
qml.PhaseShift(-np.pi / 2, wires=0)
62+
qml.PhaseShift(-np.pi / 2, wires=0) # pylint: disable=no-member
6363

6464
# CHECK: [[compbasis:%.+]] = quantum.compbasis qreg {{%.+}} : !quantum.obs
6565
# CHECK: [[snapshot5:%.+]] = quantum.state [[compbasis]] : tensor<2xcomplex<f64>>

frontend/test/pytest/from_plxpr/test_capture_integration.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def loop(i):
420420
qml.CNOT(wires=[0, i])
421421
qml.RX(x, wires=i)
422422

423-
loop()
423+
loop() # pylint: disable=no-value-for-parameter
424424

425425
return qml.expval(qml.Z(2))
426426

@@ -458,7 +458,7 @@ def loop_rx(_, x):
458458
return jnp.sin(x)
459459

460460
# apply the for loop
461-
loop_rx(x)
461+
loop_rx(x) # pylint: disable=no-value-for-parameter
462462

463463
return qml.expval(qml.Z(0))
464464

@@ -478,7 +478,7 @@ def loop_rx(_, x):
478478
return jnp.sin(x)
479479

480480
# apply the for loop
481-
loop_rx(x)
481+
loop_rx(x) # pylint: disable=no-value-for-parameter
482482

483483
return qml.expval(qml.Z(0))
484484

@@ -508,10 +508,10 @@ def qft(i):
508508
def inner(j):
509509
qml.ControlledPhaseShift(jnp.pi / 2 ** (n - j + 1), [i, j])
510510

511-
inner()
511+
inner() # pylint: disable=no-value-for-parameter
512512

513-
init()
514-
qft()
513+
init() # pylint: disable=no-value-for-parameter
514+
qft() # pylint: disable=no-value-for-parameter
515515

516516
# Expected output: |100...>
517517
return qml.state()
@@ -539,10 +539,10 @@ def qft(i):
539539
def inner(j):
540540
qml.ControlledPhaseShift(jnp.pi / 2 ** (n - j + 1), [i, j])
541541

542-
inner()
542+
inner() # pylint: disable=no-value-for-parameter
543543

544-
init()
545-
qft()
544+
init() # pylint: disable=no-value-for-parameter
545+
qft() # pylint: disable=no-value-for-parameter
546546

547547
# Expected output: |100...>
548548
return qml.state()
@@ -1544,7 +1544,7 @@ def captured_circuit():
15441544
def loop_0(i):
15451545
qml.RX(0, wires=i)
15461546

1547-
loop_0()
1547+
loop_0() # pylint: disable=no-value-for-parameter
15481548

15491549
qml.RX(0, wires=0)
15501550
return qml.sample()
@@ -1562,7 +1562,7 @@ def circuit():
15621562
def loop_0(i):
15631563
qml.RX(0, wires=i)
15641564

1565-
loop_0()
1565+
loop_0() # pylint: disable=no-value-for-parameter
15661566

15671567
qml.RX(0, wires=0)
15681568
return qml.sample()
@@ -1648,7 +1648,7 @@ def f(i0):
16481648
def g(i, x):
16491649
return c(i) + x
16501650

1651-
return g(i0)
1651+
return g(i0) # pylint: disable=no-value-for-parameter
16521652

16531653
out = f(3.0)
16541654
assert qml.math.allclose(out, 3 + jnp.cos(2) + jnp.cos(4) + jnp.cos(6))
@@ -1695,9 +1695,9 @@ def outer(i):
16951695
def inner(j):
16961696
qml.RY(x, wires=j)
16971697

1698-
inner()
1698+
inner() # pylint: disable=no-value-for-parameter
16991699

1700-
outer()
1700+
outer() # pylint: disable=no-value-for-parameter
17011701

17021702
# Expected output: |100...>
17031703
return [qml.expval(qml.PauliZ(i)) for i in range(3)]
@@ -1723,9 +1723,9 @@ def outer(i, a):
17231723
def inner(j, b):
17241724
return b + x
17251725

1726-
return inner(a)
1726+
return inner(a) # pylint: disable=no-value-for-parameter
17271727

1728-
return outer(0.0)
1728+
return outer(0.0) # pylint: disable=no-value-for-parameter
17291729

17301730
res = f(0.2, 2)
17311731
assert qml.math.allclose(res, 0.2 * 2 * 3)

frontend/test/pytest/from_plxpr/test_from_plxpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ def f(i0):
844844
def g(i, x):
845845
return i + x
846846

847-
return g(i0)
847+
return g(i0) # pylint: disable=no-value-for-parameter
848848

849849
jaxpr = jax.make_jaxpr(f)(2)
850850
catalyst_jaxpr = from_plxpr(jaxpr)(2)

0 commit comments

Comments
 (0)