Repository navigation
Conversation
Signed-off-by: Snehal Raj <snehalraj808@gmail.com>
…ounts Update the three agent references to document 2n-3 Toffolis for n >= 2 and zero Toffolis for n = 1. Replace the stale carry explanation and fix the arithmetic reference's test selector. Clarify operand, carry, and small-width contracts. Reuse one resource estimate per case and remove the redundant slope test. Validation: - Arithmetic and composition: 133 passed, no skips. - Reference command: 40 passed, including 24 resource cases. - Skill routing and packaging: 768 passed, 3 subtests passed. - YAPF 0.43.0 and git diff --check passed. Signed-off-by: Snehal Raj <snehalraj808@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses #79 and follows the discussion in #47. It reduces modular register addition and subtraction from
2n−2to2n−3Toffolis forn≥2. The constant wrappers inherit the saving.Cuccaro, Draper, Kutin, and Moulton describe the reference algorithm in A new quantum ripple-carry addition circuit (2004), Section 4.1 and Table 1, arXiv:quant-ph/0410184. They add the lower
n−1bits, write the carry into the highest sum bit, and complete that bit with a CNOT. They give the2n−3Toffoli count forn≥3. Section 3, improvement 5, explains the direct carry calculation.The existing circuit computes the last required carry into an operand bit, copies it into the sum, and then uncomputes it. For four distinct wires, the local replacement is:
Both sequences leave
wunchanged and mapttot XOR w XOR (u AND v). After commuting the top-bit CNOT past this sequence, the replacement saves one Toffoli.In
_arithmetic.py, the ordinary carry sweep stops one position earlier.subtract_registerreverses every gate explicitly. The one-bit case remains a CNOT; the two-bit case uses one Toffoli and two CNOTs. The docstrings state the new costs and the operand contracts: equal-width, disjoint little-endian registers, a clean carry on entry, and restoration on exit.The surrounding documentation changes keep the agent references consistent with the implementation:
skills/cudaq-algorithms/references/primitives/primitives-arithmetic.md: update the formulas and carry explanation. Fix the test selector to include the renamed register resource tests and the constant resource tests.skills/cudaq-algorithms/references/primitives/primitives.md: update the arithmetic cost summary.skills/cudaq-algorithms/references/conventions/resource-levels.md: update the logical Toffoli formulas while preserving the distinction from synthesized T-gate and hardware costs.In
tests/python/test_primitives_arithmetic.py:b, superposed-acorrectness tests at widths 1–5.a, clean workspace, and relative phase.0, 1, 3, 5, 13, 509logical Toffolis at widths 1, 2, 3, 4, 8, and 256 for both directions and constant wrappers.The 256-bit cases use resource estimation only.
Local validation on CUDA-Q 0.16.0, qpp-cpu, fp64:
git diff --checkpassed.Full CI remains pending maintainer approval. The broader local suite has no completed result. Two failures reproduce on unchanged upstream code: a numerical comparison in double factorization and an example that requires the missing
qsppackpackage. The remaining failures still need investigation.