Skip to content

Commit

Permalink
✅ add regression test
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Burgholzer <[email protected]>
  • Loading branch information
burgholzer committed Jul 27, 2023
1 parent 2a2800f commit b1b16b1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/dd/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1825,3 +1825,25 @@ TEST(DDPackageTest, InnerProductTopNodeConjugation) {
// it will result in +0.416.
EXPECT_NEAR(dd->expectationValue(op, evolvedState), -0.416, 0.001);
}

/**
* @brief This is a regression test for a long lasting memory leak in the DD
* package.
* @details The memory leak was caused by a bug in the normalization routine
* which was not properly returning a node to the memory manager. This occurred
* whenever the multiplication of two DDs resulted in a zero terminal.
*/
TEST(DDPackageTest, DDNodeLeakRegressionTest) {
const auto nqubits = 1U;
auto matrix = dd::GateMatrix{dd::complex_one, dd::complex_zero,
dd::complex_zero, dd::complex_zero};
auto dd = std::make_unique<dd::Package<>>(nqubits);

auto dd1 = dd->makeGateDD(matrix, nqubits, 0U);
matrix[0] = dd::complex_zero;
matrix[3] = dd::complex_one;
auto dd2 = dd->makeGateDD(matrix, nqubits, 0U);
dd->multiply(dd1, dd2);
dd->garbageCollect(true);
EXPECT_EQ(dd->mMemoryManager.getUsedCount(), 0U);
}

0 comments on commit b1b16b1

Please sign in to comment.