Skip to content

Commit

Permalink
speed up decoding for linear arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumjim committed Dec 1, 2023
1 parent 1cfed9b commit c5e41d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/qiskit_qec/circuits/repetition_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ def _get_cycles(self):
self.degree = {}
for n, q in enumerate(self.link_graph.nodes()):
self.degree[q] = self.link_graph.degree(n)
degrees = list(self.degree.values())
self._linear = degrees.count(1) == 2 and degrees.count(2) == len(degrees) - 2
lg_edges = set(self.link_graph.edge_list())
lg_nodes = self.link_graph.nodes()
ng = nx.Graph()
Expand Down Expand Up @@ -1360,8 +1362,11 @@ def is_cluster_neutral(self, atypical_nodes: dict):
Args:
atypical_nodes: dictionary in the form of the return value of string2nodes
"""
neutral, logicals, _ = self.check_nodes(atypical_nodes)
return neutral and not logicals
if self._linear:
return not bool(len(atypical_nodes) % 2)
else:
neutral, logicals, _ = self.check_nodes(atypical_nodes)
return neutral and not logicals

def transpile(self, backend, echo=("X", "X"), echo_num=(2, 0)):
"""
Expand Down
5 changes: 4 additions & 1 deletion test/code_circuits/test_rep_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,18 @@ def clustering_decoder_test(
N = 1000

# first an RCC
codes = [RepetitionCode(d, 1)]
codes = []
codes.append(RepetitionCode(d, 1))
# then a linear ARC
links = [(2 * j, 2 * j + 1, 2 * (j + 1)) for j in range(d - 1)]
codes.append(ArcCircuit(links, 0, logical="1"))
self.assertTrue(codes[-1]._linear, "Linear ARC not recognised as such")
# then make a bunch of non-linear ARCs
links_cross = [(2 * j, 2 * j + 1, 2 * (j + 1)) for j in range(d - 2)]
links_cross.append((2 * (d - 2), 2 * (d - 2) + 1, 2 * (int(d / 2))))
links_cross.append(((2 * (int(d / 2))), 2 * (d - 1), 2 * (d - 1) + 1))
codes.append(ArcCircuit(links_cross, 0))
self.assertTrue(not codes[-1]._linear, "Non-inear ARC not recognised as such")
# ladder (works for even d)
half_d = int(d / 2)
links_ladder = []
Expand Down

0 comments on commit c5e41d1

Please sign in to comment.