Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stand-by committed Jul 26, 2024
1 parent 80bf7d5 commit 5efb8a6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# Need to enforce -fPIC across whole project to build shared libraries
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# TODO different compilation flags for Debug/Release modes
# TODO different compilation flags for Debug/Release modes; also pull in
# target_compile_options for fast_pauli target defined below
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ pre-commit install # installs the checks as pre-commit hooks

## Build and Test

- Configure and build project:
```bash
cmake -B build -DCMAKE_CXX_COMPILER=clang++
cmake --build build
cmake --build build --parallel
```
- Install compiled python module to `fast_pauli` directory:
```bash
cmake --install build
```
- Run C++ tests:
```bash
ctest --test-dir build
```

Expand Down
8 changes: 4 additions & 4 deletions fast_pauli/cpp/include/__pauli_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ struct PauliString {

T sign = diag(po) ? -1.0 : 1.0;

// TODO any benefit from defining 1UL << l in a const auto var?
for (size_t li = (1UL << l); li < (1UL << (l + 1)); li++) {
k[li] = k[li - (1UL << l)] + (1UL << l) * sign;
m[li] = m[li - (1UL << l)] * eps;
auto const lower_bound = 1UL << l;
for (size_t li = lower_bound; li < (lower_bound << 1); li++) {
k[li] = k[li - lower_bound] + lower_bound * sign;
m[li] = m[li - lower_bound] * eps;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion fast_pauli/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ file(GLOB FAST_PAULI_BINDINGS CONFIGURE_DEPENDS "*.cpp")
find_package(pybind11 REQUIRED)

# TODO use different set of parameters depending on CMAKE_BUILD_TYPE
pybind11_add_module(_fast_pauli SHARED OPT_SIZE ${FAST_PAULI_BINDINGS})
pybind11_add_module(_fast_pauli SHARED ${FAST_PAULI_BINDINGS})
target_link_libraries(_fast_pauli PUBLIC fast_pauli)
# TODO recheck from where it is pulling in numpy headers

install(TARGETS _fast_pauli
LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/fast_pauli")
22 changes: 1 addition & 21 deletions fast_pauli/cpp/src/fast_pauli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,9 @@ namespace fp = fast_pauli;
namespace py = pybind11;
using namespace pybind11::literals;

void scale_tensor_3d(py::array_t<double> array, double scale) {
auto arr = array.mutable_unchecked<>();
std::mdspan tensor(arr.mutable_data(), arr.shape(0), arr.shape(1),
arr.shape(2));

#pragma omp parallel for collapse(3)
for (size_t i = 0; i < tensor.extent(0); i++) {
for (size_t j = 0; j < tensor.extent(1); j++) {
for (size_t k = 0; k < tensor.extent(2); k++) {
tensor(i, j, k) *= scale;
}
}
}
}

PYBIND11_MODULE(_fast_pauli, m) {
// TODO init default threading behaviour for the module

m.doc() = "Example NumPy/C++ Interface Using std::mdspan"; // optional module
// docstring
m.def("scale_tensor_3d", &scale_tensor_3d, "Scale a 3D tensor by a scalar.",
py::arg().noconvert(), py::arg("scale"));

py::class_<fp::Pauli>(m, "Pauli")
.def(py::init<>())
.def(py::init<int const>(), "code"_a)
Expand Down Expand Up @@ -100,4 +80,4 @@ PYBIND11_MODULE(_fast_pauli, m) {
[](fp::PauliString const &self) { return fmt::format("{}", self); });

py::class_<fp::SummedPauliOp<double>>(m, "SummedPauliOp").def(py::init<>());
}
}

0 comments on commit 5efb8a6

Please sign in to comment.