New src-layout and extensions framework #322
dsvandet
started this conversation in
Project Notes
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Update for:
This PR handles or partially handles the following Issues:
#312 [Full] - Main branch is not passing tests
#303 [Partial] - Installing fails: building editable results in error
#270: [Full] - File clean up
Details and comments
The current C++ analysis extensions are causing several issues: cyclic imports, not passing tests and compiling on Windows machines. In order to fix this problem these extensions where refactored and a new build system was implemented. This result is aimed at fixing these issues and creating a good framework for extensions (C, C++, Julia, Rust, etc).
The new structure switches from the ad-hoc-layout to the src-layout. The is useful for extensions and for reasons that can be read here (for example: https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/ or https://hynek.me/articles/testing-packaging/ etc.)
The new src-layout has the following structure:
The contents of the new directory structure are as follows:
The primary source code for the framework is contained within the
src
directory. Theextern
directory contains libraries needed by the framework that my not be on an individuals machine. The outer mostintern
directory contains libraries and code that are developed for the framework but that are not specific to QEC. The innerintern
directories contain code for extensions is internal to the project and that are not needed to link to the extensions (e.g. cpp files, for internal header files). Public header files and such are stored in the primary category directories (such asanalysis
oroperators
). Thebindings
directories contain extension code to bind libraries to Python.NOTE: pybind11 is currently included directly. This will make it easier for people but should belater removed in favor of
find_package(PYBIND11 REQUIRED)
or other methods.Support Files
/doc/
/releasenotes
/test
Build System
/build_files/
/build_files/cmake/
/CMakeLists.txt
Framework Code (/src/)
/src/
/src/qiskit_qec
/src/qiskit_qec/analysis
/src/qiskit_qec/analysis/bindings
/src/qikit_qec/analysis/intern/
/src/qiskit_qec/circuits
/src/qiskit_qec/analysis
/src/qiskit_qec/codes
/src/qiskit_qec/exceptions.py
/src/qiskit_qec/info
/src/qiskit_qec/noise
/src/qiskit_qec/structures
/src/qiskit_qec/VERSION.txt
/src/qiskit_qec/circuits
/src/qiskit_qec/decoders
/src/qiskit_qec/geometry
/src/qiskit_qec/linear
/src/qiskit_qec/operators
/src/qiskit_qec/utils
Internal Framework Code (/intern/)
External Framework Code (/extern/)
/extern/
Build System
The build system is based on the following components:
setuptools
setuptools_rust
CMake
pybind11
Julia
Cargo
Extensions
Code for extensions are split into libraries and python bindings. The library should be usable directly. The bindings simply bind python methods to the library methods. The bindings code is stored in one of the the
bindings
directories located in the appropriate category directory (e.g. analysis or operator or linear etc). Public header files should be in the main category directory. Internal header and base code should be in theintern
directories that are located next with thebindings
directories. TheCMakeLists.txt
file for building the library should be in the primary category directory.An example binding CMakeLists.txt file is as follows:
Refactoring of the Analysis extension:
The analysis extension has been refactored. The primary module is
qiskit_qec.analysis._c_analysis
. The following C/C++ extensions are available:_CErrorPropagator
C_ERROR_PROPAGATOR
_CFaultEnumerator
C_FAULT_ENUMERATOR
_CFaultSampler
C_FAULT_SAMPLER
_c_minimum_distance
C_MIN_DISTANCE
_c_minimum_distance_by_tests
C_MIN_DISTANCE_BY_TESTS
_c_rank
C_RANK
_c_isotropic
C_ISOTROPIC
The flag can be used to check if a given extension is available: For example:
Note: Do NOT load extensions directly into one the category dunder init files (
__init__.py)
as this will cause cyclic imports. If this is wanted than create a python wrapper, like minimum_distance that loads the extension from the appropriate extensions module, and import that wrapper instead.The Python interface to these analysis extensions has slight changed:
ErrorProbagator
class has been renamedBaseErrorProbagator
ep = ErrorProbagator()
and this will return either the python only propagator or the C extension version. TheEPSelector
is no longer needed.Building the Framework
The framework can be built with:
or if editable mode is wanted:
Beta Was this translation helpful? Give feedback.
All reactions