diff --git a/src/qiskit_qec/circuits/repetition_code.py b/src/qiskit_qec/circuits/repetition_code.py index 89a93cc1..f507b1da 100644 --- a/src/qiskit_qec/circuits/repetition_code.py +++ b/src/qiskit_qec/circuits/repetition_code.py @@ -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() @@ -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)): """ diff --git a/test/code_circuits/test_rep_codes.py b/test/code_circuits/test_rep_codes.py index 7a76430c..8afb6fba 100644 --- a/test/code_circuits/test_rep_codes.py +++ b/test/code_circuits/test_rep_codes.py @@ -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 = []