Skip to content

Commit

Permalink
faster calculation of exact non-binary CSS code distance
Browse files Browse the repository at this point in the history
  • Loading branch information
perlinm committed Jan 31, 2025
1 parent ff53205 commit 70746c9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions qldpc/codes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,11 +1383,15 @@ def get_distance_exact(self, pauli: PauliXZ | None = None) -> int | float:
warnings.warn(
"Computing the exact distance of a non-binary code may take a (very) long time"
)
code_x = self.code_x if pauli == Pauli.X else self.code_z
code_z = self.code_z if pauli == Pauli.X else self.code_x
dual_code_x = ~code_x
nontrivial_ops_x = (word for word in code_z.iter_words() if word not in dual_code_x)
distance = min(np.count_nonzero(word) for word in nontrivial_ops_x)
logical_ops = self.get_logical_ops(pauli).reshape(-1, 2, len(self))[:, pauli, :]
matrix = self.matrix_x if pauli == Pauli.X else self.matrix_z
code_logical_ops = ClassicalCode.from_generator(logical_ops)
code_stabilizers = ClassicalCode.from_generator(matrix)
distance = min(
np.count_nonzero(word_l + word_s)
for word_l in code_logical_ops.iter_words(skip_zero=True)
for word_s in code_stabilizers.iter_words()
)

# save the exact distance and return
if pauli == Pauli.X or self._balanced_codes:
Expand Down

0 comments on commit 70746c9

Please sign in to comment.