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

Pylint: enable modified-iterating-list and bugfix #10338

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -83,7 +83,6 @@ disable = [
"consider-using-enumerate",
"consider-using-f-string",
"consider-using-from-import",
"modified-iterating-list",
"nested-min-max",
"no-member",
"no-value-for-parameter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _find_forward_candidates(self, node_id_t):

if self.template_dag_dep.direct_successors(node_id_t):
maximal_index = self.template_dag_dep.direct_successors(node_id_t)[-1]
for elem in pred:
for elem in matches:
if elem > maximal_index:
pred.remove(elem)
Comment on lines 149 to 153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me that this is correct, because in the lines just out of sight of this diff, pred is modified such that it's no longer the same as matches. This change could cause an IndexError to be emitted if node_id_t ends up greater than maximal_index (though I don't know if that's possible).

Copy link
Contributor

@jlapeyre jlapeyre Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I read the lines above, but somehow forgot that remove will throw an error if the value is not present. Even if this works because of the nature of the data, I'd say it's too opaque and fragile to write it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as this code is being touched, it might be a good idea to rewrite it a bit. Maybe this:

        matches = [_match[0] for _match in self.match]
        pred = matches.copy()
        pred.sort()

        if direct_successors := self.template_dag_dep.direct_successors(node_id_t):
            maximal_index = direct_successors[-1]
            pred = [_match for _match in matches if _match <= maximal_index]
        else:
            pred = matches.copy()
        if node_id_t in pred:
            pred.remove(node_id_t)


Expand Down Expand Up @@ -268,7 +268,6 @@ def _is_same_q_conf(self, node_circuit, node_template):
"""

if isinstance(node_circuit.op, ControlledGate):

c_template = node_template.op.num_ctrl_qubits

if c_template == 1:
Expand All @@ -279,7 +278,6 @@ def _is_same_q_conf(self, node_circuit, node_template):
control_qubits_circuit = self.qarg_indices[:c_template]

if set(control_qubits_circuit) == set(control_qubits_template):

target_qubits_template = node_template.qindices[c_template::]
target_qubits_circuit = self.qarg_indices[c_template::]

Expand Down Expand Up @@ -347,7 +345,6 @@ def run_forward_match(self):

# While the list of matched nodes is not empty
while self.matched_nodes_list:

# Return first element of the matched_nodes_list and removes it from the list
v_first = self._get_node_forward(0)
self._remove_node_forward(0)
Expand Down Expand Up @@ -386,7 +383,6 @@ def run_forward_match(self):

# For loop over the candidates (template) to find a match.
for i in self.candidates:

# Break the for loop if a match is found.
if match:
break
Expand All @@ -411,7 +407,6 @@ def run_forward_match(self):
and self._is_same_c_conf(node_circuit, node_template)
and self._is_same_op(node_circuit, node_template)
):

v[1].matchedwith = [i]

self.template_dag_dep.get_node(i).matchedwith = [label]
Expand Down