Skip to content

Fix comparator decomposition register restoration - #492

Open
AthulKampiyil wants to merge 3 commits into
ProjectQ-Framework:developfrom
AthulKampiyil:fix-491-comparator-restore-registers
Open

AthulKampiyil wants to merge 3 commits into
ProjectQ-Framework:developfrom
AthulKampiyil:fix-491-comparator-restore-registers

Conversation

@AthulKampiyil

Copy link
Copy Markdown

Summary

Fixes #491.

The ComparatorQuantum decomposition could modify its input registers because the cleanup sequence did not reverse the order of dependent gate operations.

This change corrects the cleanup loop ordering and adds regression tests to verify that both input registers are restored and that the comparison bit follows the documented XOR semantics.

The tests exercise the arithmetic decomposition path and cover all 128 combinations of three-bit operands and the initial comparison-bit value.

Tests

  • pytest projectq/libs/math/_quantummath_test.py -k "comparator" -v — 10 passed, 39 deselected.
  • pytest projectq/libs/math/ — 87 passed, 5 skipped.
  • pytest — 972 passed, 395 skipped, 0 failed.
  • flake8 projectq/libs/math/_quantummath.py projectq/libs/math/_quantummath_test.py — passed with no errors.
  • git diff --check — passed with no issues.

@CLAassistant

CLAassistant commented Oct 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComparatorQuantum decomposition does not restore its input registers

2 participants