Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing consider-using-dict-items from lint exclusions and updates #12288

Merged
Merged
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ We provide more detail on [the release and support schedule of Qiskit in our doc
## Reporting a Vulnerability

To report vulnerabilities, you can privately report a potential security issue
via the Github security vulnerabilities feature. This can be done here:
via the GitHub security vulnerabilities feature. This can be done here:

https://github.com/Qiskit/qiskit/security/advisories

Please do **not** open a public issue about a potential security vulnerability.

You can find more details on the security vulnerability feature in the Github
You can find more details on the security vulnerability feature in the GitHub
documentation here:

https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ disable = [
# with the rationale
"arguments-renamed",
"broad-exception-raised",
"consider-using-dict-items",
"consider-using-enumerate",
"consider-using-f-string",
"no-member",
Expand Down
4 changes: 2 additions & 2 deletions qiskit/dagcircuit/collect_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def run(self, block):
self.group[self.find_leader(first)].append(node)

blocks = []
for index in self.leader:
if self.leader[index] == index:
for index, item in self.leader.items():
if index == item:
blocks.append(self.group[index])

return blocks
Expand Down
4 changes: 2 additions & 2 deletions qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@ def run(
from qiskit.compiler import assemble

out_options = {}
for key in backend_options:
for key, value in backend_options.items():
if not hasattr(self.options, key):
warnings.warn(
"Option %s is not used by this backend" % key, UserWarning, stacklevel=2
)
else:
out_options[key] = backend_options[key]
out_options[key] = value
qobj = assemble(run_input, self, **out_options)
qobj_options = qobj.config
self._set_options(qobj_config=qobj_options, backend_options=backend_options)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/providers/models/backendconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,9 @@ def get_qubit_channels(self, qubit: Union[int, Iterable[int]]) -> List[Channel]:
channels = set()
try:
if isinstance(qubit, int):
for key in self._qubit_channel_map.keys():
for key, value in self._qubit_channel_map.items():
if qubit in key:
channels.update(self._qubit_channel_map[key])
channels.update(value)
if len(channels) == 0:
raise KeyError
elif isinstance(qubit, list):
Expand Down
16 changes: 8 additions & 8 deletions qiskit/providers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,24 @@ def set_validator(self, field, validator_value):

def update_options(self, **fields):
"""Update options with kwargs"""
for field in fields:
field_validator = self.validator.get(field, None)
for field_name, field in fields.items():
field_validator = self.validator.get(field_name, None)
if isinstance(field_validator, tuple):
if fields[field] > field_validator[1] or fields[field] < field_validator[0]:
if field > field_validator[1] or field < field_validator[0]:
raise ValueError(
f"Specified value for '{field}' is not a valid value, "
f"Specified value for '{field_name}' is not a valid value, "
f"must be >={field_validator[0]} or <={field_validator[1]}"
)
elif isinstance(field_validator, list):
if fields[field] not in field_validator:
if field not in field_validator:
raise ValueError(
f"Specified value for {field} is not a valid choice, "
f"Specified value for {field_name} is not a valid choice, "
f"must be one of {field_validator}"
)
elif isinstance(field_validator, type):
if not isinstance(fields[field], field_validator):
if not isinstance(field, field_validator):
raise TypeError(
f"Specified value for {field} is not of required type {field_validator}"
f"Specified value for {field_name} is not of required type {field_validator}"
)

self._fields.update(fields)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/pulse/library/symbolic_pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ def __eq__(self, other: object) -> bool:
if not np.isclose(complex_amp1, complex_amp2):
return False

for key in self.parameters:
if key not in ["amp", "angle"] and self.parameters[key] != other.parameters[key]:
for key, value in self.parameters.items():
if key not in ["amp", "angle"] and value != other.parameters[key]:
return False

return True
Expand Down
8 changes: 4 additions & 4 deletions qiskit/result/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ def __repr__(self):
out += ", seed=%s" % self.seed
if hasattr(self, "meas_return"):
out += ", meas_return=%s" % self.meas_return
for key in self._metadata:
if isinstance(self._metadata[key], str):
value_str = "'%s'" % self._metadata[key]
for key, value in self._metadata.items():
if isinstance(value, str):
value_str = "'%s'" % value
else:
value_str = repr(self._metadata[key])
value_str = repr(value)
out += f", {key}={value_str}"
out += ")"
return out
Expand Down
8 changes: 4 additions & 4 deletions qiskit/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def __repr__(self):
)
)
out += f", date={self.date}, status={self.status}, header={self.header}"
for key in self._metadata:
if isinstance(self._metadata[key], str):
value_str = "'%s'" % self._metadata[key]
for key, value in self._metadata.items():
if isinstance(value, str):
value_str = "'%s'" % value
else:
value_str = repr(self._metadata[key])
value_str = repr(value)
out += f", {key}={value_str}"
out += ")"
return out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def collect_key(x):
prev = bit
self.gate_groups[self.find_set(prev)].append(nd)
# need to turn all groups that still exist into their own blocks
for index in self.parent:
if self.parent[index] == index and len(self.gate_groups[index]) != 0:
for index, item in self.parent.items():
if item == index and len(self.gate_groups[index]) != 0:
block_list.append(self.gate_groups[index][:])

self.property_set["block_list"] = block_list
Expand Down
6 changes: 4 additions & 2 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,9 @@ def instructions(self):
is globally defined.
"""
return [
(self._gate_name_map[op], qarg) for op in self._gate_map for qarg in self._gate_map[op]
(self._gate_name_map[op], qarg)
for op, qargs in self._gate_map.items()
for qarg in qargs
]

def instruction_properties(self, index):
Expand Down Expand Up @@ -979,7 +981,7 @@ def instruction_properties(self, index):
InstructionProperties: The instruction properties for the specified instruction tuple
"""
instruction_properties = [
inst_props for op in self._gate_map for _, inst_props in self._gate_map[op].items()
inst_props for qargs in self._gate_map.values() for inst_props in qargs.values()
]
return instruction_properties[index]

Expand Down
23 changes: 14 additions & 9 deletions qiskit/visualization/circuit/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,22 @@ def _initialize_latex_array(self):
self._latex.append([" "] * (self._img_depth + 1))

# display the bit/register labels
for wire in self._wire_map:
for wire, index in self._wire_map.items():
if isinstance(wire, ClassicalRegister):
register = wire
index = self._wire_map[wire]
wire_label = get_wire_label(
"latex", register, index, layout=self._layout, cregbundle=self._cregbundle
)
else:
register, bit_index, reg_index = get_bit_reg_index(self._circuit, wire)
index = bit_index if register is None else reg_index
wire_label = get_wire_label(
"latex",
register,
bit_index if register is None else reg_index,
layout=self._layout,
cregbundle=self._cregbundle,
)

wire_label = get_wire_label(
"latex", register, index, layout=self._layout, cregbundle=self._cregbundle
)
wire_label += " : "
if self._initial_state:
wire_label += "\\ket{{0}}" if isinstance(wire, Qubit) else "0"
Expand All @@ -234,7 +239,7 @@ def _initialize_latex_array(self):
self._latex[pos][1] = "\\lstick{/_{_{" + str(register.size) + "}}} \\cw"
wire_label = f"\\mathrm{{{wire_label}}}"
else:
pos = self._wire_map[wire]
pos = index
self._latex[pos][0] = "\\nghost{" + wire_label + " & " + "\\lstick{" + wire_label

def _get_image_depth(self):
Expand Down Expand Up @@ -620,11 +625,11 @@ def _add_condition(self, op, wire_list, col):
# First sort the val_bits in the order of the register bits in the circuit
cond_wires = []
cond_bits = []
for wire in self._wire_map:
for wire, index in self._wire_map.items():
reg, _, reg_index = get_bit_reg_index(self._circuit, wire)
if reg == cond_reg:
cond_bits.append(reg_index)
cond_wires.append(self._wire_map[wire])
cond_wires.append(index)

gap = cond_wires[0] - max(wire_list)
prev_wire = cond_wires[0]
Expand Down
3 changes: 1 addition & 2 deletions qiskit/visualization/circuit/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,9 @@ def wire_names(self, with_initial_state=False):

self._wire_map = get_wire_map(self._circuit, (self.qubits + self.clbits), self.cregbundle)
wire_labels = []
for wire in self._wire_map:
for wire, index in self._wire_map.items():
if isinstance(wire, ClassicalRegister):
register = wire
index = self._wire_map[wire]
else:
register, bit_index, reg_index = get_bit_reg_index(self._circuit, wire)
index = bit_index if register is None else reg_index
Expand Down
4 changes: 2 additions & 2 deletions test/python/primitives/test_backend_sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ def test_circuit_with_aliased_cregs(self, backend):
self.assertEqual(len(result), 1)
data = result[0].data
self.assertEqual(len(data), 3)
for creg_name in target:
for creg_name, creg in target.items():
self.assertTrue(hasattr(data, creg_name))
self._assert_allclose(getattr(data, creg_name), np.array(target[creg_name]))
self._assert_allclose(getattr(data, creg_name), np.array(creg))

@combine(backend=BACKENDS)
def test_no_cregs(self, backend):
Expand Down
4 changes: 2 additions & 2 deletions test/python/primitives/test_statevector_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ def test_circuit_with_aliased_cregs(self):
self.assertEqual(len(result), 1)
data = result[0].data
self.assertEqual(len(data), 3)
for creg_name in target:
for creg_name, creg in target.items():
self.assertTrue(hasattr(data, creg_name))
self._assert_allclose(getattr(data, creg_name), np.array(target[creg_name]))
self._assert_allclose(getattr(data, creg_name), np.array(creg))

def test_no_cregs(self):
"""Test that the sampler works when there are no classical register in the circuit."""
Expand Down
Loading