From 1b14bd31b7e660d301f2fb8da597d0dd6541b182 Mon Sep 17 00:00:00 2001 From: Eugene Rublenko <16805621+stand-by@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:02:44 -0400 Subject: [PATCH] Comment addressments --- README.md | 8 +---- fast_pauli/cpp/include/__pauli_string.hpp | 36 +++++++++++------------ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8e1f08a..3cbe21d 100644 --- a/README.md +++ b/README.md @@ -39,19 +39,13 @@ 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 --parallel -``` -- Install compiled python module to `fast_pauli` directory: -```bash cmake --install build -``` -- Run C++ tests: -```bash ctest --test-dir build ``` +Compiled `_fast_pauli` python module gets installed into `fast_pauli` directory. ## Design Choices diff --git a/fast_pauli/cpp/include/__pauli_string.hpp b/fast_pauli/cpp/include/__pauli_string.hpp index 38d8372..0dbc8f1 100644 --- a/fast_pauli/cpp/include/__pauli_string.hpp +++ b/fast_pauli/cpp/include/__pauli_string.hpp @@ -1,12 +1,10 @@ #ifndef __PAULI_STRING_HPP #define __PAULI_STRING_HPP -#include #include #include #include -#include #include #include #include @@ -156,26 +154,27 @@ struct PauliString { return 1UL; } }; + // Helper function that resolves first value of pauli string + auto inital_value = [&nY]() -> std::complex { + switch (nY % 4) { + case 0: + return 1.0; + case 1: + return {0.0, -1.0}; + case 2: + return -1.0; + case 3: + return {0.0, 1.0}; + } + return {}; + }; // Populate the initial values of our output k[0] = 0; for (size_t i = 0; i < ps.size(); ++i) { k[0] += (1UL << i) * diag(ps[i]); } - switch (nY % 4) { - case 0: - m[0] = 1.0; - break; - case 1: - m[0] = -1.0i; - break; - case 2: - m[0] = -1.0; - break; - case 3: - m[0] = 1.0i; - break; - } + m[0] = inital_value(); // Populate the rest of the values in a recursive-like manner for (size_t l = 0; l < n; ++l) { @@ -287,11 +286,10 @@ struct PauliString { get_sparse_repr(k, m); for (size_t i = 0; i < states_T.extent(0); ++i) { - // std::memcpy(&new_states_T(i, 0), &states_T(k_i, 0), - // states_T.extent(1) * sizeof(std::complex)); + std::copy_n(&states_T(k[i], 0), states_T.extent(1), &new_states_T(i, 0)); const std::complex c_m_i = c * m[i]; for (size_t t = 0; t < states_T.extent(1); ++t) { - new_states_T(i, t) = c_m_i * states_T(k[i], t); + new_states_T(i, t) *= c_m_i; } } }