pelagos-decoder 0.1.0__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.
- pelagos/__init__.py +34 -0
- pelagos/_process_worker.py +56 -0
- pelagos/adapter.py +858 -0
- pelagos/autotune.py +793 -0
- pelagos/decoder.py +3891 -0
- pelagos/graph.py +479 -0
- pelagos/kernels.py +2208 -0
- pelagos/process.py +287 -0
- pelagos/stim/__init__.py +11 -0
- pelagos/stim/sinter/__init__.py +11 -0
- pelagos/stim/sinter/check_matrices.py +112 -0
- pelagos/utils.py +995 -0
- pelagos_decoder-0.1.0.dist-info/METADATA +317 -0
- pelagos_decoder-0.1.0.dist-info/RECORD +16 -0
- pelagos_decoder-0.1.0.dist-info/WHEEL +4 -0
- pelagos_decoder-0.1.0.dist-info/licenses/LICENSE +201 -0
pelagos/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# (C) Copyright IBM 2025, 2026
|
|
2
|
+
#
|
|
3
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
4
|
+
# obtain a copy of this license in the LICENSE file in the root directory
|
|
5
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
#
|
|
7
|
+
# Any modifications or derivative works of this code must retain this
|
|
8
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
9
|
+
# that they have been altered from the originals.
|
|
10
|
+
"""Triton GPU backend for relay bp library.
|
|
11
|
+
|
|
12
|
+
This module provides GPU-accelerated implementations of the relay BP algorithm
|
|
13
|
+
using Triton kernels, with interfaces compatible with the Rust implementation.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
# Import the core Triton decoder
|
|
17
|
+
from .decoder import RelayBPDecoder
|
|
18
|
+
|
|
19
|
+
# Import adapter classes that provide Rust-compatible interfaces
|
|
20
|
+
from .adapter import RelayDecoder, ObservableDecoderRunner
|
|
21
|
+
|
|
22
|
+
# Re-export with Rust-compatible names for seamless integration
|
|
23
|
+
# These provide the same interface as the Rust RelayDecoderF32/F64 classes
|
|
24
|
+
RelayDecoderF32 = RelayDecoder
|
|
25
|
+
RelayDecoderF64 = RelayDecoder # Same implementation, dtype controlled by constructor
|
|
26
|
+
|
|
27
|
+
# For compatibility with existing code that expects these names
|
|
28
|
+
__all__ = [
|
|
29
|
+
"RelayBPDecoder", # Core Triton implementation
|
|
30
|
+
"RelayDecoder", # Adapter with Rust-compatible interface
|
|
31
|
+
"ObservableDecoderRunner", # Observable decoder adapter
|
|
32
|
+
"RelayDecoderF32", # Rust-compatible name for fp32
|
|
33
|
+
"RelayDecoderF64", # Rust-compatible name for fp64
|
|
34
|
+
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright (c) 2026 Advanced Micro Devices, Inc.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Private subprocess entry point; visibility is set before interpreter startup."""
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import traceback
|
|
7
|
+
from multiprocessing import shared_memory, resource_tracker
|
|
8
|
+
from multiprocessing.connection import Connection
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
import torch
|
|
12
|
+
|
|
13
|
+
from .decoder import RelayBPDecoder
|
|
14
|
+
from .process import validate_payload
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main():
|
|
18
|
+
conn = Connection(int(sys.argv[1]))
|
|
19
|
+
try:
|
|
20
|
+
torch.set_num_threads(max(1, int(os.environ.get("PELAGOS_WORKER_THREADS", "2"))))
|
|
21
|
+
ctor = conn.recv()
|
|
22
|
+
decoder = RelayBPDecoder(**ctor, device=[0])
|
|
23
|
+
conn.send(("ready", {"wj": decoder.wj.detach().cpu().numpy()}))
|
|
24
|
+
while True:
|
|
25
|
+
syndromes, spec = conn.recv()
|
|
26
|
+
output = decoder.decode(torch.from_numpy(syndromes))
|
|
27
|
+
torch.cuda.synchronize()
|
|
28
|
+
payload = {}
|
|
29
|
+
for key, value in output.items():
|
|
30
|
+
if key == "errors" and spec is not None:
|
|
31
|
+
name, shape, start, end = spec
|
|
32
|
+
shared = shared_memory.SharedMemory(name=name)
|
|
33
|
+
# A subprocess has its own resource tracker. The parent alone
|
|
34
|
+
# owns unlink; otherwise an exiting worker unlinks live output.
|
|
35
|
+
resource_tracker.unregister(shared._name, "shared_memory")
|
|
36
|
+
try:
|
|
37
|
+
target = np.ndarray(shape, dtype=np.uint8, buffer=shared.buf)[start:end]
|
|
38
|
+
if tuple(value.shape) != target.shape or value.dtype != torch.uint8:
|
|
39
|
+
raise ValueError("shared error output shape/dtype mismatch")
|
|
40
|
+
torch.from_numpy(target).copy_(value.detach())
|
|
41
|
+
finally:
|
|
42
|
+
shared.close()
|
|
43
|
+
else:
|
|
44
|
+
payload[key] = value.detach().cpu().contiguous().numpy()
|
|
45
|
+
validate_payload(payload)
|
|
46
|
+
conn.send(("ok", payload))
|
|
47
|
+
except EOFError:
|
|
48
|
+
pass
|
|
49
|
+
except BaseException:
|
|
50
|
+
conn.send(("error", traceback.format_exc()))
|
|
51
|
+
finally:
|
|
52
|
+
conn.close()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
main()
|