Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix ancillary handling in ZX checker #512

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
4 changes: 4 additions & 0 deletions src/EquivalenceCheckingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ void EquivalenceCheckingManager::setupAncillariesAndGarbage() {
const auto qubitDifference =
largerCircuit.getNqubits() - smallerCircuit.getNqubits();

if (qubitDifference == 0) {
return;
}

std::vector<std::pair<qc::Qubit, std::optional<qc::Qubit>>> removed{};
removed.reserve(qubitDifference);

Expand Down
27 changes: 27 additions & 0 deletions test/python/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 42 additions & 0 deletions test/test_zx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ec::EquivalenceCheckingManager>(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<ec::EquivalenceCheckingManager>(qc1, qc2, config);

ecm->run();
EXPECT_EQ(ecm->getResults().equivalence,
ec::EquivalenceCriterion::Equivalent);
}
Loading