Skip to content

Commit

Permalink
Merge branch 'main' into move-target
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss authored Jun 11, 2024
2 parents ed97436 + 03d107e commit 0c671dd
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 55 deletions.
12 changes: 4 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ disable = [
"too-many-lines", "too-many-branches", "too-many-locals", "too-many-nested-blocks", "too-many-statements",
"too-many-instance-attributes", "too-many-arguments", "too-many-public-methods", "too-few-public-methods", "too-many-ancestors",
"unnecessary-pass", # allow for methods with just "pass", for clarity
"unnecessary-dunder-call", # do not want to implement
"no-else-return", # relax "elif" after a clause with a return
"docstring-first-line-empty", # relax docstring style
"import-outside-toplevel", "import-error", # overzealous with our optionals/dynamic packages
Expand All @@ -217,17 +218,12 @@ disable = [
# TODO(#9614): these were added in modern Pylint. Decide if we want to enable them. If so,
# remove from here and fix the issues. Else, move it above this section and add a comment
# with the rationale
"arguments-renamed",
"consider-using-enumerate",
"consider-using-f-string",
"no-member",
"no-value-for-parameter",
"no-member", # for dynamically created members
"not-context-manager",
"possibly-used-before-assignment",
"unexpected-keyword-arg",
"unnecessary-dunder-call",
"unnecessary-lambda-assignment",
"unspecified-encoding",
"unnecessary-lambda-assignment", # do not want to implement
"unspecified-encoding", # do not want to implement
]

enable = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def evaluate(self, x: float) -> float:
"""

y = 0
for i in range(0, len(self.breakpoints)):
y = y + (x >= self.breakpoints[i]) * (np.poly1d(self.mapped_coeffs[i][::-1])(x))
for i, breakpt in enumerate(self.breakpoints):
y = y + (x >= breakpt) * (np.poly1d(self.mapped_coeffs[i][::-1])(x))

return y

Expand Down
2 changes: 1 addition & 1 deletion qiskit/primitives/backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _transpile(self):
transpiled_circuit = common_circuit.copy()
final_index_layout = list(range(common_circuit.num_qubits))
else:
transpiled_circuit = transpile(
transpiled_circuit = transpile( # pylint:disable=unexpected-keyword-arg
common_circuit, self.backend, **self.transpile_options.__dict__
)
if transpiled_circuit.layout is not None:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/primitives/backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _transpile(self):

start = len(self._transpiled_circuits)
self._transpiled_circuits.extend(
transpile(
transpile( # pylint:disable=unexpected-keyword-arg
self.preprocessed_circuits[start:],
self.backend,
**self.transpile_options.__dict__,
Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __copy__(self):
The returned option and validator values are shallow copies of the originals.
"""
out = self.__new__(type(self))
out = self.__new__(type(self)) # pylint:disable=no-value-for-parameter
out.__setstate__((self._fields.copy(), self.validator.copy()))
return out

Expand Down
12 changes: 6 additions & 6 deletions qiskit/synthesis/stabilizer/stabilizer_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def synth_circuit_from_stabilizers(
circuit = QuantumCircuit(num_qubits)

used = 0
for i in range(len(stabilizer_list)):
curr_stab = stabilizer_list[i].evolve(Clifford(circuit), frame="s")
for i, stabilizer in enumerate(stabilizer_list):
curr_stab = stabilizer.evolve(Clifford(circuit), frame="s")

# Find pivot.
pivot = used
Expand All @@ -81,17 +81,17 @@ def synth_circuit_from_stabilizers(
if pivot == num_qubits:
if curr_stab.x.any():
raise QiskitError(
f"Stabilizer {i} ({stabilizer_list[i]}) anti-commutes with some of "
f"Stabilizer {i} ({stabilizer}) anti-commutes with some of "
"the previous stabilizers."
)
if curr_stab.phase == 2:
raise QiskitError(
f"Stabilizer {i} ({stabilizer_list[i]}) contradicts "
f"Stabilizer {i} ({stabilizer}) contradicts "
"some of the previous stabilizers."
)
if curr_stab.z.any() and not allow_redundant:
raise QiskitError(
f"Stabilizer {i} ({stabilizer_list[i]}) is a product of the others "
f"Stabilizer {i} ({stabilizer}) is a product of the others "
"and allow_redundant is False. Add allow_redundant=True "
"to the function call if you want to allow redundant stabilizers."
)
Expand Down Expand Up @@ -133,7 +133,7 @@ def synth_circuit_from_stabilizers(
circuit.swap(pivot, used)

# fix sign
curr_stab = stabilizer_list[i].evolve(Clifford(circuit), frame="s")
curr_stab = stabilizer.evolve(Clifford(circuit), frame="s")
if curr_stab.phase == 2:
circuit.x(used)
used += 1
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/basepasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __eq__(self, other):
return hash(self) == hash(other)

@abstractmethod
def run(self, dag: DAGCircuit): # pylint: disable=arguments-differ
def run(self, dag: DAGCircuit): # pylint:disable=arguments-renamed
"""Run a pass on the DAGCircuit. This is implemented by the pass developer.
Args:
Expand Down
8 changes: 4 additions & 4 deletions qiskit/transpiler/passes/optimization/inverse_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ def _run_on_self_inverse(self, dag: DAGCircuit):
partitions = []
chunk = []
max_index = len(gate_cancel_run) - 1
for i in range(len(gate_cancel_run)):
if gate_cancel_run[i].op == gate:
chunk.append(gate_cancel_run[i])
for i, cancel_gate in enumerate(gate_cancel_run):
if cancel_gate.op == gate:
chunk.append(cancel_gate)
else:
if chunk:
partitions.append(chunk)
chunk = []
continue
if i == max_index or gate_cancel_run[i].qargs != gate_cancel_run[i + 1].qargs:
if i == max_index or cancel_gate.qargs != gate_cancel_run[i + 1].qargs:
partitions.append(chunk)
chunk = []
# Remove an even number of gates from each chunk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def _find_forward_candidates(self, node_id_t):
"""
matches = []

for i in range(0, len(self.match)):
matches.append(self.match[i][0])
for match in self.match:
matches.append(match[0])

pred = matches.copy()
if len(pred) > 1:
Expand Down
7 changes: 4 additions & 3 deletions qiskit/transpiler/passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _finalize_layouts(self, dag):
# Ordered list of original qubits
original_qubits_reverse = {v: k for k, v in original_qubit_indices.items()}
original_qubits = []
# pylint: disable-next=consider-using-enumerate
for i in range(len(original_qubits_reverse)):
original_qubits.append(original_qubits_reverse[i])

Expand All @@ -139,7 +140,7 @@ def _finalize_layouts(self, dag):
self.property_set["layout"] = t_initial_layout
self.property_set["final_layout"] = new_final_layout

def append(
def append( # pylint:disable=arguments-renamed
self,
passes: Task | list[Task],
) -> None:
Expand All @@ -153,7 +154,7 @@ def append(
"""
super().append(tasks=passes)

def replace(
def replace( # pylint:disable=arguments-renamed
self,
index: int,
passes: Task | list[Task],
Expand All @@ -167,7 +168,7 @@ def replace(
super().replace(index, tasks=passes)

# pylint: disable=arguments-differ
def run(
def run( # pylint:disable=arguments-renamed
self,
circuits: _CircuitsT,
output_name: str | None = None,
Expand Down
37 changes: 16 additions & 21 deletions qiskit/visualization/bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ def plot_axes_labels(self):
def plot_vectors(self):
"""Plot vector"""
# -X and Y data are switched for plotting purposes
for k in range(len(self.vectors)):
for k, vector in enumerate(self.vectors):

xs3d = self.vectors[k][1] * np.array([0, 1])
ys3d = -self.vectors[k][0] * np.array([0, 1])
zs3d = self.vectors[k][2] * np.array([0, 1])
xs3d = vector[1] * np.array([0, 1])
ys3d = -vector[0] * np.array([0, 1])
zs3d = vector[2] * np.array([0, 1])

color = self.vector_color[np.mod(k, len(self.vector_color))]

Expand All @@ -617,15 +617,10 @@ def plot_vectors(self):
def plot_points(self):
"""Plot points"""
# -X and Y data are switched for plotting purposes
for k in range(len(self.points)):
num = len(self.points[k][0])
for k, point in enumerate(self.points):
num = len(point[0])
dist = [
np.sqrt(
self.points[k][0][j] ** 2
+ self.points[k][1][j] ** 2
+ self.points[k][2][j] ** 2
)
for j in range(num)
np.sqrt(point[0][j] ** 2 + point[1][j] ** 2 + point[2][j] ** 2) for j in range(num)
]
if any(abs(dist - dist[0]) / dist[0] > 1e-12):
# combine arrays so that they can be sorted together
Expand All @@ -637,9 +632,9 @@ def plot_points(self):
indperm = np.arange(num)
if self.point_style[k] == "s":
self.axes.scatter(
np.real(self.points[k][1][indperm]),
-np.real(self.points[k][0][indperm]),
np.real(self.points[k][2][indperm]),
np.real(point[1][indperm]),
-np.real(point[0][indperm]),
np.real(point[2][indperm]),
s=self.point_size[np.mod(k, len(self.point_size))],
alpha=1,
edgecolor=None,
Expand All @@ -656,9 +651,9 @@ def plot_points(self):
marker = self.point_marker[np.mod(k, len(self.point_marker))]
pnt_size = self.point_size[np.mod(k, len(self.point_size))]
self.axes.scatter(
np.real(self.points[k][1][indperm]),
-np.real(self.points[k][0][indperm]),
np.real(self.points[k][2][indperm]),
np.real(point[1][indperm]),
-np.real(point[0][indperm]),
np.real(point[2][indperm]),
s=pnt_size,
alpha=1,
edgecolor=None,
Expand All @@ -670,9 +665,9 @@ def plot_points(self):
elif self.point_style[k] == "l":
color = self.point_color[np.mod(k, len(self.point_color))]
self.axes.plot(
np.real(self.points[k][1]),
-np.real(self.points[k][0]),
np.real(self.points[k][2]),
np.real(point[1]),
-np.real(point[0]),
np.real(point[2]),
alpha=0.75,
zdir="z",
color=color,
Expand Down
2 changes: 1 addition & 1 deletion test/python/circuit/test_unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_qobj_with_unitary_matrix(self):
class NumpyEncoder(json.JSONEncoder):
"""Class for encoding json str with complex and numpy arrays."""

def default(self, obj):
def default(self, obj): # pylint:disable=arguments-renamed
if isinstance(obj, numpy.ndarray):
return obj.tolist()
if isinstance(obj, complex):
Expand Down
2 changes: 1 addition & 1 deletion test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,7 @@ def max_circuits(self):
def _default_options(cls):
return Options(shots=1024)

def run(self, circuit, **kwargs):
def run(self, circuit, **kwargs): # pylint:disable=arguments-renamed
raise NotImplementedError

self.backend = FakeMultiChip()
Expand Down
6 changes: 3 additions & 3 deletions test/python/synthesis/test_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ def assertDebugOnly(self): # FIXME: when at python 3.10+ replace with assertNoL
"""Context manager, asserts log is emitted at level DEBUG but no higher"""
with self.assertLogs("qiskit.synthesis", "DEBUG") as ctx:
yield
for i in range(len(ctx.records)):
for i, record in enumerate(ctx.records):
self.assertLessEqual(
ctx.records[i].levelno,
record.levelno,
logging.DEBUG,
msg=f"Unexpected logging entry: {ctx.output[i]}",
)
self.assertIn("Requested fidelity:", ctx.records[i].getMessage())
self.assertIn("Requested fidelity:", record.getMessage())

def assertRoundTrip(self, weyl1: TwoQubitWeylDecomposition):
"""Fail if eval(repr(weyl1)) not equal to weyl1"""
Expand Down

0 comments on commit 0c671dd

Please sign in to comment.