Skip to content

Commit

Permalink
Add more C++ unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
multiphaseCFD committed Sep 13, 2024
1 parent 7c77548 commit 31a8724
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ template <class PrecisionT> class MPOTNCuda {
} else if (i == numMPOSites_ - 1) {
localModesExtents = {bondDims_[i - 1], 2, 2};
} else {
// This branch is tested in the python layer
// LCOV_EXCL_START
localModesExtents = {bondDims_[i - 1], 2, bondDims_[i], 2};
// LCOV_EXCL_STOP
}

modesExtents_int64_.emplace_back(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,29 @@ TEMPLATE_TEST_CASE("MPSTNCuda::applyMPO::2+_wires", "[MPSTNCuda_NonParam]",

CHECK(res == Pennylane::Util::approx(ref));
}

SECTION("Target at non-adjacent wire indices") {
std::size_t num_qubits = 3;

MPSTNCuda<TestType> mps_state{num_qubits, maxExtent, dev_tag};

MPSTNCuda<TestType> mps_state_mpo{num_qubits, maxExtent, dev_tag};

mps_state.applyOperations({"Hadamard", "Hadamard", "Hadamard"},
{{0}, {1}, {2}}, {false, false, false});

mps_state_mpo.applyOperations({"Hadamard", "Hadamard", "Hadamard"},
{{0}, {1}, {2}},
{false, false, false});

mps_state.applyOperation("CNOT", {0, 2}, inverse);

mps_state_mpo.applyMPOOperation(mpo_cnot, {0, 2}, max_mpo_bond);

auto ref = mps_state.getDataVector();
auto res = mps_state_mpo.getDataVector();

CHECK(res == Pennylane::Util::approx(ref));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1134,4 +1134,28 @@ TEMPLATE_TEST_CASE("MPSTNCuda::applyMPO::SingleExcitation", "[MPSTNCuda_Param]",

CHECK(res == Pennylane::Util::approx(ref));
}

SECTION("Target at non-adjacent wire indices") {
std::size_t num_qubits = 3;

MPSTNCuda<TestType> mps_state{num_qubits, maxExtent, dev_tag};

MPSTNCuda<TestType> mps_state_mpo{num_qubits, maxExtent, dev_tag};

mps_state.applyOperations({"Hadamard", "Hadamard", "Hadamard"},
{{0}, {1}, {2}}, {false, false, false});

mps_state_mpo.applyOperations({"Hadamard", "Hadamard", "Hadamard"},
{{0}, {1}, {2}}, {false, false, false});

mps_state.applyOperation("SingleExcitation", {0, 2}, false, {0.3});

mps_state_mpo.applyMPOOperation(mpo_single_excitation, {0, 2},
max_mpo_bond);

auto ref = mps_state.getDataVector();
auto res = mps_state_mpo.getDataVector();

CHECK(res == Pennylane::Util::approx(ref));
}
}

0 comments on commit 31a8724

Please sign in to comment.