Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into Issue-434
Browse files Browse the repository at this point in the history
Updating with master to include distance fixes
  • Loading branch information
drewvandeth committed Sep 16, 2024
2 parents bfe7a0c + 3b62430 commit f9fc8a3
Show file tree
Hide file tree
Showing 47 changed files with 548 additions and 577 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.extlinks",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
"nbsphinx",
"matplotlib.sphinxext.plot_directive",
Expand Down
128 changes: 67 additions & 61 deletions docs/how_tos/1-how-to-create-codes.ipynb

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions docs/how_tos/2-how-to-work-with-shape-objects.ipynb

Large diffs are not rendered by default.

69 changes: 0 additions & 69 deletions docs/tutorials/1-tutorial-example.ipynb

This file was deleted.

208 changes: 104 additions & 104 deletions docs/tutorials/QEC_Framework_IEEE_2022.ipynb

Large diffs are not rendered by default.

199 changes: 0 additions & 199 deletions docs/tutorials/how-to-use-union-find.ipynb

This file was deleted.

4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ sphinx-autodoc-typehints
nbsphinx
ddt~=1.4.2
matplotlib>=3.3.0
black[jupyter]~=22.1
black[jupyter]
pandoc
pylatexenc
2 changes: 2 additions & 0 deletions src/qiskit_qec/analysis/distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <set>
#include <exception>
#include <iterator>
#include <iostream>
#include <cassert>

#include "linear.h"
#include "combinations.h"
Expand Down
25 changes: 22 additions & 3 deletions src/qiskit_qec/analysis/distance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compute code distance."""

from typing import List
from itertools import combinations, product
import functools
Expand Down Expand Up @@ -28,6 +29,8 @@ def _distance_test(stab: np.ndarray, logic_op: np.ndarray, weight: int) -> bool:
Pauli operators on n qubits are represented as integer numpy arrays
of length 2n in the order [X-part, Z-part].
Restrictions: n < 63 to avoid overflows in numpy
Returns True or False.
"""
# number of qubits
Expand Down Expand Up @@ -94,6 +97,8 @@ def _minimum_distance_2_python(stabilizer: np.ndarray, gauge: np.ndarray, max_we
Second method based on parititioning errors.
Restrictions: n < 63 to avoid overflows in numpy
Returns the minimum distance of the code, or 0 if greater than max_weight.
"""
if symplectic.is_stabilizer_group(gauge):
Expand All @@ -109,17 +114,21 @@ def _minimum_distance_2_python(stabilizer: np.ndarray, gauge: np.ndarray, max_we
zl = np.setdiff1d(zp_rows, z_rows).view(zp.dtype).reshape(-1, zp.shape[1])
if xl.shape[0] == 0: # k = 0, fall back to first method
return _minimum_distance_1_python(stabilizer, gauge, max_weight)

weight = max_weight + 1

for row in range(xl.shape[0]):
for w in range(1, max_weight + 1):
if _distance_test(stabilizer.astype(int), xl[row].astype(int), w):
if _distance_test(stabilizer.astype(int), xl[row].astype(int), w) is True:
weight = min(weight, w)
break

for row in range(zl.shape[0]):
for w in range(1, max_weight + 1):
if _distance_test(stabilizer.astype(int), zl[row].astype(int), w):
if _distance_test(stabilizer.astype(int), zl[row].astype(int), w) is True:
weight = min(weight, w)
break

if weight < max_weight + 1:
return weight
else:
Expand Down Expand Up @@ -223,7 +232,7 @@ def _minimum_distance_2_compiled(stabilizer: np.ndarray, gauge: np.ndarray, max_
def minimum_distance(
stabilizer_or_gauge: np.ndarray,
max_weight: int = 10,
method: str = "enumerate",
method: str = "partition",
try_compiled: bool = True,
) -> int:
"""Minimum distance of (subsystem) stabilizer code.
Expand All @@ -233,6 +242,12 @@ def minimum_distance(
method and try_compiled select an algorithm and implementation.
Restrictions:
Partition: Current methods require n-k < 63
Enumerate: None, although very slow for larger n
Returns the minimum distance of the code, or 0 if greater than max_weight.
"""
method_enumerate: str = "enumerate"
Expand All @@ -253,11 +268,15 @@ def minimum_distance(
if method == method_enumerate:
distance = _c_minimum_distance(inputform1, inputform2, max_weight)
elif method == method_partition:
if method == method_partition and not stabilizer.shape[0] < 63:
raise QiskitQECError(f"Compiled method {method} only supports n-k < 63.")
distance = _minimum_distance_2_compiled(stabilizer, gauge, max_weight)
else:
logger.exception("from compiled extension was not loaded: switching to no compiled")
if method == method_enumerate:
distance = _minimum_distance_1_python(stabilizer, gauge, max_weight)
elif method == method_partition:
if method == method_partition and not stabilizer.shape[0] < 63:
raise QiskitQECError(f"Python method {method} only supports n-k < 63.")
distance = _minimum_distance_2_python(stabilizer, gauge, max_weight)
return distance
1 change: 1 addition & 0 deletions src/qiskit_qec/analysis/faultsampler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Quantum circuit fault path sampler."""

from typing import Tuple, List

import numpy as np
Expand Down
Loading

0 comments on commit f9fc8a3

Please sign in to comment.