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

[WIP] Fix memory usage issues in BasisTranslator, BarrierBeforeFinalMeasurements, DAGFixedPoint and Decompose transpiler passes, fixes issue #7485 #7989

Closed
wants to merge 5 commits 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
23 changes: 17 additions & 6 deletions qiskit/transpiler/passes/basis/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
self.gates_to_decompose = gate
else:
self.gates_to_decompose = gates_to_decompose
self._make_gate_lists()

@property
def gate(self) -> Gate:
Expand Down Expand Up @@ -74,6 +75,19 @@ def gate(self, value):
stacklevel=2,
)
self.gates_to_decompose = value
self._make_gate_lists()

def _make_gate_lists(self):
"""Make comparison lists for the gate list"""
if not isinstance(self.gates_to_decompose, list):
gates = [self.gates_to_decompose]
else:
gates = self.gates_to_decompose

self._strings_list, self._gate_type_list = [], []
if gates is not None:
self._strings_list = [s for s in gates if isinstance(s, str)]
self._gate_type_list = [g for g in gates if isinstance(g, type)]

def run(self, dag: DAGCircuit) -> DAGCircuit:
"""Run the Decompose pass on `dag`.
Expand Down Expand Up @@ -114,22 +128,19 @@ def _should_decompose(self, node) -> bool:
else:
gates = self.gates_to_decompose

strings_list = [s for s in gates if isinstance(s, str)]
gate_type_list = [g for g in gates if isinstance(g, type)]

if hasattr(node.op, "label") and node.op.label is not None:
has_label = True

if has_label and ( # check if label or label wildcard is given
node.op.label in gates or any(fnmatch(node.op.label, p) for p in strings_list)
node.op.label in gates or any(fnmatch(node.op.label, p) for p in self._strings_list)
):
return True
elif not has_label and ( # check if name or name wildcard is given
node.name in gates or any(fnmatch(node.name, p) for p in strings_list)
node.name in gates or any(fnmatch(node.name, p) for p in self._strings_list)
):
return True
elif not has_label and ( # check if Gate type given
any(isinstance(node.op, op) for op in gate_type_list)
any(isinstance(node.op, op) for op in self._gate_type_list)
):
return True
else:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/passes/utils/dag_fixed_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ def run(self, dag):
else:
fixed_point_reached = self.property_set["_dag_fixed_point_previous_dag"] == dag
self.property_set["dag_fixed_point"] = fixed_point_reached

del self.property_set["_dag_fixed_point_previous_dag"]
self.property_set["_dag_fixed_point_previous_dag"] = deepcopy(dag)
8 changes: 4 additions & 4 deletions qiskit/transpiler/passes/utils/merge_adjacent_barriers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _collect_potential_merges(dag, barriers):
# Start from the first barrier
current_barrier = barriers[0]
end_of_barrier = current_barrier
current_barrier_nodes = [current_barrier]
current_barrier_nodes = set([current_barrier])

current_qubits = set(current_barrier.qargs)
current_ancestors = dag.ancestors(current_barrier)
Expand Down Expand Up @@ -140,7 +140,7 @@ def _collect_potential_merges(dag, barriers):
barrier_to_add = Barrier(len(current_qubits))

end_of_barrier = next_barrier
current_barrier_nodes.append(end_of_barrier)
current_barrier_nodes.add(end_of_barrier)

continue

Expand All @@ -156,10 +156,10 @@ def _collect_potential_merges(dag, barriers):
current_descendants = dag.descendants(next_barrier)

barrier_to_add = Barrier(len(current_qubits))
current_barrier_nodes = []
current_barrier_nodes = set()

end_of_barrier = next_barrier
current_barrier_nodes.append(end_of_barrier)
current_barrier_nodes.add(end_of_barrier)

if barrier_to_add:
node_to_barrier_qubits[end_of_barrier] = current_qubits
Expand Down