diff --git a/cmake/ExternalDependencies.cmake b/cmake/ExternalDependencies.cmake index cb960a7a..6e7964b9 100644 --- a/cmake/ExternalDependencies.cmake +++ b/cmake/ExternalDependencies.cmake @@ -22,7 +22,7 @@ endif() # cmake-format: off set(MQT_CORE_VERSION 2.7.1 CACHE STRING "MQT Core version") -set(MQT_CORE_REV "ee7482834c75c6ba7b5ce5fbd74829cb513e3c01" +set(MQT_CORE_REV "04a1b371e1f4e52125471a610f0ed3cd1afe6b5d" CACHE STRING "MQT Core identifier (tag, branch or commit hash)") set(MQT_CORE_REPO_OWNER "cda-tum" CACHE STRING "MQT Core repository owner (change when using a fork)") diff --git a/src/EquivalenceCheckingManager.cpp b/src/EquivalenceCheckingManager.cpp index dd4614c7..ba2b8591 100644 --- a/src/EquivalenceCheckingManager.cpp +++ b/src/EquivalenceCheckingManager.cpp @@ -189,6 +189,10 @@ void EquivalenceCheckingManager::setupAncillariesAndGarbage() { const auto qubitDifference = largerCircuit.getNqubits() - smallerCircuit.getNqubits(); + if (qubitDifference == 0) { + return; + } + std::vector>> removed{}; removed.reserve(qubitDifference); diff --git a/test/python/test_verify.py b/test/python/test_verify.py index 38fb1ff2..4287c6bd 100644 --- a/test/python/test_verify.py +++ b/test/python/test_verify.py @@ -93,3 +93,30 @@ def test_cpp_exception_propagation_internal() -> None: with pytest.raises(ValueError, match="Lookahead application scheme can only be used for matrices."): qcec.verify(qc, qc, configuration=config) + + +def test_zx_ancilla_support() -> None: + """This is a regression test for the handling of ancilla registers in the ZX checker.""" + from qiskit.circuit import AncillaRegister + + anc = AncillaRegister(1) + + qc1 = QuantumCircuit(1, 0) + + qc1.add_register(anc) + qc1.h(anc[0]) + + qc2 = QuantumCircuit(1, 0) + qc2.add_register(anc) + + result = qcec.verify( + qc1, + qc2, + check_partial_equivalence=True, + parallel=False, + run_alternating_checker=False, + run_simulation_checker=False, + run_zx_checker=True, + run_construction_checker=False, + ) + assert result.equivalence == qcec.EquivalenceCriterion.not_equivalent diff --git a/test/test_zx.cpp b/test/test_zx.cpp index 60937782..cd00b8e9 100644 --- a/test/test_zx.cpp +++ b/test/test_zx.cpp @@ -449,3 +449,45 @@ TEST_F(ZXTest, TwoQubitRotations) { EXPECT_EQ(ecm->getResults().equivalence, ec::EquivalenceCriterion::Equivalent); } + +TEST_F(ZXTest, EmptyCircuitWithAncillas) { + auto qc1 = qc::QuantumComputation(0U); + qc1.addAncillaryRegister(1); + qc1.x(0); + + auto qc2 = qc::QuantumComputation(0U); + qc2.addAncillaryRegister(1); + + config.execution.runZXChecker = true; + config.execution.parallel = false; + config.execution.runSimulationChecker = false; + config.execution.runAlternatingChecker = false; + config.execution.runConstructionChecker = false; + ecm = std::make_unique(qc1, qc2, config); + + ecm->run(); + EXPECT_EQ(ecm->getResults().equivalence, + ec::EquivalenceCriterion::NotEquivalent); +} + +TEST_F(ZXTest, EmptyCircuitWithAncillasAndGarbage) { + auto qc1 = qc::QuantumComputation(1U); + qc1.addAncillaryRegister(1); + qc1.setLogicalQubitGarbage(1); + qc1.h(1); + + auto qc2 = qc::QuantumComputation(1U); + qc2.addAncillaryRegister(1); + qc2.setLogicalQubitGarbage(1); + + config.execution.runZXChecker = true; + config.execution.parallel = false; + config.execution.runSimulationChecker = false; + config.execution.runAlternatingChecker = false; + config.execution.runConstructionChecker = false; + ecm = std::make_unique(qc1, qc2, config); + + ecm->run(); + EXPECT_EQ(ecm->getResults().equivalence, + ec::EquivalenceCriterion::Equivalent); +}