From b1b16b16ad0b9f38e6ab7ff2ffc0479ab4e39c71 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Thu, 27 Jul 2023 17:12:40 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20add=20regression=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- test/dd/test_package.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/dd/test_package.cpp b/test/dd/test_package.cpp index 47e9d8ac8..9e057a412 100644 --- a/test/dd/test_package.cpp +++ b/test/dd/test_package.cpp @@ -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>(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); +}