Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [
"arguments-renamed",
"broad-exception-raised",
"consider-iterating-dictionary",
"consider-using-dict-items",
"consider-using-enumerate",
"consider-using-f-string",
"nested-min-max",
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 @@ -486,13 +486,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.items() for _, inst_props in qargs.items()
Comment thread
jakelishman marked this conversation as resolved.
Outdated
]
return instruction_properties[index]

Expand Down
7 changes: 3 additions & 4 deletions qiskit/visualization/circuit/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,9 @@ 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]
else:
register, bit_index, reg_index = get_bit_reg_index(self._circuit, wire)
index = bit_index if register is None else reg_index
Comment thread
jakelishman marked this conversation as resolved.
Outdated
Expand Down Expand Up @@ -620,11 +619,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 @@ -641,9 +641,9 @@ def test_circuit_with_aliased_cregs(self, backend):
self.assertEqual(len(result), 1)
data = result[0].data
self.assertEqual(len(astuple(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 @@ -607,9 +607,9 @@ def test_circuit_with_aliased_cregs(self):
self.assertEqual(len(result), 1)
data = result[0].data
self.assertEqual(len(astuple(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