qldpc 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qldpc/__init__.py +17 -0
- qldpc/_util.py +68 -0
- qldpc/_util_test.py +54 -0
- qldpc/abstract/__init__.py +68 -0
- qldpc/abstract/groups.py +1022 -0
- qldpc/abstract/groups_test.py +314 -0
- qldpc/abstract/linalg.py +192 -0
- qldpc/abstract/linalg_test.py +122 -0
- qldpc/abstract/rings.py +1146 -0
- qldpc/abstract/rings_test.py +318 -0
- qldpc/abstract/wedderburn_artin.py +918 -0
- qldpc/abstract/wedderburn_artin_test.py +172 -0
- qldpc/cache.py +103 -0
- qldpc/cache_test.py +70 -0
- qldpc/circuits/__init__.py +101 -0
- qldpc/circuits/benchmarking.py +430 -0
- qldpc/circuits/benchmarking_test.py +152 -0
- qldpc/circuits/bookkeeping.py +292 -0
- qldpc/circuits/bookkeeping_test.py +97 -0
- qldpc/circuits/common.py +181 -0
- qldpc/circuits/common_test.py +113 -0
- qldpc/circuits/encoding.py +311 -0
- qldpc/circuits/encoding_test.py +169 -0
- qldpc/circuits/memory/__init__.py +27 -0
- qldpc/circuits/memory/alpha_syndrome.py +377 -0
- qldpc/circuits/memory/alpha_syndrome_test.py +83 -0
- qldpc/circuits/memory/memory.py +550 -0
- qldpc/circuits/memory/memory_test.py +112 -0
- qldpc/circuits/memory/syndrome_measurement.py +193 -0
- qldpc/circuits/memory/syndrome_measurement_test.py +127 -0
- qldpc/circuits/noise_model.py +1873 -0
- qldpc/circuits/noise_model_test.py +1206 -0
- qldpc/circuits/transversal.py +499 -0
- qldpc/circuits/transversal_test.py +149 -0
- qldpc/codes/__init__.py +101 -0
- qldpc/codes/classical.py +409 -0
- qldpc/codes/classical_test.py +122 -0
- qldpc/codes/common.py +3586 -0
- qldpc/codes/common_test.py +897 -0
- qldpc/codes/distance.py +351 -0
- qldpc/codes/distance_test.py +622 -0
- qldpc/codes/quantum.py +2558 -0
- qldpc/codes/quantum_test.py +795 -0
- qldpc/conftest.py +54 -0
- qldpc/decoders/__init__.py +75 -0
- qldpc/decoders/custom.py +1031 -0
- qldpc/decoders/custom_test.py +374 -0
- qldpc/decoders/dems.py +614 -0
- qldpc/decoders/dems_test.py +314 -0
- qldpc/decoders/retrieval.py +332 -0
- qldpc/decoders/retrieval_test.py +82 -0
- qldpc/decoders/sinter.py +793 -0
- qldpc/decoders/sinter_test.py +250 -0
- qldpc/external/__init__.py +3 -0
- qldpc/external/codes.py +196 -0
- qldpc/external/codes_test.py +88 -0
- qldpc/external/gap.py +191 -0
- qldpc/external/gap_test.py +161 -0
- qldpc/external/groups.py +657 -0
- qldpc/external/groups_test.py +292 -0
- qldpc/math.py +363 -0
- qldpc/math_test.py +134 -0
- qldpc/objects.py +582 -0
- qldpc/objects_test.py +154 -0
- qldpc/py.typed +0 -0
- qldpc-0.3.3.dist-info/METADATA +163 -0
- qldpc-0.3.3.dist-info/RECORD +68 -0
- qldpc-0.3.3.dist-info/WHEEL +4 -0
qldpc/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
|
|
3
|
+
from . import abstract, cache, circuits, codes, decoders, external, math, objects
|
|
4
|
+
|
|
5
|
+
__version__ = importlib.metadata.version("qldpc")
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"__version__",
|
|
9
|
+
"abstract",
|
|
10
|
+
"cache",
|
|
11
|
+
"circuits",
|
|
12
|
+
"codes",
|
|
13
|
+
"decoders",
|
|
14
|
+
"external",
|
|
15
|
+
"math",
|
|
16
|
+
"objects",
|
|
17
|
+
]
|
qldpc/_util.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Miscellaneous internal utilities.
|
|
2
|
+
|
|
3
|
+
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import importlib.util
|
|
21
|
+
import sys
|
|
22
|
+
from collections.abc import Callable
|
|
23
|
+
from types import ModuleType
|
|
24
|
+
from typing import TYPE_CHECKING, TypeVar
|
|
25
|
+
|
|
26
|
+
CallableType = TypeVar("CallableType", bound=Callable[..., object])
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def lazy_import(name: str) -> ModuleType:
|
|
30
|
+
"""Import a module lazily, deferring its execution until its first attribute access.
|
|
31
|
+
|
|
32
|
+
Uses importlib.util.LazyLoader so a heavy but rarely-used dependency stays out of ``import
|
|
33
|
+
qldpc`` while call sites keep using ``module.attr`` exactly as if it had been imported eagerly.
|
|
34
|
+
"""
|
|
35
|
+
if (module := sys.modules.get(name)) is not None:
|
|
36
|
+
return module
|
|
37
|
+
spec = importlib.util.find_spec(name)
|
|
38
|
+
assert spec is not None and spec.loader is not None
|
|
39
|
+
spec.loader = importlib.util.LazyLoader(spec.loader)
|
|
40
|
+
module = importlib.util.module_from_spec(spec)
|
|
41
|
+
sys.modules[name] = module
|
|
42
|
+
spec.loader.exec_module(module)
|
|
43
|
+
return module
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# networkx is loaded lazily to keep it and its ~110 ms import out of ``import qldpc``.
|
|
47
|
+
# Call sites import it as ``from qldpc._util import networkx as nx``.
|
|
48
|
+
if TYPE_CHECKING:
|
|
49
|
+
import networkx
|
|
50
|
+
else:
|
|
51
|
+
networkx = lazy_import("networkx")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def format_docstring(**substitutions: object) -> Callable[[CallableType], CallableType]:
|
|
55
|
+
"""Substitute named values into a function's docstring via str.format.
|
|
56
|
+
|
|
57
|
+
This lets a docstring reference values (such as module-level constants) by name, for example
|
|
58
|
+
"Default: {error_rate}.", without making the docstring an f-string. An f-string cannot be used
|
|
59
|
+
as a docstring: Python evaluates it as an ordinary expression and leaves __doc__ set to None,
|
|
60
|
+
silently discarding the documentation.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def decorator(func: CallableType) -> CallableType:
|
|
64
|
+
if func.__doc__ is not None:
|
|
65
|
+
func.__doc__ = func.__doc__.format(**substitutions)
|
|
66
|
+
return func
|
|
67
|
+
|
|
68
|
+
return decorator
|
qldpc/_util_test.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Unit tests for _util.py.
|
|
2
|
+
|
|
3
|
+
Copyright 2023 The qLDPC Authors and Infleqtion Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import sys
|
|
19
|
+
from types import ModuleType
|
|
20
|
+
|
|
21
|
+
from qldpc._util import format_docstring, lazy_import
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_lazy_import() -> None:
|
|
25
|
+
"""A lazily imported module is only executed on first attribute access."""
|
|
26
|
+
name = "colorsys" # a small stdlib module not otherwise imported by the test suite
|
|
27
|
+
sys.modules.pop(name, None)
|
|
28
|
+
|
|
29
|
+
module = lazy_import(name) # uncached path
|
|
30
|
+
assert isinstance(module, ModuleType)
|
|
31
|
+
assert callable(module.rgb_to_hls) # force the deferred execution
|
|
32
|
+
|
|
33
|
+
assert lazy_import(name) is module # cached path returns the same module
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_format_docstring() -> None:
|
|
37
|
+
"""Named values are substituted into a docstring."""
|
|
38
|
+
|
|
39
|
+
@format_docstring(value=1e-3, name="tag")
|
|
40
|
+
def func() -> None:
|
|
41
|
+
"""A docstring with a {value} and a {name}."""
|
|
42
|
+
|
|
43
|
+
assert func.__doc__ == "A docstring with a 0.001 and a tag."
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_format_docstring_without_docstring() -> None:
|
|
47
|
+
"""A function without a docstring is left untouched."""
|
|
48
|
+
|
|
49
|
+
@format_docstring(value=1)
|
|
50
|
+
def func() -> None:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
assert func.__doc__ is None
|
|
54
|
+
assert func() is None
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from .groups import (
|
|
2
|
+
PSL,
|
|
3
|
+
SL,
|
|
4
|
+
AbelianGroup,
|
|
5
|
+
AlternatingGroup,
|
|
6
|
+
CyclicGroup,
|
|
7
|
+
DihedralGroup,
|
|
8
|
+
Group,
|
|
9
|
+
GroupMember,
|
|
10
|
+
ProjectiveSpecialLinearGroup,
|
|
11
|
+
QuaternionGroup,
|
|
12
|
+
SmallGroup,
|
|
13
|
+
SpecialLinearGroup,
|
|
14
|
+
SymmetricGroup,
|
|
15
|
+
TrivialGroup,
|
|
16
|
+
get_coefficient_and_exponents,
|
|
17
|
+
iter_monomial_terms,
|
|
18
|
+
resolve_field,
|
|
19
|
+
)
|
|
20
|
+
from .linalg import (
|
|
21
|
+
block_diag,
|
|
22
|
+
get_howell_dual,
|
|
23
|
+
kron,
|
|
24
|
+
matmul,
|
|
25
|
+
)
|
|
26
|
+
from .rings import (
|
|
27
|
+
Element,
|
|
28
|
+
GroupRing,
|
|
29
|
+
Protograph,
|
|
30
|
+
RingArray,
|
|
31
|
+
RingMember,
|
|
32
|
+
)
|
|
33
|
+
from .wedderburn_artin import (
|
|
34
|
+
WedderburnArtinComponentTransformer,
|
|
35
|
+
WedderburnArtinTransformer,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"GF2",
|
|
40
|
+
"PSL",
|
|
41
|
+
"SL",
|
|
42
|
+
"AbelianGroup",
|
|
43
|
+
"AlternatingGroup",
|
|
44
|
+
"CyclicGroup",
|
|
45
|
+
"DihedralGroup",
|
|
46
|
+
"Element",
|
|
47
|
+
"Group",
|
|
48
|
+
"GroupMember",
|
|
49
|
+
"GroupRing",
|
|
50
|
+
"ProjectiveSpecialLinearGroup",
|
|
51
|
+
"Protograph",
|
|
52
|
+
"QuaternionGroup",
|
|
53
|
+
"RingArray",
|
|
54
|
+
"RingMember",
|
|
55
|
+
"SmallGroup",
|
|
56
|
+
"SpecialLinearGroup",
|
|
57
|
+
"SymmetricGroup",
|
|
58
|
+
"TrivialGroup",
|
|
59
|
+
"WedderburnArtinComponentTransformer",
|
|
60
|
+
"WedderburnArtinTransformer",
|
|
61
|
+
"block_diag",
|
|
62
|
+
"get_coefficient_and_exponents",
|
|
63
|
+
"get_howell_dual",
|
|
64
|
+
"iter_monomial_terms",
|
|
65
|
+
"kron",
|
|
66
|
+
"matmul",
|
|
67
|
+
"resolve_field",
|
|
68
|
+
]
|