analog-ecc-heights 0.1.0__tar.gz
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.
- analog_ecc_heights-0.1.0/CMakeLists.txt +161 -0
- analog_ecc_heights-0.1.0/LICENSE +21 -0
- analog_ecc_heights-0.1.0/PKG-INFO +111 -0
- analog_ecc_heights-0.1.0/README.md +87 -0
- analog_ecc_heights-0.1.0/cmake/build_info.py.in +6 -0
- analog_ecc_heights-0.1.0/docs/api.md +149 -0
- analog_ecc_heights-0.1.0/docs/installation.md +159 -0
- analog_ecc_heights-0.1.0/examples/basic_usage.py +26 -0
- analog_ecc_heights-0.1.0/examples/compare_backends.py +38 -0
- analog_ecc_heights-0.1.0/examples/height_profile.py +18 -0
- analog_ecc_heights-0.1.0/pyproject.toml +72 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/__init__.py +33 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/_dispatch.py +55 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/_validation.py +64 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/combinatorial.py +59 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/__init__.py +1 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/adapter.py +55 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/lp_common.hh +9 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/lp_workspace_glpk.hh +83 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/lp_workspace_highs.hh +186 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods.hh +32 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods_jiang_lp_glpk.cc +168 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods_jiang_lp_highs.cc +140 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods_roth_comb.cc +345 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods_roth_lp_glpk.cc +93 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods_roth_lp_highs.cc +74 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/methods_roth_mds_comb.cc +54 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/py_binding_comb.cc +126 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/py_binding_glpk.cc +79 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/py_binding_highs.cc +91 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/cpp_backend/src/utils.hh +254 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/lp.py +63 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/__init__.py +1 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/_linalg.py +174 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/_lp_solver.py +62 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/_utils.py +29 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/jiang_lp.py +92 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/roth_comb.py +176 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/roth_lp.py +57 -0
- analog_ecc_heights-0.1.0/src/analog_ecc_heights/py_backend/roth_mds_comb.py +51 -0
- analog_ecc_heights-0.1.0/src/solve_m_height_cpp.py +40 -0
- analog_ecc_heights-0.1.0/tests/native/test_comb_backends.py +171 -0
- analog_ecc_heights-0.1.0/tests/native/test_lp_backends.py +165 -0
- analog_ecc_heights-0.1.0/tests/native/test_main.cc +506 -0
- analog_ecc_heights-0.1.0/tests/test_api.py +137 -0
- analog_ecc_heights-0.1.0/tests/test_backend_equivalence.py +216 -0
- analog_ecc_heights-0.1.0/tests/test_installation.py +188 -0
- analog_ecc_heights-0.1.0/tests/test_native_isolation.py +80 -0
- analog_ecc_heights-0.1.0/tests/test_python_comb.py +171 -0
- analog_ecc_heights-0.1.0/tests/test_python_lp.py +191 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18)
|
|
2
|
+
project(analog_ecc_heights LANGUAGES CXX)
|
|
3
|
+
|
|
4
|
+
option(BUILD_TEST_MAIN "Build the standalone native test executable" OFF)
|
|
5
|
+
option(SANITIZE "Enable Address/UndefinedBehavior sanitizers" OFF)
|
|
6
|
+
option(BUILD_CPP_COMB "Build the Eigen/OpenMP combinatorial extension" ON)
|
|
7
|
+
option(USE_GLPK "Require and enable the system GLPK library" OFF)
|
|
8
|
+
option(USE_HIGHS "Require and enable the system HiGHS library" OFF)
|
|
9
|
+
option(USE_CUDA_FULL_SWEEP "Enable the experimental CUDA full sweep" OFF)
|
|
10
|
+
|
|
11
|
+
if (USE_CUDA_FULL_SWEEP)
|
|
12
|
+
message(FATAL_ERROR
|
|
13
|
+
"The CUDA full-sweep source is not part of this package. "
|
|
14
|
+
"Build with USE_CUDA_FULL_SWEEP=OFF.")
|
|
15
|
+
endif()
|
|
16
|
+
|
|
17
|
+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
18
|
+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
|
19
|
+
endif()
|
|
20
|
+
|
|
21
|
+
set(PYBIND11_FINDPYTHON ON)
|
|
22
|
+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
|
|
23
|
+
find_package(pybind11 CONFIG REQUIRED)
|
|
24
|
+
find_package(Eigen3 CONFIG REQUIRED)
|
|
25
|
+
|
|
26
|
+
if (NOT BUILD_CPP_COMB AND NOT USE_GLPK AND NOT USE_HIGHS)
|
|
27
|
+
message(FATAL_ERROR "Enable BUILD_CPP_COMB, USE_GLPK, or USE_HIGHS; use wheel.cmake=false for Python-only builds.")
|
|
28
|
+
endif()
|
|
29
|
+
set(HAS_COMB False)
|
|
30
|
+
set(HAS_GLPK False)
|
|
31
|
+
if (BUILD_CPP_COMB)
|
|
32
|
+
set(HAS_COMB True)
|
|
33
|
+
endif()
|
|
34
|
+
if (USE_GLPK)
|
|
35
|
+
find_path(GLPK_INCLUDE_DIR glpk.h)
|
|
36
|
+
find_library(GLPK_LIBRARY NAMES glpk)
|
|
37
|
+
if (NOT GLPK_INCLUDE_DIR OR NOT GLPK_LIBRARY)
|
|
38
|
+
message(FATAL_ERROR "USE_GLPK=ON requires system GLPK headers and library. Set GLPK_INCLUDE_DIR and GLPK_LIBRARY if needed.")
|
|
39
|
+
endif()
|
|
40
|
+
get_filename_component(GLPK_LIBRARY_DIR "${GLPK_LIBRARY}" DIRECTORY)
|
|
41
|
+
set(HAS_GLPK True)
|
|
42
|
+
endif()
|
|
43
|
+
set(HAS_OPENMP False)
|
|
44
|
+
if (BUILD_CPP_COMB OR USE_HIGHS)
|
|
45
|
+
find_package(OpenMP REQUIRED COMPONENTS CXX)
|
|
46
|
+
set(HAS_OPENMP True)
|
|
47
|
+
endif()
|
|
48
|
+
|
|
49
|
+
set(HAS_HIGHS False)
|
|
50
|
+
set(HIGHS_TARGET "")
|
|
51
|
+
if (USE_HIGHS)
|
|
52
|
+
find_package(HiGHS CONFIG QUIET)
|
|
53
|
+
find_package(highs CONFIG QUIET)
|
|
54
|
+
foreach(candidate IN ITEMS HiGHS::highs highs::highs highs)
|
|
55
|
+
if (TARGET ${candidate} AND NOT HIGHS_TARGET)
|
|
56
|
+
set(HIGHS_TARGET ${candidate})
|
|
57
|
+
endif()
|
|
58
|
+
endforeach()
|
|
59
|
+
|
|
60
|
+
# Existing sources include <highs/Highs.h>, so retain the include root
|
|
61
|
+
# alongside any include/highs path supplied by a config target.
|
|
62
|
+
find_path(HIGHS_INCLUDE_ROOT highs/Highs.h)
|
|
63
|
+
if (NOT HIGHS_TARGET)
|
|
64
|
+
find_library(HIGHS_LIBRARY NAMES highs)
|
|
65
|
+
if (HIGHS_INCLUDE_ROOT AND HIGHS_LIBRARY)
|
|
66
|
+
add_library(analog_ecc_system_highs UNKNOWN IMPORTED)
|
|
67
|
+
set_target_properties(analog_ecc_system_highs PROPERTIES
|
|
68
|
+
IMPORTED_LOCATION "${HIGHS_LIBRARY}"
|
|
69
|
+
INTERFACE_INCLUDE_DIRECTORIES
|
|
70
|
+
"${HIGHS_INCLUDE_ROOT};${HIGHS_INCLUDE_ROOT}/highs")
|
|
71
|
+
set(HIGHS_TARGET analog_ecc_system_highs)
|
|
72
|
+
endif()
|
|
73
|
+
endif()
|
|
74
|
+
|
|
75
|
+
if (NOT HIGHS_TARGET)
|
|
76
|
+
message(FATAL_ERROR
|
|
77
|
+
"USE_HIGHS=ON requires a system HiGHS development installation. "
|
|
78
|
+
"Set CMAKE_PREFIX_PATH to its installation prefix, or set "
|
|
79
|
+
"HIGHS_INCLUDE_ROOT and HIGHS_LIBRARY explicitly. "
|
|
80
|
+
"The Python highspy package alone is not sufficient.")
|
|
81
|
+
endif()
|
|
82
|
+
set(HAS_HIGHS True)
|
|
83
|
+
endif()
|
|
84
|
+
|
|
85
|
+
set(NATIVE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/analog_ecc_heights/cpp_backend/src")
|
|
86
|
+
set(COMB_SOURCES "${NATIVE_SOURCE_DIR}/methods_roth_comb.cc" "${NATIVE_SOURCE_DIR}/methods_roth_mds_comb.cc")
|
|
87
|
+
set(GLPK_SOURCES "${NATIVE_SOURCE_DIR}/methods_jiang_lp_glpk.cc" "${NATIVE_SOURCE_DIR}/methods_roth_lp_glpk.cc")
|
|
88
|
+
set(HIGHS_SOURCES "${NATIVE_SOURCE_DIR}/methods_jiang_lp_highs.cc" "${NATIVE_SOURCE_DIR}/methods_roth_lp_highs.cc")
|
|
89
|
+
set(NATIVE_TARGETS "")
|
|
90
|
+
if (BUILD_CPP_COMB)
|
|
91
|
+
pybind11_add_module(_comb "${NATIVE_SOURCE_DIR}/py_binding_comb.cc" ${COMB_SOURCES})
|
|
92
|
+
list(APPEND NATIVE_TARGETS _comb)
|
|
93
|
+
endif()
|
|
94
|
+
if (USE_GLPK)
|
|
95
|
+
pybind11_add_module(_glpk "${NATIVE_SOURCE_DIR}/py_binding_glpk.cc" ${GLPK_SOURCES})
|
|
96
|
+
list(APPEND NATIVE_TARGETS _glpk)
|
|
97
|
+
endif()
|
|
98
|
+
if (USE_HIGHS)
|
|
99
|
+
pybind11_add_module(_highs "${NATIVE_SOURCE_DIR}/py_binding_highs.cc" ${HIGHS_SOURCES})
|
|
100
|
+
list(APPEND NATIVE_TARGETS _highs)
|
|
101
|
+
endif()
|
|
102
|
+
set(EXTENSION_TARGETS ${NATIVE_TARGETS})
|
|
103
|
+
if (BUILD_TEST_MAIN)
|
|
104
|
+
if (NOT BUILD_CPP_COMB OR NOT USE_GLPK)
|
|
105
|
+
message(FATAL_ERROR "BUILD_TEST_MAIN requires BUILD_CPP_COMB=ON and USE_GLPK=ON.")
|
|
106
|
+
endif()
|
|
107
|
+
add_executable(test_main tests/native/test_main.cc ${COMB_SOURCES} ${GLPK_SOURCES})
|
|
108
|
+
if (USE_HIGHS)
|
|
109
|
+
target_sources(test_main PRIVATE ${HIGHS_SOURCES})
|
|
110
|
+
endif()
|
|
111
|
+
list(APPEND NATIVE_TARGETS test_main)
|
|
112
|
+
endif()
|
|
113
|
+
|
|
114
|
+
if (SANITIZE AND NOT MSVC)
|
|
115
|
+
include(CheckCXXCompilerFlag)
|
|
116
|
+
check_cxx_compiler_flag("-fsanitize=address" ANALOG_ECC_HAS_ASAN)
|
|
117
|
+
check_cxx_compiler_flag("-fsanitize=undefined" ANALOG_ECC_HAS_UBSAN)
|
|
118
|
+
endif()
|
|
119
|
+
|
|
120
|
+
foreach(native_target IN LISTS NATIVE_TARGETS)
|
|
121
|
+
target_compile_features(${native_target} PRIVATE cxx_std_17)
|
|
122
|
+
target_include_directories(${native_target} PRIVATE "${NATIVE_SOURCE_DIR}")
|
|
123
|
+
target_link_libraries(${native_target} PRIVATE Eigen3::Eigen)
|
|
124
|
+
set_target_properties(${native_target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
125
|
+
if (native_target STREQUAL "_glpk" OR native_target STREQUAL "test_main")
|
|
126
|
+
target_include_directories(${native_target} PRIVATE "${GLPK_INCLUDE_DIR}")
|
|
127
|
+
target_link_libraries(${native_target} PRIVATE "${GLPK_LIBRARY}")
|
|
128
|
+
set_target_properties(${native_target} PROPERTIES
|
|
129
|
+
BUILD_RPATH "${GLPK_LIBRARY_DIR}" INSTALL_RPATH "${GLPK_LIBRARY_DIR}")
|
|
130
|
+
endif()
|
|
131
|
+
if (NOT native_target STREQUAL "_glpk")
|
|
132
|
+
target_link_libraries(${native_target} PRIVATE OpenMP::OpenMP_CXX)
|
|
133
|
+
target_compile_definitions(${native_target} PRIVATE USE_OPENMP=1)
|
|
134
|
+
endif()
|
|
135
|
+
if (native_target STREQUAL "_highs" OR (native_target STREQUAL "test_main" AND USE_HIGHS))
|
|
136
|
+
target_compile_definitions(${native_target} PRIVATE HAVE_HIGHS=1)
|
|
137
|
+
target_link_libraries(${native_target} PRIVATE ${HIGHS_TARGET})
|
|
138
|
+
if (HIGHS_INCLUDE_ROOT)
|
|
139
|
+
target_include_directories(${native_target} PRIVATE "${HIGHS_INCLUDE_ROOT}")
|
|
140
|
+
endif()
|
|
141
|
+
set_property(TARGET ${native_target} APPEND PROPERTY BUILD_RPATH "$<TARGET_FILE_DIR:${HIGHS_TARGET}>")
|
|
142
|
+
set_property(TARGET ${native_target} APPEND PROPERTY INSTALL_RPATH "$<TARGET_FILE_DIR:${HIGHS_TARGET}>")
|
|
143
|
+
endif()
|
|
144
|
+
if (SANITIZE AND NOT MSVC)
|
|
145
|
+
if (ANALOG_ECC_HAS_ASAN)
|
|
146
|
+
target_compile_options(${native_target} PRIVATE -fsanitize=address -fno-omit-frame-pointer)
|
|
147
|
+
target_link_options(${native_target} PRIVATE -fsanitize=address)
|
|
148
|
+
endif()
|
|
149
|
+
if (ANALOG_ECC_HAS_UBSAN)
|
|
150
|
+
target_compile_options(${native_target} PRIVATE -fsanitize=undefined)
|
|
151
|
+
target_link_options(${native_target} PRIVATE -fsanitize=undefined)
|
|
152
|
+
endif()
|
|
153
|
+
endif()
|
|
154
|
+
endforeach()
|
|
155
|
+
|
|
156
|
+
configure_file(cmake/build_info.py.in "${CMAKE_CURRENT_BINARY_DIR}/_build_info.py" @ONLY)
|
|
157
|
+
install(TARGETS ${EXTENSION_TARGETS}
|
|
158
|
+
LIBRARY DESTINATION analog_ecc_heights/cpp_backend
|
|
159
|
+
RUNTIME DESTINATION analog_ecc_heights/cpp_backend)
|
|
160
|
+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_build_info.py"
|
|
161
|
+
DESTINATION analog_ecc_heights/cpp_backend)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Changcheng Yuan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: analog-ecc-heights
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Height calculations for analog error-correcting codes
|
|
5
|
+
Author-Email: Changcheng Yuan <eric.yuan.cc@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: C++
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
12
|
+
Project-URL: Repository, https://github.com/EricYJA/Analog-ECC-height-profile-methods
|
|
13
|
+
Project-URL: Issues, https://github.com/EricYJA/Analog-ECC-height-profile-methods/issues
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: numpy>=1.23
|
|
16
|
+
Requires-Dist: scipy>=1.9
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
21
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
22
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# analog-ecc-heights
|
|
26
|
+
|
|
27
|
+
Python and C++ methods for computing the height profile of analog error-correcting codes, including Jiang's LP formulations and Roth's LP and combinatorial formulations. The distribution is **`analog-ecc-heights`**; the Python import is **`analog_ecc_heights`**.
|
|
28
|
+
|
|
29
|
+
One package provides a NumPy/SciPy implementation by default and optional native backends. Installing native support does not change the default backend.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
Requires Python 3.10 or later. Pip installs NumPy >=1.23 and SciPy >=1.9 automatically. With Python and Git installed, start from a fresh checkout:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/EricYJA/Analog-ECC-height-profile-methods.git
|
|
37
|
+
cd Analog-ECC-height-profile-methods
|
|
38
|
+
python -m venv .venv
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If your Python command is `python3` or `py`, use it to create the environment. Activate it using the command for your shell:
|
|
42
|
+
|
|
43
|
+
| Platform / shell | Activation command |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| Linux or macOS / Bash or Zsh | `source .venv/bin/activate` |
|
|
46
|
+
| Windows / PowerShell | `.\.venv\Scripts\Activate.ps1` |
|
|
47
|
+
| Windows / Command Prompt | `.venv\Scripts\activate.bat` |
|
|
48
|
+
|
|
49
|
+
Then install into the active environment:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
python -m pip install .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
An existing Python environment also works. See [environment setup](docs/installation.md#choose-a-python-environment) for details and the optional Conda workflow.
|
|
56
|
+
|
|
57
|
+
The default installation does not invoke CMake or require a compiler, Eigen, GLPK, or a separately installed HiGHS library. Native support is an optional source build of this same distribution; see [installation](docs/installation.md).
|
|
58
|
+
|
|
59
|
+
## Use
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import numpy as np
|
|
63
|
+
from analog_ecc_heights import (
|
|
64
|
+
available_backends,
|
|
65
|
+
h_m_roth_primal_lp,
|
|
66
|
+
h_m_roth_primal_combinatorial,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
G = np.array([[1.0, 0.0, 1.0], [0.0, 1.0, 1.0]])
|
|
70
|
+
|
|
71
|
+
print(h_m_roth_primal_lp(G, 1)) # 2.0
|
|
72
|
+
print(h_m_roth_primal_lp(G, 1, early_quit_threshold=1.5)) # 1.5
|
|
73
|
+
print(h_m_roth_primal_combinatorial(G)) # [2.0]
|
|
74
|
+
print(available_backends()) # ["python"] in a default install
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For a native-enabled installation, select the implementation explicitly:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
h_m_roth_primal_lp(G, 1, backend="cpp-glpk")
|
|
81
|
+
h_m_roth_primal_lp(G, 1, backend="cpp-highs", num_threads=1)
|
|
82
|
+
h_m_roth_primal_combinatorial(G, 1, backend="cpp", num_threads=1)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
| Backend | Methods | Separately installed native dependencies |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| `python` | LP and combinatorial | None; LP uses the HiGHS solver included with SciPy |
|
|
88
|
+
| `cpp` | Combinatorial | Eigen headers at build time; OpenMP |
|
|
89
|
+
| `cpp-glpk` | LP | Eigen headers at build time; GLPK headers and library |
|
|
90
|
+
| `cpp-highs` | LP | Eigen headers at build time; HiGHS headers and library; OpenMP |
|
|
91
|
+
|
|
92
|
+
An unavailable backend raises an installation error. Unsupported combinations raise an argument error. Calls never switch to another backend automatically.
|
|
93
|
+
|
|
94
|
+
## Documentation and examples
|
|
95
|
+
|
|
96
|
+
- [Installation and native builds](docs/installation.md)
|
|
97
|
+
- [API, backend selection, and numerical behavior](docs/api.md)
|
|
98
|
+
- Runnable examples: [basic usage](examples/basic_usage.py), [height profiles](examples/height_profile.py), and [backend comparison](examples/compare_backends.py)
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
Licensed under the [MIT License](https://github.com/EricYJA/Analog-ECC-height-profile-methods/blob/main/LICENSE).
|
|
103
|
+
Copyright (c) 2026 Changcheng Yuan.
|
|
104
|
+
|
|
105
|
+
## References
|
|
106
|
+
|
|
107
|
+
All implementations are based on the methods and theorems developed in these papers:
|
|
108
|
+
|
|
109
|
+
1. Ron M. Roth, “[Analog Error-Correcting Codes](https://doi.org/10.1109/TIT.2020.2977918),” *IEEE Transactions on Information Theory*, 66(7), 4075–4088, 2020.
|
|
110
|
+
2. Anxiao Jiang, “[Analog Error-Correcting Codes: Designs and Analysis](https://doi.org/10.1109/TIT.2024.3454059),” *IEEE Transactions on Information Theory*, 70(11), 7740–7756, 2024.
|
|
111
|
+
3. Ron M. Roth, Ziyuan Zhu, Changcheng Yuan, Paul H. Siegel, and Anxiao Jiang, “[On the Height Profile of Analog Error-Correcting Codes](https://arxiv.org/abs/2602.20366),” *2026 IEEE International Symposium on Information Theory (ISIT)*, also available as arXiv:2602.20366.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# analog-ecc-heights
|
|
2
|
+
|
|
3
|
+
Python and C++ methods for computing the height profile of analog error-correcting codes, including Jiang's LP formulations and Roth's LP and combinatorial formulations. The distribution is **`analog-ecc-heights`**; the Python import is **`analog_ecc_heights`**.
|
|
4
|
+
|
|
5
|
+
One package provides a NumPy/SciPy implementation by default and optional native backends. Installing native support does not change the default backend.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires Python 3.10 or later. Pip installs NumPy >=1.23 and SciPy >=1.9 automatically. With Python and Git installed, start from a fresh checkout:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/EricYJA/Analog-ECC-height-profile-methods.git
|
|
13
|
+
cd Analog-ECC-height-profile-methods
|
|
14
|
+
python -m venv .venv
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If your Python command is `python3` or `py`, use it to create the environment. Activate it using the command for your shell:
|
|
18
|
+
|
|
19
|
+
| Platform / shell | Activation command |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| Linux or macOS / Bash or Zsh | `source .venv/bin/activate` |
|
|
22
|
+
| Windows / PowerShell | `.\.venv\Scripts\Activate.ps1` |
|
|
23
|
+
| Windows / Command Prompt | `.venv\Scripts\activate.bat` |
|
|
24
|
+
|
|
25
|
+
Then install into the active environment:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m pip install .
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
An existing Python environment also works. See [environment setup](docs/installation.md#choose-a-python-environment) for details and the optional Conda workflow.
|
|
32
|
+
|
|
33
|
+
The default installation does not invoke CMake or require a compiler, Eigen, GLPK, or a separately installed HiGHS library. Native support is an optional source build of this same distribution; see [installation](docs/installation.md).
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import numpy as np
|
|
39
|
+
from analog_ecc_heights import (
|
|
40
|
+
available_backends,
|
|
41
|
+
h_m_roth_primal_lp,
|
|
42
|
+
h_m_roth_primal_combinatorial,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
G = np.array([[1.0, 0.0, 1.0], [0.0, 1.0, 1.0]])
|
|
46
|
+
|
|
47
|
+
print(h_m_roth_primal_lp(G, 1)) # 2.0
|
|
48
|
+
print(h_m_roth_primal_lp(G, 1, early_quit_threshold=1.5)) # 1.5
|
|
49
|
+
print(h_m_roth_primal_combinatorial(G)) # [2.0]
|
|
50
|
+
print(available_backends()) # ["python"] in a default install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For a native-enabled installation, select the implementation explicitly:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
h_m_roth_primal_lp(G, 1, backend="cpp-glpk")
|
|
57
|
+
h_m_roth_primal_lp(G, 1, backend="cpp-highs", num_threads=1)
|
|
58
|
+
h_m_roth_primal_combinatorial(G, 1, backend="cpp", num_threads=1)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Backend | Methods | Separately installed native dependencies |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `python` | LP and combinatorial | None; LP uses the HiGHS solver included with SciPy |
|
|
64
|
+
| `cpp` | Combinatorial | Eigen headers at build time; OpenMP |
|
|
65
|
+
| `cpp-glpk` | LP | Eigen headers at build time; GLPK headers and library |
|
|
66
|
+
| `cpp-highs` | LP | Eigen headers at build time; HiGHS headers and library; OpenMP |
|
|
67
|
+
|
|
68
|
+
An unavailable backend raises an installation error. Unsupported combinations raise an argument error. Calls never switch to another backend automatically.
|
|
69
|
+
|
|
70
|
+
## Documentation and examples
|
|
71
|
+
|
|
72
|
+
- [Installation and native builds](docs/installation.md)
|
|
73
|
+
- [API, backend selection, and numerical behavior](docs/api.md)
|
|
74
|
+
- Runnable examples: [basic usage](examples/basic_usage.py), [height profiles](examples/height_profile.py), and [backend comparison](examples/compare_backends.py)
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
Licensed under the [MIT License](https://github.com/EricYJA/Analog-ECC-height-profile-methods/blob/main/LICENSE).
|
|
79
|
+
Copyright (c) 2026 Changcheng Yuan.
|
|
80
|
+
|
|
81
|
+
## References
|
|
82
|
+
|
|
83
|
+
All implementations are based on the methods and theorems developed in these papers:
|
|
84
|
+
|
|
85
|
+
1. Ron M. Roth, “[Analog Error-Correcting Codes](https://doi.org/10.1109/TIT.2020.2977918),” *IEEE Transactions on Information Theory*, 66(7), 4075–4088, 2020.
|
|
86
|
+
2. Anxiao Jiang, “[Analog Error-Correcting Codes: Designs and Analysis](https://doi.org/10.1109/TIT.2024.3454059),” *IEEE Transactions on Information Theory*, 70(11), 7740–7756, 2024.
|
|
87
|
+
3. Ron M. Roth, Ziyuan Zhu, Changcheng Yuan, Paul H. Siegel, and Anxiao Jiang, “[On the Height Profile of Analog Error-Correcting Codes](https://arxiv.org/abs/2602.20366),” *2026 IEEE International Symposium on Information Theory (ISIT)*, also available as arXiv:2602.20366.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Python API
|
|
2
|
+
|
|
3
|
+
Import public functions from `analog_ecc_heights`. The matrix and height index can be positional; all configuration options are keyword-only.
|
|
4
|
+
|
|
5
|
+
A generator matrix `G` has shape `(k, n)` and generates codewords `u @ G`. A parity-check matrix `H` has shape `(r, n)` and describes codewords satisfying `H @ c = 0`. Matrix inputs must be real, finite, two-dimensional arrays or convertible array-like values. They are converted to float64 as needed; caller data is not modified. Contiguous, strided, and read-only arrays are supported.
|
|
6
|
+
|
|
7
|
+
## Linear-programming methods
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
h_m_jiang_original_lp(G, m, *, backend="python", num_threads=None)
|
|
11
|
+
|
|
12
|
+
h_m_jiang_simplified_lp(
|
|
13
|
+
G, m, *, backend="python", early_quit_threshold=float("inf"), num_threads=None
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
h_m_roth_primal_lp(
|
|
17
|
+
G, m, *, backend="python", early_quit_threshold=float("inf"), num_threads=None
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
h_m_roth_dual_lp(
|
|
21
|
+
G, m, *, backend="python", early_quit_threshold=float("inf"), num_threads=None
|
|
22
|
+
)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
All four accept `backend="python"`, `"cpp-glpk"`, or `"cpp-highs"` and return a Python `float`.
|
|
26
|
+
|
|
27
|
+
| Function | Index restriction | Additional behavior |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `h_m_jiang_original_lp` | `1 <= m <= min(30, n-1)` | No zero column in `G`; no threshold option |
|
|
30
|
+
| `h_m_jiang_simplified_lp` | `1 <= m <= min(30, n-1)` | Supports threshold capping |
|
|
31
|
+
| `h_m_roth_primal_lp` | `0 <= m < n` | At `m=0`, returns `min(1, threshold)` |
|
|
32
|
+
| `h_m_roth_dual_lp` | `0 <= m < n` | At `m=0`, returns `min(1, threshold)` |
|
|
33
|
+
|
|
34
|
+
LP matrices must have at least one row and one column. Unlike the combinatorial APIs, LP calls do not require full row rank. The 30-coordinate limit applies to the **height index `m` in Jiang's methods**, not the number of columns in `G`.
|
|
35
|
+
|
|
36
|
+
### Thresholds and solver outcomes
|
|
37
|
+
|
|
38
|
+
The three threshold-capable methods return `min(h_m, early_quit_threshold)`. The default positive infinity computes the full height. A completed inner solve that exceeds the threshold permits early exit; a result equal to the threshold can still require additional enumeration. The reported value is capped, rather than an uncapped lower bound.
|
|
39
|
+
|
|
40
|
+
Real thresholds, including negative values and infinities, are accepted; NaN is rejected. Original Jiang has no threshold argument. Positive infinity represents an unbounded height. Infeasible sign/order cases are ignored in original Jiang; infeasibility of a Roth dual inner problem certifies an infinite height. Unexpected solver failures raise an error and do not produce a height or trigger a backend switch.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from analog_ecc_heights import h_m_roth_primal_lp
|
|
44
|
+
|
|
45
|
+
G = [[1.0, -2.0, 4.0]]
|
|
46
|
+
assert abs(h_m_roth_primal_lp(G, 1) - 2.0) < 1e-8
|
|
47
|
+
assert h_m_roth_primal_lp(G, 1, early_quit_threshold=1.5) == 1.5
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Combinatorial methods
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
h_m_roth_primal_combinatorial(
|
|
54
|
+
G, m=None, *, backend="python", tol=1e-10, num_threads=None
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
h_m_roth_primal_combinatorial_pruning(
|
|
58
|
+
G, m, *, backend="python", tol=1e-10, num_threads=None
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
h_m_roth_dual_combinatorial_generator(
|
|
62
|
+
G, m, *, backend="python", tol=1e-10, num_threads=None
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
h_m_roth_dual_combinatorial_parity(
|
|
66
|
+
H, m, *, backend="python", tol=1e-10, num_threads=None
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
h_m_roth_mds_combinatorial(
|
|
70
|
+
G, m, *, backend="python", tol=1e-10, num_threads=None
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
h_m_roth_mds_combinatorial_parity(
|
|
74
|
+
H, m, *, backend="python", tol=1e-10, num_threads=None
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
All six accept `backend="python"` or `"cpp"`. No LP solver name is selected for combinatorial calls.
|
|
79
|
+
|
|
80
|
+
Generator matrices must have `1 <= k <= n` and full row rank under `tol`. Parity-check matrices must have `0 <= r < n`, at least one column, and full row rank under `tol`; a `(0, n)` parity-check matrix is allowed. `tol` must be finite and nonnegative. It controls complete-pivot LU rank decisions using the parent matrix's scale; see [numerical behavior](#numerical-behavior).
|
|
81
|
+
|
|
82
|
+
Scalar indices satisfy `0 <= m < n`. General combinatorial methods return `1.0` at `m=0`, a finite height when supported by the code's minimum distance, or positive infinity. Pruning computes the same scalar quantity as the primal method while eliminating candidates using bounds.
|
|
83
|
+
|
|
84
|
+
### Full profiles
|
|
85
|
+
|
|
86
|
+
Only `h_m_roth_primal_combinatorial` accepts `m=None`, which is also its default. It returns a `list[float]`:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
[h_1, h_2, ..., h_(n-k)]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The list does not include `h_0`; its length is the redundancy `n-k`. A square full-rank generator has an empty profile. Full profiles share computation across indices. Integer `m` returns a scalar `float`.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from analog_ecc_heights import h_m_roth_primal_combinatorial
|
|
96
|
+
|
|
97
|
+
G = [[1.0, -2.0, 4.0]]
|
|
98
|
+
print(h_m_roth_primal_combinatorial(G)) # [2.0, 4.0]
|
|
99
|
+
print(h_m_roth_primal_combinatorial(G, 2)) # 4.0
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### MDS specializations
|
|
103
|
+
|
|
104
|
+
`h_m_roth_mds_combinatorial` requires `m=n-k`; its parity counterpart requires `m=r`. Both check the MDS condition under `tol` and reject non-MDS input. **At zero redundancy, these two specializations return `0.0`**. This is distinct from the general methods' `m=0` convention of `1.0`.
|
|
105
|
+
|
|
106
|
+
## Backend availability and threads
|
|
107
|
+
|
|
108
|
+
Every method defaults to `backend="python"`, even when native support is installed. Choose a backend explicitly to use a different implementation:
|
|
109
|
+
|
|
110
|
+
| Backend | Supported methods | Implementation |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| `python` | LP and combinatorial | NumPy/SciPy; LP uses SciPy's HiGHS solver |
|
|
113
|
+
| `cpp` | Combinatorial | C++ |
|
|
114
|
+
| `cpp-glpk` | LP | C++ with GLPK |
|
|
115
|
+
| `cpp-highs` | LP | C++ with HiGHS |
|
|
116
|
+
|
|
117
|
+
Install optional backends using the [installation guide](installation.md#install-optional-native-backends). Check which backends are available in your environment:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from analog_ecc_heights import available_backends
|
|
121
|
+
|
|
122
|
+
print(available_backends()) # ["python"] in a default installation
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`available_backends()` returns a `list[str]` containing `"python"` and whichever native backends can be loaded. An unavailable backend or solver failure raises an error; calls never switch to another backend automatically.
|
|
126
|
+
|
|
127
|
+
Pass `num_threads=1` for sequential execution. Leaving it as `None` uses the backend default:
|
|
128
|
+
|
|
129
|
+
| Backend | Accepted `num_threads` | Meaning of `None` |
|
|
130
|
+
| --- | --- | --- |
|
|
131
|
+
| `python` | `None` or `1` | Sequential Python enumeration |
|
|
132
|
+
| `cpp-glpk` | `None` or `1` | Sequential GLPK enumeration |
|
|
133
|
+
| `cpp`, `cpp-highs` | Positive integers; OpenMP required at build time | 16 workers |
|
|
134
|
+
|
|
135
|
+
The parameter controls this package's workers. It does not set every NumPy/SciPy or BLAS internal thread count. Unsupported thread counts raise an error; an explicit parallel request is not silently ignored.
|
|
136
|
+
|
|
137
|
+
Large problems can require exponentially many cases. Compare performance using matrices and height indices representative of your application.
|
|
138
|
+
|
|
139
|
+
## Numerical behavior
|
|
140
|
+
|
|
141
|
+
`tol` applies only to combinatorial methods. Rank decisions use complete-pivot LU with cutoff `tol * reference_scale`, where the reference scale is the largest absolute entry of the input matrix. Submatrices use their parent matrix's scale. Changing `tol` can change rank and MDS classifications, and whether a reported height is finite.
|
|
142
|
+
|
|
143
|
+
LP feasibility and optimality tolerances are determined by the selected solver; LP functions do not accept `tol`. Nearly singular matrices, extreme coefficient scales, and different solver versions can produce different results or classifications across methods and backends. Compare finite results with a suitable numerical tolerance and handle positive infinity separately.
|
|
144
|
+
|
|
145
|
+
## Errors and compatibility
|
|
146
|
+
|
|
147
|
+
Wrong option types raise `TypeError`; invalid matrix values, index ranges, backend combinations, rank conditions, and unsupported thread requests raise `ValueError`. Missing native support raises `ImportError` with installation guidance. LP solver failures raise `RuntimeError`. `m` and `num_threads` must be integer values; booleans are rejected.
|
|
148
|
+
|
|
149
|
+
`solve_m_height_cpp` remains available for existing code after installing the corresponding native backends. Its original function names, positional options, and native defaults are supported. Import from `analog_ecc_heights` to use the backend selection and option validation described in this guide.
|