Skip to content

Commit c0c5e99

Browse files
committed
Merge branch 'python-lint' into polish-qasm
2 parents cf1c951 + 21130af commit c0c5e99

File tree

126 files changed

+726
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+726
-154
lines changed

python/pecos-rslib/src/pecos_rslib/rssparse_sim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pecos_rslib._pecos_rslib import SparseSim as RustSparseSim
2626

2727
if TYPE_CHECKING:
28-
from pecos.type_defs import SimulatorGateParams
28+
from pecos.typing import SimulatorGateParams
2929

3030

3131
class SparseSimRs:

python/pecos-rslib/src/pecos_rslib/rsstate_vec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pecos_rslib._pecos_rslib import RsStateVec as RustStateVec
2626

2727
if TYPE_CHECKING:
28-
from pecos.type_defs import SimulatorGateParams
28+
from pecos.typing import SimulatorGateParams
2929

3030

3131
class StateVecRs:

python/quantum-pecos/src/pecos/circuits/qc2phir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,14 @@ def ops_buffer_append(
276276
}
277277
del metadata["export"]
278278

279-
elif metadata.get("cop_type") in ["Idle", "idle"]:
279+
elif metadata.get("cop_type") in {"Idle", "idle"}:
280280
del metadata["cop_type"]
281281
op = {
282282
"mop": "Idle",
283283
"args": find_qid2qsym(qubits),
284284
}
285285

286-
elif metadata.get("cop_type") in ["Transport", "transport"]:
286+
elif metadata.get("cop_type") in {"Transport", "transport"}:
287287
del metadata["cop_type"]
288288
op = {
289289
"mop": "Transport",

python/quantum-pecos/src/pecos/circuits/quantum_circuit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from __future__ import annotations
1717

18+
import copy
1819
import json
1920
from collections import defaultdict
2021
from collections.abc import MutableSequence
@@ -26,13 +27,13 @@
2627
if TYPE_CHECKING:
2728
from collections.abc import Iterator
2829

29-
from pecos.type_defs import JSONDict, JSONValue
30+
from pecos.typing import JSONDict, JSONValue
3031

3132
# Type aliases
3233
Location = int | tuple[int, ...]
3334
LocationSet = set[Location] | list[Location] | tuple[Location, ...]
3435
GateDict = dict[str, LocationSet]
35-
CircuitSetup = None | int | list[GateDict]
36+
CircuitSetup = int | list[GateDict] | None
3637

3738

3839
class QuantumCircuit(MutableSequence):
@@ -353,7 +354,7 @@ def __copy__(self) -> QuantumCircuit:
353354

354355
def copy(self) -> QuantumCircuit:
355356
"""Create a shallow copy of the circuit."""
356-
return self.__copy__()
357+
return copy.copy(self)
357358

358359
def __iter__(self) -> Iterator[tuple[str, LocationSet, JSONDict]]:
359360
"""Iterate over all gates in the circuit."""

python/quantum-pecos/src/pecos/classical_interpreters/phir_classical_interpreter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def init(
105105
PHIRModel.model_validate(self.program)
106106

107107
if isinstance(self.program, dict):
108-
if self.program["format"] not in ["PHIR/JSON", "PHIR"]:
108+
if self.program["format"] not in {"PHIR/JSON", "PHIR"}:
109109
msg = f"Unsupported PHIR format: {self.program['format']}"
110110
raise ValueError(msg)
111111
if version2tuple(self.program["version"]) >= (0, 2, 0):
@@ -203,7 +203,7 @@ def execute(self, seq: Sequence) -> Generator[list, Any, None]:
203203
if isinstance(op, pt.opt.QOp):
204204
op_buffer.append(op)
205205

206-
if op.name in ["measure Z", "Measure", "Measure +Z"]:
206+
if op.name in {"measure Z", "Measure", "Measure +Z"}:
207207
yield op_buffer
208208
op_buffer.clear()
209209

@@ -266,7 +266,7 @@ def get_bit(self, cvar: str, idx: int) -> int:
266266
def eval_expr(
267267
self,
268268
expr: int | str | list | pt.opt.COp,
269-
) -> None | int | integer:
269+
) -> int | integer | None:
270270
"""Evaluates integer expressions."""
271271
match expr:
272272
case int():
@@ -442,5 +442,5 @@ def result_bits(
442442
i: int
443443
if filter_private and m.startswith("__"):
444444
continue
445-
send_meas[(m, i)] = self.get_bit(m, i)
445+
send_meas[m, i] = self.get_bit(m, i)
446446
return send_meas

python/quantum-pecos/src/pecos/decoders/mwpm2d/mwpm2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def decode(
140140
matching.update(dict(matching_edges))
141141

142142
nodes_paired = set()
143-
## for n1 in real_graph.nodes():
143+
# for n1 in real_graph.nodes():
144144
real_syn = set(real_graph.nodes())
145145
for n1 in syndromes & real_syn:
146146
n2 = matching[n1]

python/quantum-pecos/src/pecos/decoders/mwpm2d/precomputing.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ def surface4444_identity(instr: LogicalInstructionProtocol) -> dict[str, Any]:
221221
virt_node = "v" + str(vi)
222222

223223
# X virtual nodes (sides left and right)
224-
if side_label in ["left", "right"]: # 1 for i = 1 and 3 => left and right
224+
if side_label in {"left", "right"}: # 1 for i = 1 and 3 => left and right
225225
syn_list = d2edge_x.setdefault(data, [])
226226
syn_list.append(virt_node)
227227
virt_x.add(virt_node)
228228

229229
# Z virtual nodes (sides top and bottom)
230-
elif side_label in ["top", "bottom"]: # 0 for i = 0 and 2 => top and bottom
230+
elif side_label in {"top", "bottom"}: # 0 for i = 0 and 2 => top and bottom
231231
syn_list = d2edge_z.setdefault(data, [])
232232
syn_list.append(virt_node)
233233
virt_z.add(virt_node)
@@ -255,7 +255,7 @@ def surface4444_identity(instr: LogicalInstructionProtocol) -> dict[str, Any]:
255255
raise Exception(msg)
256256

257257
edges[tuple(edge)] = data
258-
edges[(edge[1], edge[0])] = data
258+
edges[edge[1], edge[0]] = data
259259
temp_graph.add_edge(edge[0], edge[1])
260260

261261
# Create distance graph
@@ -288,7 +288,7 @@ def surface4444_identity(instr: LogicalInstructionProtocol) -> dict[str, Any]:
288288
data_path = []
289289
s1 = syn_path[0]
290290
for s2 in syn_path[1:]:
291-
data = edge2d[(s1, s2)]
291+
data = edge2d[s1, s2]
292292
data_path.append(data)
293293
s1 = s2
294294

@@ -323,7 +323,7 @@ def surface4444_identity(instr: LogicalInstructionProtocol) -> dict[str, Any]:
323323
data_path = []
324324
s1 = syn_path[0]
325325
for s2 in syn_path[1:]:
326-
data = edge2d[(s1, s2)]
326+
data = edge2d[s1, s2]
327327
data_path.append(data)
328328
s1 = s2
329329

@@ -510,7 +510,7 @@ def surface4444medial_identity(instr: LogicalInstructionProtocol) -> dict[str, A
510510
raise Exception(msg)
511511

512512
edges[tuple(edge)] = data
513-
edges[(edge[1], edge[0])] = data
513+
edges[edge[1], edge[0]] = data
514514
temp_graph.add_edge(edge[0], edge[1])
515515

516516
# Create distance graph
@@ -543,7 +543,7 @@ def surface4444medial_identity(instr: LogicalInstructionProtocol) -> dict[str, A
543543
data_path = []
544544
s1 = syn_path[0]
545545
for s2 in syn_path[1:]:
546-
data = edge2d[(s1, s2)]
546+
data = edge2d[s1, s2]
547547
data_path.append(data)
548548
s1 = s2
549549

@@ -578,7 +578,7 @@ def surface4444medial_identity(instr: LogicalInstructionProtocol) -> dict[str, A
578578
data_path = []
579579
s1 = syn_path[0]
580580
for s2 in syn_path[1:]:
581-
data = edge2d[(s1, s2)]
581+
data = edge2d[s1, s2]
582582
data_path.append(data)
583583
s1 = s2
584584

python/quantum-pecos/src/pecos/engines/cvm/binarray.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1818
# specific language governing permissions and limitations under the License.
1919

20+
"""Binary array implementation for the PECOS classical virtual machine.
21+
22+
This module provides the BinArray class for efficient binary array operations
23+
within the classical virtual machine (CVM) framework. It supports various
24+
binary representations and operations needed for classical computations
25+
in quantum error correction simulations.
26+
"""
27+
2028
from __future__ import annotations
2129

2230
from typing import TYPE_CHECKING

python/quantum-pecos/src/pecos/engines/cvm/classical.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,20 +377,20 @@ def eval_condition(
377377

378378
# Map of operators to their evaluation functions
379379
ops = {
380-
"==": lambda a, b: bool(a.__eq__(b)),
381-
"!=": lambda a, b: bool(a.__ne__(b)),
382-
"^": lambda a, b: bool(a.__xor__(b).__int__()),
383-
"|": lambda a, b: bool(a.__or__(b).__int__()),
384-
"&": lambda a, b: bool(a.__and__(b).__int__()),
385-
"<": lambda a, b: a.__lt__(b),
386-
">": lambda a, b: a.__gt__(b),
387-
"<=": lambda a, b: a.__le__(b),
388-
">=": lambda a, b: a.__ge__(b),
389-
">>": lambda a, b: a.__rshift__(b),
390-
"<<": lambda a, b: a.__lshift__(b),
391-
"~": lambda a, _: a.__invert__(),
392-
"*": lambda a, b: a.__mul__(b),
393-
"/": lambda a, b: a.__floordiv__(b),
380+
"==": lambda a, b: bool(a == b),
381+
"!=": lambda a, b: bool(a != b),
382+
"^": lambda a, b: bool(int(a ^ b)),
383+
"|": lambda a, b: bool(int(a | b)),
384+
"&": lambda a, b: bool(int(a & b)),
385+
"<": lambda a, b: a < b,
386+
">": lambda a, b: a > b,
387+
"<=": lambda a, b: a <= b,
388+
">=": lambda a, b: a >= b,
389+
">>": lambda a, b: a >> b,
390+
"<<": lambda a, b: a << b,
391+
"~": lambda a, _: ~a,
392+
"*": lambda a, b: a * b,
393+
"/": lambda a, b: a // b,
394394
}
395395

396396
if op in ops:

python/quantum-pecos/src/pecos/engines/cvm/sim_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def sim_exec(
172172
func: str,
173173
runner: Runner,
174174
*args: Any, # noqa: ANN401 - Dynamic dispatch requires Any
175-
) -> None | int | dict[str, Any]:
175+
) -> int | dict[str, Any] | None:
176176
"""Execute a simulation function by name.
177177
178178
Dispatches to the appropriate simulation function based on the function name,

0 commit comments

Comments
 (0)