Skip to content

Commit

Permalink
[feature/CI_setup] more tweaking still not fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesETsmith committed Jun 7, 2024
1 parent dc4db03 commit 14c9ddf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/all_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
compiler: [g++-12, clang++-17]
python-version: ["3.10", "3.11", "3.12"]
compiler: [g++-12]
# compiler: [g++-12, clang++-17]
# python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -30,14 +32,14 @@ jobs:
- name: Configure CMake
env:
CXX: ${{ matrix.compiler }}
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_BUILD_TYPE=Release
run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_COMPILER=${CXX}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --parallel

- name: Test C++
run: OMP_NUM_THREADS=1 ctest --test-dir build --verbose
run: ctest --test-dir build --verbose

# - name: Test Python
# run: PYTHONPATH=build:$PYTHONPATH pytest -v test
45 changes: 40 additions & 5 deletions tests/test_pauli_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ TEST_CASE("test apply multistate") {

TEST_CASE("test apply multistate multistring") {
// Set up PauliOp
std::vector<PauliString> pauli_strings = {"IXYZ", "XXXX", "YZZZ",
"ZIII", "IIII", "ZZYY"};
std::vector<std::complex<double>> coeffs = {
1i, -2., 42i, 0.5, std::complex<double>(1e-3, -1e1), 0.1};
std::vector<PauliString> pauli_strings = {"IXXZYZ", "XXXXZX", "YZZXZZ",
"ZXZIII", "IIIXZI", "ZZXZYY"};
std::vector<std::complex<double>> coeffs = {1i, -2., 42i, 0.5, 1, 0.1};
// std::vector<PauliString> pauli_strings = {"IXYZ", "YYIZ"};
// std::vector<std::complex<double>> coeffs = {1, 1};
PauliOp<double> pauli_op(coeffs, pauli_strings);

size_t const dims = pauli_strings[0].dims();

// Set up random states
size_t const n_states = 10; // TODO change back to more than 1
size_t const n_states = 10;
std::vector<std::complex<double>> states_raw;
std::mdspan states =
fast_pauli::rand<std::complex<double>, 2>(states_raw, {dims, n_states});
Expand Down Expand Up @@ -161,3 +162,37 @@ TEST_CASE("test apply multistate multistring") {
}
}
}

TEST_CASE("test apply multistate multistring identity") {
// Set up PauliOp
std::vector<PauliString> pauli_strings = {"IIIIII", "IIIIII", "IIIIII",
"IIIIII", "IIIIII", "IIIIII"};
std::vector<std::complex<double>> coeffs(pauli_strings.size(),
1. / pauli_strings.size());
PauliOp<double> pauli_op(coeffs, pauli_strings);

size_t const dims = pauli_strings[0].dims();

// Set up random states
size_t const n_states = 10;
std::vector<std::complex<double>> states_raw;
std::mdspan states =
fast_pauli::rand<std::complex<double>, 2>(states_raw, {dims, n_states});

// Apply the PauliOp to a batch of states
std::vector<std::complex<double>> new_states_raw(dims * n_states, 0);
std::mdspan<std::complex<double>, std::dextents<size_t, 2>> new_states(
new_states_raw.data(), dims, n_states);
pauli_op.apply(new_states, states);

//
// States should be unchanged
//

// Check
for (size_t t = 0; t < n_states; ++t) {
for (size_t i = 0; i < dims; ++i) {
CHECK(abs(new_states(i, t) - states(i, t)) < 1e-6);
}
}
}

0 comments on commit 14c9ddf

Please sign in to comment.