Skip to content

Commit

Permalink
Comment addressments
Browse files Browse the repository at this point in the history
  • Loading branch information
stand-by committed Jul 26, 2024
1 parent 5efb8a6 commit 1b14bd3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 17 additions & 19 deletions fast_pauli/cpp/include/__pauli_string.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#ifndef __PAULI_STRING_HPP
#define __PAULI_STRING_HPP

#include <cstddef>
#include <fmt/format.h>
#include <fmt/ranges.h>

#include <algorithm>
#include <cstring>
#include <experimental/mdspan>
#include <ranges>
#include <string>
Expand Down Expand Up @@ -156,26 +154,27 @@ struct PauliString {
return 1UL;
}
};
// Helper function that resolves first value of pauli string
auto inital_value = [&nY]() -> std::complex<T> {
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) {
Expand Down Expand Up @@ -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<T>));
std::copy_n(&states_T(k[i], 0), states_T.extent(1), &new_states_T(i, 0));
const std::complex<T> 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;
}
}
}
Expand Down

0 comments on commit 1b14bd3

Please sign in to comment.