From e4a635de87128de3b1d8b03e6d53bf9a15696cbc Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 4 Nov 2024 11:41:45 -0800 Subject: [PATCH] pylint - fix dangerous-default-value --- dev_tools/.pylintrc | 2 +- unitary/quantum_chess/mcpe_utils.py | 8 +++++--- unitary/quantum_chess/swap_updater.py | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dev_tools/.pylintrc b/dev_tools/.pylintrc index 515badfc..a5224ff9 100644 --- a/dev_tools/.pylintrc +++ b/dev_tools/.pylintrc @@ -16,7 +16,7 @@ enable= consider-merging-isinstance, consider-using-f-string, continue-in-finally, - # dangerous-default-value, # TODO: #210 - enable and fix + dangerous-default-value, docstyle, duplicate-argument-name, # expression-not-assigned, # TODO: #210 - enable and fix diff --git a/unitary/quantum_chess/mcpe_utils.py b/unitary/quantum_chess/mcpe_utils.py index 882cd412..7c12ef81 100644 --- a/unitary/quantum_chess/mcpe_utils.py +++ b/unitary/quantum_chess/mcpe_utils.py @@ -22,7 +22,7 @@ """ from collections import defaultdict, deque -from typing import Callable, Dict, Iterable, Set, Tuple +from typing import Callable, Dict, Iterable, Optional, Set, Tuple import cirq @@ -67,8 +67,10 @@ class QubitMapping: initial_mapping: initial logical-to-physical qubit map. """ - def __init__(self, initial_mapping: Dict[cirq.Qid, cirq.GridQubit] = {}): - self.logical_to_physical = initial_mapping + def __init__( + self, initial_mapping: Optional[Dict[cirq.Qid, cirq.GridQubit]] = None + ): + self.logical_to_physical = initial_mapping or {} self.physical_to_logical = {v: k for k, v in initial_mapping.items()} def swap_physical(self, q1: cirq.GridQubit, q2: cirq.GridQubit) -> None: diff --git a/unitary/quantum_chess/swap_updater.py b/unitary/quantum_chess/swap_updater.py index a836f0b8..4ad272fc 100644 --- a/unitary/quantum_chess/swap_updater.py +++ b/unitary/quantum_chess/swap_updater.py @@ -161,14 +161,14 @@ def __init__( self, circuit: cirq.Circuit, device_qubits: Optional[Iterable[cirq.GridQubit]], - initial_mapping: Dict[cirq.Qid, cirq.GridQubit] = {}, + initial_mapping: Optional[Dict[cirq.Qid, cirq.GridQubit]] = None, swap_factory: Callable[ [cirq.Qid, cirq.Qid], Iterable[cirq.Operation] ] = generate_decomposed_swap, ): self.device_qubits = device_qubits or [] self.dlists = mcpe.DependencyLists(circuit) - self.mapping = mcpe.QubitMapping(initial_mapping) + self.mapping = mcpe.QubitMapping(initial_mapping or {}) self.swap_factory = swap_factory self.adjacent = {q: q.neighbors(device_qubits) for q in self.device_qubits} self.pairwise_distances = _pairwise_shortest_distances(self.adjacent)