├── .clang-format
├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── BUILD
├── CMakeLists.txt
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── WORKSPACE
├── assets
├── ablated_stabilizers.png
├── cmp_transit_from_prev.png
├── color2surface.png
├── color_code_layouts.png
├── color_code_layouts.svg
├── example_boundary_match.png
├── generated
│ ├── cmp_transit.png
│ ├── compare_X.png
│ ├── compare_XZ.png
│ ├── compare_Z.png
│ ├── midout_error_X.png
│ ├── midout_error_XZ.png
│ ├── midout_error_Z.png
│ ├── midout_footprint_X.png
│ ├── midout_footprint_XZ.png
│ ├── midout_footprint_Z.png
│ ├── phenom.png
│ ├── prev_work_comparison_0.0001.png
│ ├── prev_work_comparison_0.0002.png
│ ├── prev_work_comparison_0.0003.png
│ ├── prev_work_comparison_0.0005.png
│ ├── prev_work_comparison_0.001.png
│ ├── prev_work_comparison_0.002.png
│ ├── stats-xz-combo.csv
│ ├── superdense_error_X.png
│ ├── superdense_error_XZ.png
│ ├── superdense_error_Z.png
│ ├── superdense_footprint_X.png
│ ├── superdense_footprint_XZ.png
│ ├── superdense_footprint_Z.png
│ ├── timing_d.png
│ ├── timing_d_full.png
│ ├── timing_r.png
│ ├── timing_r_full.png
│ ├── timing_rq.png
│ ├── timing_rq_full.png
│ └── toric.png
├── midout-detslice-cycle.png
├── midout-detslice-cycle.svg
├── midout_detectors.svg
├── midout_detectors_2.svg
├── multiplexing.png
├── perf.png
├── pyramid_code.png
├── pyramid_code.svg
├── solved_euclidean_problem.png
├── stats.csv
├── superdense-detslice-cycle.png
├── superdense-detslice-cycle.svg
├── superdense_detectors.svg
├── superdense_detectors_2.svg
└── timing_stats.csv
├── doc
├── chromobius.pyi
├── chromobius_api_reference.md
├── developers.md
└── getting_started.ipynb
├── file_lists
├── perf_files
├── pybind_files
├── source_files_no_main
└── test_files
├── pyproject.toml
├── requirements.txt
├── setup.py
├── src
├── chromobius.h
├── chromobius
│ ├── commands
│ │ ├── main_all.cc
│ │ ├── main_all.h
│ │ ├── main_all.test.cc
│ │ ├── main_all.test.h
│ │ ├── main_benchmark.cc
│ │ ├── main_benchmark.h
│ │ ├── main_benchmark.test.cc
│ │ ├── main_describe_decoder.cc
│ │ ├── main_describe_decoder.h
│ │ ├── main_describe_decoder.test.cc
│ │ ├── main_predict.cc
│ │ ├── main_predict.h
│ │ └── main_predict.test.cc
│ ├── datatypes
│ │ ├── atomic_error.cc
│ │ ├── atomic_error.h
│ │ ├── atomic_error.perf.cc
│ │ ├── atomic_error.test.cc
│ │ ├── color_basis.cc
│ │ ├── color_basis.h
│ │ ├── color_basis.test.cc
│ │ ├── conf.h
│ │ ├── rgb_edge.cc
│ │ ├── rgb_edge.h
│ │ ├── rgb_edge.test.cc
│ │ ├── stim_integration.cc
│ │ ├── stim_integration.h
│ │ ├── stim_integration.test.cc
│ │ ├── xor_vec.h
│ │ └── xor_vec.test.cc
│ ├── decode
│ │ ├── decoder.cc
│ │ ├── decoder.h
│ │ ├── decoder.perf.cc
│ │ ├── decoder.test.cc
│ │ ├── decoder_integration.test.cc
│ │ ├── matcher_interface.h
│ │ ├── pymatcher.cc
│ │ └── pymatcher.h
│ ├── graph
│ │ ├── charge_graph.cc
│ │ ├── charge_graph.h
│ │ ├── charge_graph.test.cc
│ │ ├── choose_rgb_reps.cc
│ │ ├── choose_rgb_reps.h
│ │ ├── choose_rgb_reps.test.cc
│ │ ├── collect_atomic_errors.cc
│ │ ├── collect_atomic_errors.h
│ │ ├── collect_composite_errors.cc
│ │ ├── collect_composite_errors.h
│ │ ├── collect_nodes.cc
│ │ ├── collect_nodes.h
│ │ ├── drag_graph.cc
│ │ ├── drag_graph.h
│ │ ├── drag_graph.test.cc
│ │ ├── euler_tours.cc
│ │ ├── euler_tours.h
│ │ ├── euler_tours.perf.cc
│ │ └── euler_tours.test.cc
│ ├── pybind
│ │ ├── chromobius.pybind.cc
│ │ ├── chromobius_pybind_test.py
│ │ ├── sinter_compat.pybind.cc
│ │ ├── sinter_compat.pybind.h
│ │ └── sinter_compat_pybind_test.py
│ ├── test_util.test.cc
│ ├── test_util.test.h
│ └── util.perf.h
├── clorco
│ ├── __init__.py
│ ├── _circuits_vs_chromobius_test.py
│ ├── _make_circuit.py
│ ├── _make_circuit_params.py
│ ├── _make_circuit_test.py
│ ├── color2surface_code
│ │ ├── __init__.py
│ │ ├── _color2surface_layouts.py
│ │ ├── _color2surface_layouts_test.py
│ │ ├── _draw_mobius_graph.py
│ │ └── _keyed_constructions.py
│ ├── color_code
│ │ ├── __init__.py
│ │ ├── _color_code_layouts.py
│ │ ├── _color_code_layouts_test.py
│ │ ├── _keyed_constructions.py
│ │ ├── _midout_planar_color_code_circuits.py
│ │ ├── _midout_planar_color_code_circuits_test.py
│ │ ├── _mxyz_color_codes.py
│ │ ├── _mxyz_color_codes_test.py
│ │ ├── _superdense_planar_color_code_circuits.py
│ │ ├── _superdense_planar_color_code_circuits_test.py
│ │ ├── _toric_color_code_circuits.py
│ │ └── _toric_color_code_circuits_test.py
│ ├── pyramid_code
│ │ ├── __init__.py
│ │ ├── _keyed_constructions.py
│ │ ├── _pyramid_code_layouts.py
│ │ └── _pyramid_code_layouts_test.py
│ ├── rep_code
│ │ ├── __init__.py
│ │ ├── _keyed_constructions.py
│ │ ├── _keyed_constructions_test.py
│ │ ├── _rep_code_circuits.py
│ │ ├── _rep_code_circuits_test.py
│ │ ├── _rep_code_layouts.py
│ │ └── _rep_code_layouts_test.py
│ └── surface_code
│ │ ├── __init__.py
│ │ ├── _keyed_constructions.py
│ │ ├── _surface_code_chunks.py
│ │ ├── _surface_code_chunks_test.py
│ │ ├── _surface_code_layouts.py
│ │ ├── _surface_code_layouts_test.py
│ │ ├── _surface_code_patches.py
│ │ ├── _transversal_cnot.py
│ │ ├── _transversal_cnot_test.py
│ │ ├── _xz_surface_code_memory_circuits.py
│ │ └── _xz_surface_code_memory_circuits_test.py
├── gen
│ ├── __init__.py
│ ├── _circuit_util.py
│ ├── _circuit_util_test.py
│ ├── _core
│ │ ├── __init__.py
│ │ ├── _builder.py
│ │ ├── _builder_test.py
│ │ ├── _keyed_pauli_string.py
│ │ ├── _measurement_tracker.py
│ │ ├── _noise.py
│ │ ├── _noise_test.py
│ │ ├── _patch.py
│ │ ├── _patch_test.py
│ │ ├── _pauli_string.py
│ │ ├── _pauli_string_test.py
│ │ ├── _stabilizer_code.py
│ │ ├── _stabilizer_code_test.py
│ │ ├── _tile.py
│ │ ├── _tile_test.py
│ │ ├── _util.py
│ │ └── _util_test.py
│ ├── _flows
│ │ ├── __init__.py
│ │ ├── _chunk.py
│ │ ├── _chunk_interface.py
│ │ ├── _chunk_loop.py
│ │ ├── _chunk_reflow.py
│ │ ├── _chunk_test.py
│ │ ├── _circuit_util.py
│ │ ├── _flow.py
│ │ ├── _flow_test.py
│ │ ├── _flow_util.py
│ │ ├── _flow_util_test.py
│ │ └── _test_util.py
│ ├── _layers
│ │ ├── __init__.py
│ │ ├── _data.py
│ │ ├── _det_obs_annotation_layer.py
│ │ ├── _empty_layer.py
│ │ ├── _feedback_layer.py
│ │ ├── _feedback_layer_test.py
│ │ ├── _interact_layer.py
│ │ ├── _interact_swap_layer.py
│ │ ├── _iswap_layer.py
│ │ ├── _layer.py
│ │ ├── _layer_circuit.py
│ │ ├── _layer_circuit_test.py
│ │ ├── _loop_layer.py
│ │ ├── _measure_layer.py
│ │ ├── _mpp_layer.py
│ │ ├── _noise_layer.py
│ │ ├── _qubit_coord_annotation_layer.py
│ │ ├── _reset_layer.py
│ │ ├── _rotation_layer.py
│ │ ├── _shift_coord_annotation_layer.py
│ │ ├── _sqrt_pp_layer.py
│ │ ├── _swap_layer.py
│ │ ├── _transpile.py
│ │ └── _transpile_test.py
│ ├── _util.py
│ ├── _util_test.py
│ ├── _viz_circuit_html.py
│ ├── _viz_gltf_3d.py
│ ├── _viz_gltf_3d_test.py
│ ├── _viz_patch_svg.py
│ └── _viz_patch_svg_test.py
├── main.cc
└── main.perf.cc
├── test_data
├── color2surface_d5_transit_p100.stim
├── color2surface_d7_phenom_r7_p100.stim
├── fix_check_1.stim
├── midout488_color_code_d9_r33_p1000.stim
├── midout_color_code_d25_r100_p1000.stim
├── midout_color_code_d5_r10_p1000.stim
├── midout_color_code_d9_r36_p1000.stim
├── old_fail_to_configure_cases
│ ├── detector_reorder_superdense_round.stim
│ ├── detector_unreorder_superdense_round.stim
│ └── hard_config.stim
├── phenom_color_code_d5_r5_p1000.stim
├── phenom_color_code_d5_r5_p1000_with_ignored.stim
├── rep_code_d9_transit_p10.stim
├── rep_code_rbrrr_d9_transit_p10.stim
├── rep_code_rg_d9_transit_p10.stim
├── superdense_color_code_d5_r20_p1000.stim
├── surface_code_d5_r5_p1000.stim
└── toric_superdense_color_code_epr_d12_r5_p1000.stim
└── tools
├── doctest_proper.py
├── fuse_xz_data
├── gen_chromobius_api_reference.py
├── gen_chromobius_stub_file.py
├── gen_circuits
├── gen_timing_stats
├── overwrite_dev_versions_with_date.py
├── plot_comparison
├── plot_stats_timing
├── regen_docs.sh
├── regen_file_lists.sh
├── regen_test_data.sh
├── sinter_plot_print
├── step1_generate_circuits.sh
├── step2_collect_stats.sh
├── step3_plot_stats.sh
└── util_gen_stub_file.py
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | BasedOnStyle: Google
4 | IndentWidth: 4
5 | ColumnLimit: 120
6 | AlignAfterOpenBracket: AlwaysBreak
7 | AllowShortBlocksOnASingleLine: Never
8 | AllowShortFunctionsOnASingleLine: None
9 | AllowShortIfStatementsOnASingleLine: Never
10 | AllowShortLoopsOnASingleLine: false
11 | AllowShortLambdasOnASingleLine: None
12 | BinPackArguments: false
13 | BinPackParameters: false
14 |
15 | IncludeCategories:
16 | - Regex: '^<.*>$'
17 | Priority: 1
18 | - Regex: '^"gtest/.*"$'
19 | Priority: 2
20 | - Regex: '^".*"$'
21 | Priority: 3
22 | ...
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .pytest_cache
3 | out
4 | __pycache__
5 | cmake-build-debug
6 | .cmake
7 | CMakeFiles
8 | CMakeCache.txt
9 | .ninja_deps
10 | .ninja_log
11 | Testing
12 | _deps
13 | build.ninja
14 | cmake_install.cmake
15 | perf.data
16 | perf.data.old
17 | lib
18 | bazel-bin
19 | bazel-out
20 | bazel-testlogs
21 | bazel-*
22 | python_build_chromobius
23 | chromobius.egg-info
24 | .clwb
25 | wheelhouse
26 | build
27 | package_data
28 | .eggs
29 | dist
30 | MODULE.bazel
31 | MODULE.bazel.lock
32 |
--------------------------------------------------------------------------------
/BUILD:
--------------------------------------------------------------------------------
1 | package(default_visibility = ["//visibility:public"])
2 |
3 | load("@rules_python//python:packaging.bzl", "py_wheel")
4 |
5 | SOURCE_FILES_NO_MAIN = glob(
6 | [
7 | "src/**/*.cc",
8 | "src/**/*.h",
9 | "src/**/*.inl",
10 | ],
11 | exclude = glob([
12 | "src/**/*.test.cc",
13 | "src/**/*.test.h",
14 | "src/**/*.perf.cc",
15 | "src/**/*.perf.h",
16 | "src/**/*.pybind.cc",
17 | "src/**/*.pybind.h",
18 | "src/**/main.cc",
19 | ]),
20 | )
21 |
22 | TEST_FILES = glob(
23 | [
24 | "src/**/*.test.cc",
25 | "src/**/*.test.h",
26 | ],
27 | )
28 |
29 | PERF_FILES = glob(
30 | [
31 | "src/**/*.perf.cc",
32 | "src/**/*.perf.h",
33 | ],
34 | )
35 |
36 | PYBIND_FILES = glob(
37 | [
38 | "src/**/*.pybind.cc",
39 | "src/**/*.pybind.h",
40 | ],
41 | )
42 |
43 | cc_binary(
44 | name = "chromobius",
45 | srcs = SOURCE_FILES_NO_MAIN + glob(["src/**/main.cc"]),
46 | copts = [
47 | "-std=c++20",
48 | "-O3",
49 | "-DNDEBUG",
50 | ],
51 | includes = ["src/"],
52 | deps = [
53 | "@pymatching//:libpymatching",
54 | "@stim//:stim_lib",
55 | ],
56 | )
57 |
58 | cc_binary(
59 | name = "chromobius_perf",
60 | srcs = SOURCE_FILES_NO_MAIN + PERF_FILES,
61 | copts = [
62 | "-O3",
63 | "-std=c++20",
64 | "-DNDEBUG",
65 | ],
66 | data = glob(["test_data/**"]),
67 | includes = ["src/"],
68 | deps = [
69 | "@pymatching//:libpymatching",
70 | "@stim//:stim_lib",
71 | ],
72 | )
73 |
74 | cc_test(
75 | name = "chromobius_test",
76 | srcs = SOURCE_FILES_NO_MAIN + TEST_FILES,
77 | copts = [
78 | "-std=c++20",
79 | ],
80 | data = glob(["test_data/**"]),
81 | includes = ["src/"],
82 | deps = [
83 | "@gtest",
84 | "@gtest//:gtest_main",
85 | "@pymatching//:libpymatching",
86 | "@stim//:stim_lib",
87 | ],
88 | )
89 |
90 | cc_binary(
91 | name = "chromobius.so",
92 | srcs = SOURCE_FILES_NO_MAIN + PYBIND_FILES,
93 | copts = [
94 | "-O3",
95 | "-std=c++20",
96 | "-fvisibility=hidden",
97 | "-DNDEBUG",
98 | "-DCHROMOBIUS_VERSION_INFO=0.0.dev0",
99 | ],
100 | includes = ["src/"],
101 | linkshared = 1,
102 | deps = [
103 | "@pybind11",
104 | "@pymatching//:libpymatching",
105 | "@stim//:stim_lib",
106 | ],
107 | )
108 |
109 | genrule(
110 | name = "chromobius_wheel_files",
111 | srcs = ["doc/chromobius.pyi"],
112 | outs = ["chromobius.pyi"],
113 | cmd = "cp $(location doc/chromobius.pyi) $@",
114 | )
115 |
116 | py_wheel(
117 | name = "chromobius_dev_wheel",
118 | distribution = "chromobius",
119 | requires = [
120 | "numpy",
121 | "stim",
122 | ],
123 | version = "0.0.dev0",
124 | deps = [
125 | ":chromobius.so",
126 | ":chromobius_wheel_files",
127 | ],
128 | )
129 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 |
3 | We'd love to accept your patches and contributions to this project.
4 |
5 | ## Before you begin
6 |
7 | ### Sign our Contributor License Agreement
8 |
9 | Contributions to this project must be accompanied by a
10 | [Contributor License Agreement](https://cla.developers.google.com/about) (CLA).
11 | You (or your employer) retain the copyright to your contribution; this simply
12 | gives us permission to use and redistribute your contributions as part of the
13 | project.
14 |
15 | If you or your current employer have already signed the Google CLA (even if it
16 | was for a different project), you probably don't need to do it again.
17 |
18 | Visit to see your current agreements or to
19 | sign a new one.
20 |
21 | ### Review our community guidelines
22 |
23 | This project follows
24 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/).
25 |
26 | ## Contribution process
27 |
28 | ### Code reviews
29 |
30 | All submissions, including submissions by project members, require review. We
31 | use GitHub pull requests for this purpose. Consult
32 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
33 | information on using pull requests.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chromobius: color code decoder
2 |
3 | Chromobius is an implementation of a ["mobius decoder"](https://arxiv.org/abs/2108.11395), which approximates the color code decoding problem as a minimum weight matching problem.
4 | Chromobius uses [PyMatching](https://github.com/oscarhiggott/PyMatching/) to solve the minimum weight matching problem.
5 |
6 | See ((((the paper "New circuits and an open source decoder for the color code")))) for more details on how Chromobius works.
7 |
8 | ## How to use Chromobius
9 |
10 | See the [**getting started notebook**](doc/getting_started.ipynb).
11 |
12 | Also see the [python api reference](doc/chromobius_api_reference.md).
13 |
14 | Programmers who want to edit and build Chromobius can check the [developer documentation](doc/developers.md).
15 |
16 | ## Example Snippets
17 |
18 | ### Decoding a shot with Chromobius
19 |
20 | From python:
21 |
22 | ```python
23 | import stim
24 | import chromobius
25 | import numpy as np
26 |
27 | def count_mistakes(circuit: stim.Circuit, shots: int) -> int:
28 | # Sample the circuit.
29 | dets, actual_obs_flips = circuit.compile_detector_sampler().sample(
30 | shots=shots,
31 | separate_observables=True,
32 | bit_packed=True,
33 | )
34 |
35 | # Decode with Chromobius.
36 | decoder = chromobius.compile_decoder_for_dem(circuit.detector_error_model())
37 | predicted_obs_flips = decoder.predict_obs_flips_from_dets_bit_packed(dets)
38 |
39 | # Count mistakes.
40 | return np.count_nonzero(np.any(predicted_obs_flips != actual_obs_flips, axis=1))
41 | ```
42 |
43 | From the command line:
44 |
45 | ```bash
46 | # Sample shots of detectors and observable flips.
47 | stim detect \
48 | --shots 100000 \
49 | --in "example_circuit.stim" \
50 | --out "dets.b8" \
51 | --out_format "b8" \
52 | --obs_out "obs_actual.txt" \
53 | --obs_out_format "01"
54 |
55 | # Extract a detector error model used to configure Chromobius.
56 | stim analyze_errors \
57 | --in "example_circuit.stim" \
58 | --fold_loops \
59 | --out "dem.dem"
60 |
61 | # Decode the shots.
62 | chromobius predict \
63 | --dem "dem.dem" \
64 | --in "dets.b8" \
65 | --in_format "b8" \
66 | --out "obs_predicted.txt" \
67 | --out_format "01"
68 |
69 | # Count the number of shots with a prediction mistake.
70 | paste obs_actual.txt obs_predicted.txt \
71 | | grep -Pv "^([01]*)\\s*\\1$" \
72 | | wc -l
73 | ```
74 |
75 | From python using sinter:
76 |
77 | ```python
78 | import sinter
79 | import chromobius
80 | import os
81 |
82 | tasks: list[sinter.Task] = ...
83 | stats: list[sinter.TaskStats] = sinter.collect(
84 | decoders=["chromobius"],
85 | custom_decoders=chromobius.sinter_decoders(),
86 | tasks=tasks,
87 | num_workers=os.cpu_count(),
88 | max_shots=100_000,
89 | max_errors=100,
90 | )
91 | ```
92 |
93 | From the command line using sinter:
94 |
95 | ```bash
96 | sinter collect \
97 | --circuits "example_circuit.stim" \
98 | --decoders chromobius \
99 | --custom_decoders_module_function "chromobius:sinter_decoders" \
100 | --max_shots 100_000 \
101 | --max_errors 100
102 | --processes auto \
103 | --save_resume_filepath "stats.csv" \
104 | ```
105 |
--------------------------------------------------------------------------------
/WORKSPACE:
--------------------------------------------------------------------------------
1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
3 |
4 | git_repository(
5 | name = "stim",
6 | commit = "da4594c5ede00a063ec2b84bd830f846b5d097dd",
7 | remote = "https://github.com/quantumlib/stim.git",
8 | )
9 |
10 | git_repository(
11 | name = "pymatching",
12 | commit = "40dcf8c01273ff7e23a7105d5cdc410ada067001",
13 | remote = "https://github.com/oscarhiggott/pymatching.git",
14 | )
15 |
16 | http_archive(
17 | name = "gtest",
18 | sha256 = "353571c2440176ded91c2de6d6cd88ddd41401d14692ec1f99e35d013feda55a",
19 | strip_prefix = "googletest-release-1.11.0",
20 | urls = ["https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip"],
21 | )
22 |
23 | http_archive(
24 | name = "pybind11",
25 | build_file = "@pybind11_bazel//:pybind11.BUILD",
26 | sha256 = "832e2f309c57da9c1e6d4542dedd34b24e4192ecb4d62f6f4866a737454c9970",
27 | strip_prefix = "pybind11-2.10.4",
28 | urls = ["https://github.com/pybind/pybind11/archive/v2.10.4.tar.gz"],
29 | )
30 |
31 | http_archive(
32 | name = "pybind11_bazel",
33 | sha256 = "e8355ee56c2ff772334b4bfa22be17c709e5573f6d1d561c7176312156c27bd4",
34 | strip_prefix = "pybind11_bazel-2.11.1",
35 | urls = ["https://github.com/pybind/pybind11_bazel/releases/download/v2.11.1/pybind11_bazel-2.11.1.tar.gz"],
36 | )
37 |
38 | http_archive(
39 | name = "rules_python",
40 | sha256 = "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
41 | strip_prefix = "rules_python-0.24.0",
42 | url = "https://github.com/bazelbuild/rules_python/releases/download/0.24.0/rules_python-0.24.0.tar.gz",
43 | )
44 |
45 | load("@rules_python//python:repositories.bzl", "py_repositories")
46 | load("@pybind11_bazel//:python_configure.bzl", "python_configure")
47 |
48 | py_repositories()
49 |
50 | python_configure(name = "local_config_python")
51 |
--------------------------------------------------------------------------------
/assets/ablated_stabilizers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/ablated_stabilizers.png
--------------------------------------------------------------------------------
/assets/cmp_transit_from_prev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/cmp_transit_from_prev.png
--------------------------------------------------------------------------------
/assets/color2surface.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/color2surface.png
--------------------------------------------------------------------------------
/assets/color_code_layouts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/color_code_layouts.png
--------------------------------------------------------------------------------
/assets/example_boundary_match.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/example_boundary_match.png
--------------------------------------------------------------------------------
/assets/generated/cmp_transit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/cmp_transit.png
--------------------------------------------------------------------------------
/assets/generated/compare_X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/compare_X.png
--------------------------------------------------------------------------------
/assets/generated/compare_XZ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/compare_XZ.png
--------------------------------------------------------------------------------
/assets/generated/compare_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/compare_Z.png
--------------------------------------------------------------------------------
/assets/generated/midout_error_X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/midout_error_X.png
--------------------------------------------------------------------------------
/assets/generated/midout_error_XZ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/midout_error_XZ.png
--------------------------------------------------------------------------------
/assets/generated/midout_error_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/midout_error_Z.png
--------------------------------------------------------------------------------
/assets/generated/midout_footprint_X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/midout_footprint_X.png
--------------------------------------------------------------------------------
/assets/generated/midout_footprint_XZ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/midout_footprint_XZ.png
--------------------------------------------------------------------------------
/assets/generated/midout_footprint_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/midout_footprint_Z.png
--------------------------------------------------------------------------------
/assets/generated/phenom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/phenom.png
--------------------------------------------------------------------------------
/assets/generated/prev_work_comparison_0.0001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/prev_work_comparison_0.0001.png
--------------------------------------------------------------------------------
/assets/generated/prev_work_comparison_0.0002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/prev_work_comparison_0.0002.png
--------------------------------------------------------------------------------
/assets/generated/prev_work_comparison_0.0003.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/prev_work_comparison_0.0003.png
--------------------------------------------------------------------------------
/assets/generated/prev_work_comparison_0.0005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/prev_work_comparison_0.0005.png
--------------------------------------------------------------------------------
/assets/generated/prev_work_comparison_0.001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/prev_work_comparison_0.001.png
--------------------------------------------------------------------------------
/assets/generated/prev_work_comparison_0.002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/prev_work_comparison_0.002.png
--------------------------------------------------------------------------------
/assets/generated/superdense_error_X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/superdense_error_X.png
--------------------------------------------------------------------------------
/assets/generated/superdense_error_XZ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/superdense_error_XZ.png
--------------------------------------------------------------------------------
/assets/generated/superdense_error_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/superdense_error_Z.png
--------------------------------------------------------------------------------
/assets/generated/superdense_footprint_X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/superdense_footprint_X.png
--------------------------------------------------------------------------------
/assets/generated/superdense_footprint_XZ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/superdense_footprint_XZ.png
--------------------------------------------------------------------------------
/assets/generated/superdense_footprint_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/superdense_footprint_Z.png
--------------------------------------------------------------------------------
/assets/generated/timing_d.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/timing_d.png
--------------------------------------------------------------------------------
/assets/generated/timing_d_full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/timing_d_full.png
--------------------------------------------------------------------------------
/assets/generated/timing_r.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/timing_r.png
--------------------------------------------------------------------------------
/assets/generated/timing_r_full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/timing_r_full.png
--------------------------------------------------------------------------------
/assets/generated/timing_rq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/timing_rq.png
--------------------------------------------------------------------------------
/assets/generated/timing_rq_full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/timing_rq_full.png
--------------------------------------------------------------------------------
/assets/generated/toric.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/generated/toric.png
--------------------------------------------------------------------------------
/assets/midout-detslice-cycle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/midout-detslice-cycle.png
--------------------------------------------------------------------------------
/assets/multiplexing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/multiplexing.png
--------------------------------------------------------------------------------
/assets/perf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/perf.png
--------------------------------------------------------------------------------
/assets/pyramid_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/pyramid_code.png
--------------------------------------------------------------------------------
/assets/solved_euclidean_problem.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/solved_euclidean_problem.png
--------------------------------------------------------------------------------
/assets/superdense-detslice-cycle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/chromobius/35e289570fdc1d71e73582e1fd4e0c8e29298ef5/assets/superdense-detslice-cycle.png
--------------------------------------------------------------------------------
/file_lists/perf_files:
--------------------------------------------------------------------------------
1 | src/chromobius/datatypes/atomic_error.perf.cc
2 | src/chromobius/decode/decoder.perf.cc
3 | src/chromobius/graph/euler_tours.perf.cc
4 | src/chromobius/util.perf.h
5 | src/main.perf.cc
6 |
--------------------------------------------------------------------------------
/file_lists/pybind_files:
--------------------------------------------------------------------------------
1 | src/chromobius/pybind/chromobius.pybind.cc
2 | src/chromobius/pybind/sinter_compat.pybind.cc
3 | src/chromobius/pybind/sinter_compat.pybind.h
4 |
--------------------------------------------------------------------------------
/file_lists/source_files_no_main:
--------------------------------------------------------------------------------
1 | src/chromobius.h
2 | src/chromobius/commands/main_all.cc
3 | src/chromobius/commands/main_all.h
4 | src/chromobius/commands/main_benchmark.cc
5 | src/chromobius/commands/main_benchmark.h
6 | src/chromobius/commands/main_describe_decoder.cc
7 | src/chromobius/commands/main_describe_decoder.h
8 | src/chromobius/commands/main_predict.cc
9 | src/chromobius/commands/main_predict.h
10 | src/chromobius/datatypes/atomic_error.cc
11 | src/chromobius/datatypes/atomic_error.h
12 | src/chromobius/datatypes/color_basis.cc
13 | src/chromobius/datatypes/color_basis.h
14 | src/chromobius/datatypes/conf.h
15 | src/chromobius/datatypes/rgb_edge.cc
16 | src/chromobius/datatypes/rgb_edge.h
17 | src/chromobius/datatypes/stim_integration.cc
18 | src/chromobius/datatypes/stim_integration.h
19 | src/chromobius/datatypes/xor_vec.h
20 | src/chromobius/decode/decoder.cc
21 | src/chromobius/decode/decoder.h
22 | src/chromobius/decode/matcher_interface.h
23 | src/chromobius/decode/pymatcher.cc
24 | src/chromobius/decode/pymatcher.h
25 | src/chromobius/graph/charge_graph.cc
26 | src/chromobius/graph/charge_graph.h
27 | src/chromobius/graph/choose_rgb_reps.cc
28 | src/chromobius/graph/choose_rgb_reps.h
29 | src/chromobius/graph/collect_atomic_errors.cc
30 | src/chromobius/graph/collect_atomic_errors.h
31 | src/chromobius/graph/collect_composite_errors.cc
32 | src/chromobius/graph/collect_composite_errors.h
33 | src/chromobius/graph/collect_nodes.cc
34 | src/chromobius/graph/collect_nodes.h
35 | src/chromobius/graph/drag_graph.cc
36 | src/chromobius/graph/drag_graph.h
37 | src/chromobius/graph/euler_tours.cc
38 | src/chromobius/graph/euler_tours.h
39 |
--------------------------------------------------------------------------------
/file_lists/test_files:
--------------------------------------------------------------------------------
1 | src/chromobius/commands/main_all.test.cc
2 | src/chromobius/commands/main_all.test.h
3 | src/chromobius/commands/main_benchmark.test.cc
4 | src/chromobius/commands/main_describe_decoder.test.cc
5 | src/chromobius/commands/main_predict.test.cc
6 | src/chromobius/datatypes/atomic_error.test.cc
7 | src/chromobius/datatypes/color_basis.test.cc
8 | src/chromobius/datatypes/rgb_edge.test.cc
9 | src/chromobius/datatypes/stim_integration.test.cc
10 | src/chromobius/datatypes/xor_vec.test.cc
11 | src/chromobius/decode/decoder.test.cc
12 | src/chromobius/decode/decoder_integration.test.cc
13 | src/chromobius/graph/charge_graph.test.cc
14 | src/chromobius/graph/choose_rgb_reps.test.cc
15 | src/chromobius/graph/drag_graph.test.cc
16 | src/chromobius/graph/euler_tours.test.cc
17 | src/chromobius/test_util.test.cc
18 | src/chromobius/test_util.test.h
19 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools"]
3 | build-backend = "setuptools.build_meta"
4 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | # These are development requirements, not install requirements.
2 | matplotlib ~= 3.5
3 | numpy
4 | pymatching ~= 2.0
5 | pytest
6 | scipy
7 | sinter ~= 1.14
8 | stim ~= 1.14
9 | pygltflib
10 |
--------------------------------------------------------------------------------
/src/chromobius.h:
--------------------------------------------------------------------------------
1 | #ifndef _CHROMOBIUS_H
2 | #define _CHROMOBIUS_H
3 | /// WARNING: THE chromobius C++ API MAKES NO COMPATIBILITY GUARANTEES.
4 | /// It may change arbitrarily and catastrophically from minor version to minor version.
5 | /// If you need a stable API, use chromobius's Python API.
6 | #include "chromobius/commands/main_all.h"
7 | #include "chromobius/commands/main_benchmark.h"
8 | #include "chromobius/commands/main_describe_decoder.h"
9 | #include "chromobius/commands/main_predict.h"
10 | #include "chromobius/datatypes/atomic_error.h"
11 | #include "chromobius/datatypes/color_basis.h"
12 | #include "chromobius/datatypes/conf.h"
13 | #include "chromobius/datatypes/rgb_edge.h"
14 | #include "chromobius/datatypes/stim_integration.h"
15 | #include "chromobius/datatypes/xor_vec.h"
16 | #include "chromobius/decode/decoder.h"
17 | #include "chromobius/decode/matcher_interface.h"
18 | #include "chromobius/decode/pymatcher.h"
19 | #include "chromobius/graph/charge_graph.h"
20 | #include "chromobius/graph/choose_rgb_reps.h"
21 | #include "chromobius/graph/collect_atomic_errors.h"
22 | #include "chromobius/graph/collect_composite_errors.h"
23 | #include "chromobius/graph/collect_nodes.h"
24 | #include "chromobius/graph/drag_graph.h"
25 | #include "chromobius/graph/euler_tours.h"
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_all.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_COMMANDS_MAIN_ALL_H
18 | #define _CHROMOBIUS_COMMANDS_MAIN_ALL_H
19 |
20 | namespace chromobius {
21 |
22 | int main(int argc, const char **argv);
23 |
24 | }
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_all.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/commands/main_all.test.h"
16 |
17 | #include "gtest/gtest.h"
18 |
19 | #include "chromobius/test_util.test.h"
20 |
21 | using namespace chromobius;
22 |
23 | std::string chromobius::result_of_running_main(const std::vector args, const std::string &input) {
24 | std::vector argv;
25 | argv.push_back("TEST_PROCESS");
26 | for (const auto &a : args) {
27 | argv.push_back(a.c_str());
28 | }
29 | RaiiTempNamedFile inp;
30 | RaiiTempNamedFile out;
31 | argv.push_back("--in");
32 | argv.push_back(inp.path.c_str());
33 | argv.push_back("--out");
34 | argv.push_back(out.path.c_str());
35 | FILE *f = fopen(inp.path.c_str(), "w");
36 | if (f == nullptr || fwrite(input.data(), 1, input.size(), f) != input.size()) {
37 | throw std::invalid_argument("Failed to write input.");
38 | }
39 | fclose(f);
40 | if (chromobius::main((int)argv.size(), argv.data()) != EXIT_SUCCESS) {
41 | throw std::invalid_argument("Returned not EXIT_SUCCESS");
42 | }
43 | f = fopen(out.path.c_str(), "rb");
44 | if (f == nullptr) {
45 | throw std::invalid_argument("Failed to read output.");
46 | }
47 | std::string s;
48 | while (true) {
49 | int i = getc(f);
50 | if (i == EOF) {
51 | break;
52 | }
53 | s.push_back((char)i);
54 | }
55 | return s;
56 | }
57 |
58 | TEST(main_all, unknown_command) {
59 | ASSERT_THROW({ result_of_running_main({"UNKNOWN_COMMAND"}, ""); }, std::invalid_argument);
60 | }
61 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_all.test.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_COMMANDS_MAIN_ALL_TEST_H
18 | #define _CHROMOBIUS_COMMANDS_MAIN_ALL_TEST_H
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "chromobius/commands/main_all.h"
25 |
26 | namespace chromobius {
27 |
28 | std::string result_of_running_main(const std::vector args, const std::string &input);
29 |
30 | } // namespace chromobius
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_benchmark.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_COMMANDS_MAIN_COUNT_MISTAKES_H
18 | #define _CHROMOBIUS_COMMANDS_MAIN_COUNT_MISTAKES_H
19 |
20 | namespace chromobius {
21 |
22 | int main_benchmark(int argc, const char **argv);
23 |
24 | }
25 |
26 | #endif
--------------------------------------------------------------------------------
/src/chromobius/commands/main_benchmark.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "gtest/gtest.h"
16 |
17 | #include "chromobius/commands/main_all.test.h"
18 | #include "chromobius/test_util.test.h"
19 |
20 | using namespace chromobius;
21 |
22 | TEST(main_benchmark, basic) {
23 | RaiiTempNamedFile dem;
24 | FILE *f = fopen(dem.path.c_str(), "w");
25 | fprintf(f, "%s", R"DEM(
26 | error(0.1) D0 L0
27 | error(0.1) D0 D1 L1
28 | error(0.1) D1 L2
29 | detector(0, 0, 0, 0) D0
30 | detector(0, 0, 0, 1) D1
31 | )DEM");
32 | fclose(f);
33 | auto stdout_text = result_of_running_main(
34 | {
35 | "benchmark",
36 | "--dem",
37 | dem.path,
38 | "--in_format",
39 | "dets",
40 | "--in_includes_appended_observables",
41 | },
42 | R"stdin(shot L0
43 | shot D0 L0
44 | shot D1 L2
45 | shot D0 D1 L1)stdin");
46 |
47 | std::string expected_prefix = R"OUT(
48 | num_shots = 4
49 | num_mistakes = 1
50 | mistakes_per_shot = 0.25
51 |
52 | num_detection_events = 4
53 | num_detectors_per_shot = 2
54 | detection_fraction = 0.5
55 |
56 | setup_seconds =)OUT";
57 | ASSERT_EQ(stdout_text.substr(0, expected_prefix.size() - 1), expected_prefix.substr(1));
58 | }
59 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_describe_decoder.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/commands/main_describe_decoder.h"
16 |
17 | #include "chromobius/decode/decoder.h"
18 | #include "stim.h"
19 |
20 | using namespace chromobius;
21 |
22 | int chromobius::main_describe_decoder(int argc, const char **argv) {
23 | stim::check_for_unknown_arguments(
24 | {
25 | "--in",
26 | "--out",
27 | "--circuit",
28 | },
29 | {},
30 | "describe_decoder",
31 | argc,
32 | argv);
33 |
34 | auto out_file = stim::find_output_stream_argument("--out", true, argc, argv);
35 | auto &out = out_file.stream();
36 |
37 | stim::DetectorErrorModel dem;
38 |
39 | if (stim::find_argument("--circuit", argc, argv) != nullptr) {
40 | FILE *circuit_in = stim::find_open_file_argument("--circuit", nullptr, "rb", argc, argv);
41 | auto circuit = stim::Circuit::from_file(circuit_in);
42 | fclose(circuit_in);
43 | dem = stim::ErrorAnalyzer::circuit_to_detector_error_model(circuit, false, true, false, true, false, false);
44 | } else {
45 | FILE *dem_in = stim::find_open_file_argument("--in", stdin, "rb", argc, argv);
46 | dem = stim::DetectorErrorModel::from_file(dem_in);
47 | fclose(dem_in);
48 | }
49 |
50 | auto decoder = Decoder::from_dem(dem, DecoderConfigOptions{.include_coords_in_mobius_dem=true});
51 | out << decoder;
52 | out << "\n";
53 | return EXIT_SUCCESS;
54 | }
55 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_describe_decoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_COMMANDS_MAIN_DESCRIBE_DECODER_H
18 | #define _CHROMOBIUS_COMMANDS_MAIN_DESCRIBE_DECODER_H
19 |
20 | namespace chromobius {
21 |
22 | int main_describe_decoder(int argc, const char **argv);
23 |
24 | }
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_describe_decoder.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "gtest/gtest.h"
16 |
17 | #include "chromobius/commands/main_all.test.h"
18 |
19 | using namespace chromobius;
20 |
21 | TEST(main_describe_decoder, basic_usage) {
22 | auto result = result_of_running_main(
23 | {"describe_decoder"},
24 | R"stdin(
25 | error(0.1) D0 L0
26 | error(0.1) D0 D1 L1
27 | error(0.1) D1 L2
28 | detector(0, 0, 0, 0) D0
29 | detector(0, 0, 0, 1) D1
30 | )stdin");
31 | ASSERT_EQ("\n" + result, R"stdout(
32 | chromobius::Decoder{
33 |
34 | .charge_graph=ChargeGraph{.nodes={
35 | ChargeGraphNode{.neighbors={{0,0}, {1,2}, {BOUNDARY_NODE,1}}}, // node 0
36 | ChargeGraphNode{.neighbors={{0,2}, {1,0}, {BOUNDARY_NODE,4}}}, // node 1
37 | }}
38 |
39 | .rgb_reps={
40 | RgbEdge{.red_node=0, .green_node=1, .blue_node=BOUNDARY_NODE, .obs_flip=2, .charge_flip=B} // rep 0
41 | RgbEdge{.red_node=0, .green_node=1, .blue_node=BOUNDARY_NODE, .obs_flip=2, .charge_flip=B} // rep 1
42 | }
43 |
44 | .drag_graph=DragGraph{.mmm={
45 | NEUTRAL@0:NEUTRAL@0 = 0
46 | NEUTRAL@0:R@0 = 1
47 | R@0:NEUTRAL@0 = 1
48 | NEUTRAL@0:NEUTRAL@1 = 0
49 | R@0:R@1 = 0
50 | R@0:G@1 = 2
51 | G@0:G@1 = 0
52 | NEUTRAL@1:NEUTRAL@0 = 0
53 | R@1:R@0 = 0
54 | G@1:R@0 = 2
55 | G@1:G@0 = 0
56 | NEUTRAL@1:NEUTRAL@1 = 0
57 | NEUTRAL@1:G@1 = 4
58 | G@1:NEUTRAL@1 = 4
59 | }}
60 |
61 | .mobius_dem=stim::DetectorErrorModel{
62 | detector(0, 0, 0, 0, 2) D0
63 | detector(0, 0, 0, 0, 3) D1
64 | detector(0, 0, 0, 1, 1) D2
65 | detector(0, 0, 0, 1, 3) D3
66 | error(0.01000000000000000194) D0 D1
67 | error(0.1000000000000000056) D0 D2 ^ D1 D3
68 | error(0.01000000000000000194) D2 D3
69 | }
70 |
71 | }
72 | )stdout");
73 | }
74 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_predict.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/commands/main_predict.h"
16 |
17 | #include "chromobius/decode/decoder.h"
18 | #include "stim.h"
19 |
20 | using namespace chromobius;
21 |
22 | int chromobius::main_predict(int argc, const char **argv) {
23 | stim::check_for_unknown_arguments(
24 | {
25 | "--in",
26 | "--in_format",
27 | "--in_includes_appended_observables",
28 | "--out",
29 | "--out_format",
30 | "--dem",
31 | },
32 | {},
33 | "predict",
34 | argc,
35 | argv);
36 |
37 | FILE *shots_in = stim::find_open_file_argument("--in", stdin, "rb", argc, argv);
38 | FILE *predictions_out = stim::find_open_file_argument("--out", stdout, "wb", argc, argv);
39 | FILE *dem_file = stim::find_open_file_argument("--dem", nullptr, "rb", argc, argv);
40 | stim::FileFormatData shots_in_format =
41 | stim::find_enum_argument("--in_format", "b8", stim::format_name_to_enum_map(), argc, argv);
42 | stim::FileFormatData predictions_out_format =
43 | stim::find_enum_argument("--out_format", "01", stim::format_name_to_enum_map(), argc, argv);
44 | bool append_obs = stim::find_bool_argument("--in_includes_appended_observables", argc, argv);
45 |
46 | stim::DetectorErrorModel dem = stim::DetectorErrorModel::from_file(dem_file);
47 | fclose(dem_file);
48 | auto decoder = Decoder::from_dem(dem, DecoderConfigOptions{});
49 |
50 | size_t num_dets = dem.count_detectors();
51 | size_t num_obs = dem.count_observables();
52 | auto reader = stim::MeasureRecordReader::make(
53 | shots_in, shots_in_format.id, 0, dem.count_detectors(), append_obs * num_obs);
54 | auto writer = stim::MeasureRecordWriter::make(predictions_out, predictions_out_format.id);
55 | writer->begin_result_type('L');
56 |
57 | stim::simd_bits buf_dets(reader->bits_per_record());
58 | while (reader->start_and_read_entire_record(buf_dets)) {
59 | if (append_obs) {
60 | for (size_t k = 0; k < num_obs; k++) {
61 | buf_dets[num_dets + k] = 0;
62 | }
63 | }
64 | auto prediction =
65 | decoder.decode_detection_events({buf_dets.u8, buf_dets.u8 + buf_dets.num_u8_padded()});
66 | for (size_t k = 0; k < num_obs; k++) {
67 | writer->write_bit((prediction >> k) & 1);
68 | }
69 | writer->write_end();
70 | buf_dets.clear();
71 | }
72 |
73 | if (predictions_out != stdout) {
74 | fclose(predictions_out);
75 | }
76 | if (shots_in != stdin) {
77 | fclose(shots_in);
78 | }
79 |
80 | return EXIT_SUCCESS;
81 | }
82 |
--------------------------------------------------------------------------------
/src/chromobius/commands/main_predict.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_COMMANDS_MAIN_PREDICT_H
18 | #define _CHROMOBIUS_COMMANDS_MAIN_PREDICT_H
19 |
20 | namespace chromobius {
21 |
22 | int main_predict(int argc, const char **argv);
23 |
24 | }
25 |
26 | #endif
--------------------------------------------------------------------------------
/src/chromobius/commands/main_predict.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "gtest/gtest.h"
16 |
17 | #include "chromobius/commands/main_all.test.h"
18 | #include "chromobius/test_util.test.h"
19 |
20 | using namespace chromobius;
21 |
22 | TEST(main_predict, basic) {
23 | RaiiTempNamedFile dem;
24 | FILE *f = fopen(dem.path.c_str(), "w");
25 | fprintf(f, "%s", R"DEM(
26 | error(0.1) D0 L0
27 | error(0.1) D0 D1 L1
28 | error(0.1) D1 L2
29 | detector(0, 0, 0, 0) D0
30 | detector(0, 0, 0, 1) D1
31 | )DEM");
32 | fclose(f);
33 | auto stdout_content = result_of_running_main(
34 | {"predict", "--dem", dem.path, "--in_format", "dets", "--out_format", "dets"},
35 | R"stdin(shot
36 | shot D0
37 | shot D1
38 | shot D0 D1)stdin");
39 | ASSERT_EQ(stdout_content, R"stdout(shot
40 | shot L0
41 | shot L2
42 | shot L1
43 | )stdout");
44 | }
45 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/atomic_error.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include
16 |
17 | #include "chromobius/datatypes/atomic_error.h"
18 |
19 | using namespace chromobius;
20 |
21 | void AtomicErrorKey::check_invariants(std::span det_types) {
22 | Charge net_charge = Charge::NEUTRAL;
23 | for (auto d : dets) {
24 | if (d < det_types.size()) {
25 | net_charge ^= det_types[d].color;
26 | } else if (d != BOUNDARY_NODE) {
27 | std::stringstream ss;
28 | ss << *this << " has a too-large detector index. det_types.size() = " << det_types.size();
29 | throw std::invalid_argument(ss.str());
30 | }
31 | }
32 |
33 | if (dets[0] == BOUNDARY_NODE) {
34 | throw std::invalid_argument("Vacuous: " + str());
35 | }
36 | if (dets[0] > dets[1] || dets[1] > dets[2]) {
37 | throw std::invalid_argument("Not sorted: " + str());
38 | }
39 | if (net_charge != Charge::NEUTRAL && dets[2] != BOUNDARY_NODE) {
40 | std::stringstream ss;
41 | ss << "Triplet " << *this << " has non-neutral charge " << net_charge;
42 | throw std::invalid_argument(ss.str());
43 | }
44 | }
45 |
46 | std::ostream &chromobius::operator<<(std::ostream &out, const AtomicErrorKey &val) {
47 | out << "AtomicErrorKey{.dets={";
48 | for (size_t k = 0; k < 3; k++) {
49 | if (k > 0) {
50 | out << ", ";
51 | }
52 | if (val.dets[k] == BOUNDARY_NODE) {
53 | out << "BOUNDARY_NODE";
54 | } else {
55 | out << val.dets[k];
56 | }
57 | }
58 | out << "}}";
59 | return out;
60 | }
61 | std::string AtomicErrorKey::str() const {
62 | std::stringstream ss;
63 | ss << *this;
64 | return ss.str();
65 | }
66 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/atomic_error.perf.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/datatypes/atomic_error.h"
16 |
17 | #include "chromobius/util.perf.h"
18 | #include "stim.h"
19 |
20 | using namespace chromobius;
21 |
22 | BENCHMARK(sort3) {
23 | std::vector data;
24 | std::mt19937_64 rng{0};
25 | for (size_t k = 0; k < 999; k++) {
26 | data.push_back((node_offset_int)rng());
27 | }
28 |
29 | size_t v0 = 0;
30 | size_t v1 = 0;
31 | size_t v2 = 0;
32 | benchmark_go([&]() {
33 | for (size_t k = 0; k < data.size(); k += 3) {
34 | auto abc = sort3(data[k], data[k + 1], data[k + 2]);
35 | v0 += abc[0];
36 | v1 ^= abc[1];
37 | v2 += abc[2];
38 | }
39 | })
40 | .goal_nanos(150)
41 | .show_rate("Constructions", data.size() / 3);
42 | if (v0 + v1 + v2 == 1) {
43 | std::cerr << "data dependence";
44 | }
45 | }
46 |
47 | BENCHMARK(sort3_known_max) {
48 | std::vector data;
49 | std::mt19937_64 rng{0};
50 | for (size_t k = 0; k < 999; k++) {
51 | data.push_back((node_offset_int)rng());
52 | }
53 |
54 | size_t v0 = 0;
55 | size_t v1 = 0;
56 | size_t v2 = 0;
57 | benchmark_go([&]() {
58 | for (size_t k = 0; k < data.size(); k += 3) {
59 | auto e2 = sort3(data[k], UINT32_MAX, data[k + 1]);
60 | v0 += e2[0];
61 | v1 ^= e2[1];
62 | v2 += e2[2];
63 | }
64 | })
65 | .goal_nanos(100)
66 | .show_rate("Constructions", data.size() / 3);
67 | if (v0 + v1 + v2 == 1) {
68 | std::cerr << "data dependence";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/color_basis.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_COLOR_BASIS_H
18 | #define _CHROMOBIUS_COLOR_BASIS_H
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "chromobius/datatypes/conf.h"
25 |
26 | namespace chromobius {
27 |
28 | enum Charge : uint8_t {
29 | NEUTRAL = 0,
30 | R = 1,
31 | G = 2,
32 | B = 3,
33 | };
34 | inline Charge next_non_neutral_charge(Charge c) {
35 | return (Charge)(c % 3 + 1);
36 | }
37 | inline Charge operator^(Charge c1, Charge c2) {
38 | return (Charge)((uint8_t)c1 ^ (uint8_t)c2);
39 | }
40 | inline Charge &operator^=(Charge &c1, Charge c2) {
41 | c1 = (Charge)((uint8_t)c1 ^ (uint8_t)c2);
42 | return c1;
43 | }
44 |
45 | enum SubGraphCoord : uint8_t {
46 | UNKNOWN_SUBGRAPH_COORD = 0,
47 | NotRed = 1,
48 | NotGreen = 2,
49 | NotBlue = 3,
50 | };
51 |
52 | constexpr uint8_t SUBGRAPH_OFFSET_Red_NotGreen = 0;
53 | constexpr uint8_t SUBGRAPH_OFFSET_Red_NotBlue = 1;
54 | constexpr uint8_t SUBGRAPH_OFFSET_Green_NotRed = 0;
55 | constexpr uint8_t SUBGRAPH_OFFSET_Green_NotBlue = 1;
56 | constexpr uint8_t SUBGRAPH_OFFSET_Blue_NotRed = 0;
57 | constexpr uint8_t SUBGRAPH_OFFSET_Blue_NotGreen = 1;
58 |
59 | enum Basis : uint8_t {
60 | UNKNOWN_BASIS = 0,
61 | X = 1,
62 | Z = 2,
63 | };
64 |
65 | struct ColorBasis {
66 | Charge color;
67 | Basis basis;
68 | bool ignored = false;
69 | bool operator==(const ColorBasis &other) const;
70 | bool operator!=(const ColorBasis &other) const;
71 | std::string str() const;
72 | };
73 | std::ostream &operator<<(std::ostream &out, const ColorBasis &val);
74 | std::ostream &operator<<(std::ostream &out, const Charge &val);
75 | std::ostream &operator<<(std::ostream &out, const SubGraphCoord &val);
76 | std::ostream &operator<<(std::ostream &out, const Basis &val);
77 |
78 | std::tuple mobius_node_to_detector(
79 | uint64_t mobius_node, std::span colors);
80 | uint64_t detector_to_mobius_node(node_offset_int node, SubGraphCoord subgraph, std::span colors);
81 |
82 | } // namespace chromobius
83 |
84 | #endif
85 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/color_basis.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/datatypes/color_basis.h"
16 |
17 | #include "gtest/gtest.h"
18 |
19 | using namespace chromobius;
20 |
21 | TEST(types, color_basis_basic) {
22 | ColorBasis e{.color = Charge::R, .basis = Basis::X};
23 |
24 | ASSERT_TRUE(e == (ColorBasis{.color = Charge::R, .basis = Basis::X}));
25 | ASSERT_FALSE(e == (ColorBasis{.color = Charge::G, .basis = Basis::X}));
26 | ASSERT_FALSE(e == (ColorBasis{.color = Charge::R, .basis = Basis::Z}));
27 |
28 | ASSERT_TRUE(e != (ColorBasis{.color = Charge::G, .basis = Basis::X}));
29 |
30 | ASSERT_EQ(e.str(), "ColorBasis{.color=R, .basis=X}");
31 | }
32 |
33 | TEST(atomic_error, mobius_node_to_detector_vs_detector_to_mobius_node) {
34 | std::vector colors;
35 | colors.resize(50);
36 |
37 | colors[29].color = Charge::R;
38 | ASSERT_EQ(
39 | mobius_node_to_detector(29 * 2 + SUBGRAPH_OFFSET_Red_NotGreen, colors),
40 | (std::tuple(29, Charge::R, SubGraphCoord::NotGreen)));
41 | ASSERT_EQ(detector_to_mobius_node(29, SubGraphCoord::NotGreen, colors), 29 * 2 + SUBGRAPH_OFFSET_Red_NotGreen);
42 |
43 | colors[31].color = Charge::R;
44 | ASSERT_EQ(
45 | mobius_node_to_detector(31 * 2 + SUBGRAPH_OFFSET_Red_NotBlue, colors),
46 | (std::tuple(31, Charge::R, SubGraphCoord::NotBlue)));
47 | ASSERT_EQ(detector_to_mobius_node(31, SubGraphCoord::NotBlue, colors), 31 * 2 + SUBGRAPH_OFFSET_Red_NotBlue);
48 |
49 | colors[36].color = Charge::G;
50 | ASSERT_EQ(
51 | mobius_node_to_detector(36 * 2 + SUBGRAPH_OFFSET_Green_NotRed, colors),
52 | (std::tuple(36, Charge::G, SubGraphCoord::NotRed)));
53 | ASSERT_EQ(detector_to_mobius_node(36, SubGraphCoord::NotRed, colors), 36 * 2 + SUBGRAPH_OFFSET_Green_NotRed);
54 |
55 | colors[41].color = Charge::G;
56 | ASSERT_EQ(
57 | mobius_node_to_detector(41 * 2 + SUBGRAPH_OFFSET_Green_NotBlue, colors),
58 | (std::tuple(41, Charge::G, SubGraphCoord::NotBlue)));
59 | ASSERT_EQ(detector_to_mobius_node(41, SubGraphCoord::NotBlue, colors), 41 * 2 + SUBGRAPH_OFFSET_Green_NotBlue);
60 |
61 | colors[43].color = Charge::B;
62 | ASSERT_EQ(
63 | mobius_node_to_detector(43 * 2 + SUBGRAPH_OFFSET_Blue_NotRed, colors),
64 | (std::tuple(43, Charge::B, SubGraphCoord::NotRed)));
65 | ASSERT_EQ(detector_to_mobius_node(43, SubGraphCoord::NotRed, colors), 43 * 2 + SUBGRAPH_OFFSET_Blue_NotRed);
66 |
67 | colors[47].color = Charge::B;
68 | ASSERT_EQ(
69 | mobius_node_to_detector(47 * 2 + SUBGRAPH_OFFSET_Blue_NotGreen, colors),
70 | (std::tuple(47, Charge::B, SubGraphCoord::NotGreen)));
71 | ASSERT_EQ(detector_to_mobius_node(47, SubGraphCoord::NotGreen, colors), 47 * 2 + SUBGRAPH_OFFSET_Blue_NotGreen);
72 | }
73 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/conf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_TYPES_H
18 | #define _CHROMOBIUS_TYPES_H
19 |
20 | #include
21 | #include
22 |
23 | namespace chromobius {
24 |
25 | typedef uint64_t obsmask_int;
26 | typedef uint32_t node_offset_int;
27 | constexpr node_offset_int BOUNDARY_NODE = (node_offset_int)-1;
28 |
29 | } // namespace chromobius
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/rgb_edge.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/datatypes/rgb_edge.h"
16 |
17 | #include
18 | #include
19 |
20 | using namespace chromobius;
21 |
22 | bool RgbEdge::operator==(const RgbEdge &other) const {
23 | return red_node == other.red_node && blue_node == other.blue_node && green_node == other.green_node &&
24 | obs_flip == other.obs_flip && charge_flip == other.charge_flip;
25 | }
26 | bool RgbEdge::operator!=(const RgbEdge &other) const {
27 | return !(*this == other);
28 | }
29 | std::string RgbEdge::str() const {
30 | std::stringstream ss;
31 | ss << *this;
32 | return ss.str();
33 | }
34 | std::ostream &chromobius::operator<<(std::ostream &out, const RgbEdge &val) {
35 | out << "RgbEdge{.red_node=";
36 | if (val.red_node == BOUNDARY_NODE) {
37 | out << "BOUNDARY_NODE";
38 | } else {
39 | out << val.red_node;
40 | }
41 | out << ", .green_node=";
42 | if (val.green_node == BOUNDARY_NODE) {
43 | out << "BOUNDARY_NODE";
44 | } else {
45 | out << val.green_node;
46 | }
47 | out << ", .blue_node=";
48 | if (val.blue_node == BOUNDARY_NODE) {
49 | out << "BOUNDARY_NODE";
50 | } else {
51 | out << val.blue_node;
52 | }
53 | out << ", .obs_flip=" << val.obs_flip;
54 | out << ", .charge_flip=" << val.charge_flip;
55 | out << "}";
56 | return out;
57 | }
58 | size_t RgbEdge::weight() const {
59 | return (red_node != BOUNDARY_NODE) + (green_node != BOUNDARY_NODE) + (blue_node != BOUNDARY_NODE);
60 | }
61 |
62 | bool RgbEdge::operator<(const RgbEdge &other) const {
63 | if (red_node != other.red_node) {
64 | return red_node < other.red_node;
65 | }
66 | if (green_node != other.green_node) {
67 | return green_node < other.green_node;
68 | }
69 | if (blue_node != other.blue_node) {
70 | return blue_node < other.blue_node;
71 | }
72 | if (obs_flip != other.obs_flip) {
73 | return obs_flip < other.obs_flip;
74 | }
75 | return charge_flip < other.charge_flip;
76 | }
77 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/rgb_edge.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_DEM_GRAPH_H
18 | #define _CHROMOBIUS_DEM_GRAPH_H
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "chromobius/datatypes/atomic_error.h"
25 | #include "chromobius/datatypes/color_basis.h"
26 |
27 | namespace chromobius {
28 |
29 | struct RgbEdge;
30 |
31 | /// Represents an error with at most one symptom of each color.
32 | struct RgbEdge {
33 | node_offset_int red_node;
34 | node_offset_int green_node;
35 | node_offset_int blue_node;
36 | obsmask_int obs_flip;
37 | Charge charge_flip;
38 |
39 | inline node_offset_int color_node(Charge c) const {
40 | if (c == 0) {
41 | return BOUNDARY_NODE;
42 | }
43 | return (&red_node)[c - 1];
44 | }
45 | inline node_offset_int &color_node(Charge c) {
46 | assert(c != NEUTRAL);
47 | return (&red_node)[c - 1];
48 | }
49 |
50 | size_t weight() const;
51 | bool operator<(const RgbEdge &other) const;
52 | bool operator==(const RgbEdge &other) const;
53 | bool operator!=(const RgbEdge &other) const;
54 | std::string str() const;
55 | };
56 | std::ostream &operator<<(std::ostream &out, const RgbEdge &val);
57 |
58 | } // namespace chromobius
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/rgb_edge.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/datatypes/rgb_edge.h"
16 |
17 | #include "gtest/gtest.h"
18 |
19 | using namespace chromobius;
20 |
21 | TEST(dem_rgb_edge, dem_rgb_edge_basics) {
22 | RgbEdge e{.red_node = 5, .green_node = 7, .blue_node = 9, .obs_flip = 1, .charge_flip = Charge::NEUTRAL};
23 |
24 | ASSERT_TRUE(e == (RgbEdge{5, 7, 9, 1, Charge::NEUTRAL}));
25 | ASSERT_FALSE(e == (RgbEdge{4, 7, 9, 1, Charge::NEUTRAL}));
26 | ASSERT_FALSE(e == (RgbEdge{5, 6, 9, 1, Charge::NEUTRAL}));
27 | ASSERT_FALSE(e == (RgbEdge{5, 7, 8, 1, Charge::NEUTRAL}));
28 | ASSERT_FALSE(e == (RgbEdge{5, 7, 9, 2, Charge::NEUTRAL}));
29 | ASSERT_FALSE(e == (RgbEdge{5, 7, 9, 1, Charge::R}));
30 |
31 | ASSERT_TRUE(e != (RgbEdge{5, 7, 9, 2, Charge::NEUTRAL}));
32 | ASSERT_FALSE(e != (RgbEdge{5, 7, 9, 1, Charge::NEUTRAL}));
33 |
34 | ASSERT_EQ(
35 | e.str(),
36 | "RgbEdge{.red_node=5, .green_node=7, .blue_node=9, .obs_flip=1, "
37 | ".charge_flip=NEUTRAL}");
38 | }
39 |
40 | TEST(dem_rgb_edge, dem_rgb_edge_weight) {
41 | ASSERT_EQ((RgbEdge{.red_node = 2, .green_node = 3, .blue_node = 7, .obs_flip = 5}.weight()), 3);
42 | ASSERT_EQ((RgbEdge{.red_node = 2, .green_node = 3, .blue_node = 7, .obs_flip = 0}.weight()), 3);
43 | ASSERT_EQ(
44 | (RgbEdge{.red_node = BOUNDARY_NODE, .green_node = BOUNDARY_NODE, .blue_node = 7, .obs_flip = 5}.weight()), 1);
45 | ASSERT_EQ(
46 | (RgbEdge{.red_node = BOUNDARY_NODE, .green_node = BOUNDARY_NODE, .blue_node = BOUNDARY_NODE, .obs_flip = 5}
47 | .weight()),
48 | 0);
49 | ASSERT_EQ((RgbEdge{.red_node = BOUNDARY_NODE, .green_node = 3, .blue_node = 7, .obs_flip = 5}.weight()), 2);
50 | ASSERT_EQ((RgbEdge{.red_node = 2, .green_node = BOUNDARY_NODE, .blue_node = 7, .obs_flip = 5}.weight()), 2);
51 | ASSERT_EQ((RgbEdge{.red_node = 2, .green_node = 5, .blue_node = BOUNDARY_NODE, .obs_flip = 5}.weight()), 2);
52 | }
53 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/stim_integration.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/datatypes/stim_integration.h"
16 |
17 | #include
18 |
19 | using namespace chromobius;
20 |
21 | ColorBasis chromobius::detector_instruction_to_color_basis(
22 | const stim::DemInstruction &instruction, std::span coord_offsets) {
23 | assert(instruction.type == stim::DemInstructionType::DEM_DETECTOR);
24 | bool failed = false;
25 | double c = -2;
26 | if (instruction.arg_data.size() > 3) {
27 | c = instruction.arg_data[3];
28 | if (coord_offsets.size() > 3) {
29 | c += coord_offsets[3];
30 | }
31 | } else {
32 | failed = true;
33 | }
34 |
35 | int r = 0;
36 | if (c < -1 || c > 5) {
37 | failed = true;
38 | } else {
39 | r = (int)c;
40 | if (r != c) {
41 | failed = true;
42 | }
43 | }
44 | if (failed) {
45 | throw std::invalid_argument(
46 | "Expected all detectors to have at least 4 coordinates, with the 4th "
47 | "identifying the basis and color "
48 | "(RedX=0, GreenX=1, BlueX=2, RedZ=3, GreenZ=4, BlueZ=5), but got " +
49 | instruction.str());
50 | }
51 | if (r == -1) {
52 | return ColorBasis{
53 | .color=Charge::NEUTRAL,
54 | .basis=Basis::UNKNOWN_BASIS,
55 | .ignored=true,
56 | };
57 | }
58 | constexpr std::array mapping{
59 | ColorBasis{Charge::R, Basis::X},
60 | ColorBasis{Charge::G, Basis::X},
61 | ColorBasis{Charge::B, Basis::X},
62 | ColorBasis{Charge::R, Basis::Z},
63 | ColorBasis{Charge::G, Basis::Z},
64 | ColorBasis{Charge::B, Basis::Z},
65 | };
66 | return mapping[r];
67 | }
68 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/stim_integration.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_STIM_INTEGRATION_H
18 | #define _CHROMOBIUS_STIM_INTEGRATION_H
19 |
20 | #include
21 | #include
22 |
23 | #include "chromobius/datatypes/conf.h"
24 | #include "chromobius/datatypes/color_basis.h"
25 | #include "stim.h"
26 |
27 | namespace chromobius {
28 |
29 | ColorBasis detector_instruction_to_color_basis(
30 | const stim::DemInstruction &instruction, std::span coord_offsets);
31 |
32 | } // namespace chromobius
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/stim_integration.test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/datatypes/stim_integration.h"
16 |
17 | #include "gtest/gtest.h"
18 |
19 | using namespace chromobius;
20 |
21 | TEST(atomic_error, detector_instruction_to_color_basis) {
22 | std::vector args{-1, -1, -1, 2};
23 | std::vector offsets{-3, -3, -3, 3, -2};
24 | stim::DemInstruction instruction{
25 | .arg_data = args,
26 | .target_data = {},
27 | .type = stim::DemInstructionType::DEM_DETECTOR,
28 | };
29 | ASSERT_EQ(detector_instruction_to_color_basis(instruction, offsets), (ColorBasis{Charge::B, Basis::Z}));
30 | offsets[3] = 100;
31 | ASSERT_THROW({ detector_instruction_to_color_basis(instruction, offsets); }, std::invalid_argument);
32 | offsets[3] = 0.5;
33 | ASSERT_THROW({ detector_instruction_to_color_basis(instruction, offsets); }, std::invalid_argument);
34 | args[3] = 0.5;
35 | ASSERT_EQ(detector_instruction_to_color_basis(instruction, offsets), (ColorBasis{Charge::G, Basis::X}));
36 | args[3] = -1.5;
37 | ASSERT_EQ(detector_instruction_to_color_basis(instruction, offsets), (ColorBasis{Charge::NEUTRAL, Basis::UNKNOWN_BASIS, true}));
38 | }
39 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/xor_vec.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_XOR_VEC_H
18 | #define _CHROMOBIUS_XOR_VEC_H
19 |
20 | #include
21 | #include
22 |
23 | namespace chromobius {
24 |
25 | template
26 | inline std::span inplace_xor_sort(std::span items) {
27 | std::sort(items.begin(), items.end());
28 | size_t new_size = 0;
29 | for (size_t k = 0; k < items.size(); k++) {
30 | if (new_size > 0 && items[k] == items[new_size - 1]) {
31 | new_size--;
32 | } else {
33 | if (k != new_size) {
34 | std::swap(items[new_size], items[k]);
35 | }
36 | new_size++;
37 | }
38 | }
39 | return items.subspan(0, new_size);
40 | }
41 |
42 | } // namespace chromobius
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/chromobius/datatypes/xor_vec.test.cc:
--------------------------------------------------------------------------------
1 | #include "chromobius/datatypes/xor_vec.h"
2 |
3 | #include "gtest/gtest.h"
4 |
5 | using namespace chromobius;
6 |
7 | TEST(xor_vec, inplace_xor_sort) {
8 | auto f = [](std::vector v) -> std::vector {
9 | std::span s = v;
10 | auto r = inplace_xor_sort(s);
11 | v.resize(r.size());
12 | return v;
13 | };
14 | ASSERT_EQ(f({}), (std::vector({})));
15 | ASSERT_EQ(f({5}), (std::vector({5})));
16 | ASSERT_EQ(f({5, 5}), (std::vector({})));
17 | ASSERT_EQ(f({5, 5, 5}), (std::vector({5})));
18 | ASSERT_EQ(f({5, 5, 5, 5}), (std::vector({})));
19 | ASSERT_EQ(f({5, 4, 5, 5}), (std::vector({4, 5})));
20 | ASSERT_EQ(f({4, 5, 5, 5}), (std::vector({4, 5})));
21 | ASSERT_EQ(f({5, 5, 5, 4}), (std::vector({4, 5})));
22 | ASSERT_EQ(f({4, 5, 5, 4}), (std::vector({})));
23 | ASSERT_EQ(f({3, 5, 5, 4}), (std::vector({3, 4})));
24 | }
25 |
--------------------------------------------------------------------------------
/src/chromobius/decode/matcher_interface.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_DECODE_MATCHER_INTERFACE_H
18 | #define _CHROMOBIUS_DECODE_MATCHER_INTERFACE_H
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "stim.h"
25 |
26 | namespace chromobius {
27 |
28 | /// This class is used to implement polymorphism
29 | struct MatcherInterface {
30 | virtual ~MatcherInterface(){};
31 |
32 | /// Creates a new instance of the matcher, configured for the given detector error model.
33 | virtual std::unique_ptr configured_for_mobius_dem(const stim::DetectorErrorModel &dem) = 0;
34 |
35 | /// Performs matching on the given mobius dem detection events, producing edges.
36 | ///
37 | /// Args:
38 | /// mobius_detection_event_indices: The detection events to decode.
39 | /// out_edge_buffer: Where to write edges to. Edges should be rewritten in an
40 | /// interleaved fashion, so that (out_edge_buffer[2*k], out_edge_buffer[2*k+1])
41 | /// is an edge. There should be no boundary edges in the result, since the mobius
42 | /// dem is guaranteed to not contain any boundary edges.
43 | virtual void match_edges(
44 | const std::vector &mobius_detection_event_indices, std::vector *out_edge_buffer, float *out_weight = nullptr) = 0;
45 | };
46 |
47 | } // namespace chromobius
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/src/chromobius/decode/pymatcher.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "chromobius/decode/pymatcher.h"
16 |
17 | using namespace chromobius;
18 |
19 | PymatchingMatcher::PymatchingMatcher() : pymatching_matcher(), weight_scaling_constant(1) {
20 | }
21 |
22 | PymatchingMatcher::PymatchingMatcher(const stim::DetectorErrorModel &dem)
23 | : pymatching_matcher(pm::detector_error_model_to_mwpm(dem, 1 << 24, true)), weight_scaling_constant(pymatching_matcher.flooder.graph.normalising_constant) {
24 |
25 | }
26 |
27 | void PymatchingMatcher::match_edges(
28 | const std::vector &mobius_detection_event_indices,
29 | std::vector *out_edge_buffer,
30 | float *out_weight) {
31 | pm::decode_detection_events_to_edges(pymatching_matcher, mobius_detection_event_indices, *out_edge_buffer);
32 | if (out_weight != nullptr) {
33 | pm::total_weight_int w = 0;
34 | auto &e = *out_edge_buffer;
35 | for (size_t k = 0; k < e.size(); k += 2) {
36 | auto &d1 = pymatching_matcher.search_flooder.graph.nodes[e[k]];
37 | auto &d2 = pymatching_matcher.search_flooder.graph.nodes[e[k + 1]];
38 | w += d2.neighbor_weights[d2.index_of_neighbor(&d1)];
39 | }
40 | *out_weight = (float)(w / weight_scaling_constant);
41 | }
42 | }
43 |
44 | std::unique_ptr PymatchingMatcher::configured_for_mobius_dem(const stim::DetectorErrorModel &dem) {
45 | std::unique_ptr result;
46 | result.reset(new PymatchingMatcher(dem));
47 | return result;
48 | }
49 |
--------------------------------------------------------------------------------
/src/chromobius/decode/pymatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_DECODE_PYMATCHER_H
18 | #define _CHROMOBIUS_DECODE_PYMATCHER_H
19 |
20 | #include "chromobius/decode/matcher_interface.h"
21 | #include "pymatching/sparse_blossom/driver/mwpm_decoding.h"
22 | #include "stim.h"
23 |
24 | namespace chromobius {
25 |
26 | struct PymatchingMatcher : MatcherInterface {
27 | pm::Mwpm pymatching_matcher;
28 | double weight_scaling_constant;
29 |
30 | PymatchingMatcher();
31 | PymatchingMatcher(const stim::DetectorErrorModel &dem);
32 | virtual ~PymatchingMatcher() = default;
33 |
34 | virtual std::unique_ptr configured_for_mobius_dem(const stim::DetectorErrorModel &dem) override;
35 |
36 | virtual void match_edges(
37 | const std::vector &mobius_detection_event_indices, std::vector *out_edge_buffer, float *out_weight = nullptr) override;
38 | };
39 |
40 | } // namespace chromobius
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/chromobius/graph/charge_graph.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _CHROMOBIUS_CHARGE_GRAPH_H
18 | #define _CHROMOBIUS_CHARGE_GRAPH_H
19 |
20 | #include