Skip to content

Commit

Permalink
Correct coloured_nodes type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mills-cqc committed Dec 9, 2024
1 parent da35910 commit a589f67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions qermit/coherent_pauli_checks/box_clifford_subcircuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _command_is_clifford(command: Command) -> bool:
return False


def _get_clifford_commands(command_list: list[Command]) -> set[int]:
def _get_clifford_commands(command_list: list[Command]) -> list[int]:
"""Given a list of commands, return a set of indexes of that list
corresponding to those commands which are Clifford gates.
Expand All @@ -39,9 +39,9 @@ def _get_clifford_commands(command_list: list[Command]) -> set[int]:
:return: Indexes in the list which correspond to commands in the
list which are Clifford.
"""
return {
return [
i for i, command in enumerate(command_list) if _command_is_clifford(command)
}
]


def _give_nodes_subdag(dag: nx.DiGraph, node_subdag: dict[int, int]) -> list[int]:
Expand Down
12 changes: 5 additions & 7 deletions qermit/coherent_pauli_checks/monochromatic_convex_subdag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from itertools import permutations
from itertools import combinations
from typing import Any

import networkx as nx # type: ignore
Expand Down Expand Up @@ -66,7 +66,7 @@ def _subdag_successors(


def get_monochromatic_convex_subdag(
dag: nx.DiGraph, coloured_nodes: set[Any]
dag: nx.DiGraph, coloured_nodes: list[Any]
) -> dict[Any, int]:
"""Retrieve assignment of coloured nodes to sub-DAGs.
The assignment aims to minimise the number of sub-DAGs.
Expand All @@ -75,7 +75,6 @@ def get_monochromatic_convex_subdag(
:param coloured_nodes: The nodes which are coloured.
:return: Map from node to the sub-DAG to which it belongs.
"""
node_subdag = {node: i for i, node in enumerate(coloured_nodes)}

node_descendants = {node: nx.descendants(dag, node) for node in dag.nodes}
for node in node_descendants.keys():
Expand Down Expand Up @@ -124,15 +123,14 @@ def _can_merge(

return True

node_subdag = {node: i for i, node in enumerate(coloured_nodes)}

subgraph_merged = True
while subgraph_merged:
subgraph_merged = False

# Try to merge all pairs of sub-DAGs
for subdag_one, subdag_two in permutations(node_subdag.values(), 2):
if subdag_one == subdag_two:
continue

for subdag_one, subdag_two in combinations(set(node_subdag.values()), 2):
if _can_merge(
dag=dag,
subdag_one=subdag_one,
Expand Down

0 comments on commit a589f67

Please sign in to comment.