Skip to content

Commit

Permalink
[feature/CI_setup] more CI tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesETsmith committed Jun 10, 2024
1 parent 63a9789 commit f756a89
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/test_pauli_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void __check_apply(PauliOp<double> &pauli_op, size_t n_states) {
//
// Calculate the expected new states
//
auto pop_dense = pauli_op.get_dense_repr();
std::vector<std::vector<std::complex<double>>> pop_dense =
pauli_op.get_dense_repr();

// pop_dense : d x d
// states : n x d
Expand Down Expand Up @@ -62,6 +63,10 @@ void __check_apply(PauliOp<double> &pauli_op, size_t n_states) {
// Tests
//

//
// Constructors
//

TEST_CASE("test pauli op") {
std::vector<PauliString> pauli_strings = {"IXYZ", "XIII", "XXYZ"};
std::vector<std::complex<double>> coeffs = {1i, 2., -1i};
Expand All @@ -84,6 +89,29 @@ TEST_CASE("test bad apply") {
CHECK_THROWS(pauli_op.apply(state));
}

//
// Member functions
//

TEST_CASE("test get_dense_repr") {
std::vector<PauliString> pauli_strings = {"III", "III", "III"};
std::vector<std::complex<double>> coeffs = {1, 2., 1};
PauliOp<double> pauli_op(coeffs, pauli_strings);
auto pop_dense = pauli_op.get_dense_repr();

size_t const dim = pauli_op.dims();

for (size_t i = 0; i < dim; ++i) {
for (size_t j = 0; j < dim; ++j) {
if (i == j) {
CHECK(abs(pop_dense[i][j] - std::complex<double>(4)) < 1e-6);
} else {
CHECK(abs(pop_dense[i][j]) < 1e-6);
}
}
}
}

// TODO add tests for multiple pauli strings
TEST_CASE("test apply simple") {
// Set up PauliOp
Expand Down

0 comments on commit f756a89

Please sign in to comment.