Skip to content

✨ Add controlled multiplication modulo N benchmark - #2409

Draft
denialhaag wants to merge 5 commits into
mainfrom
codex/add-controlled-multiplication-modulo-n
Draft

✨ Add controlled multiplication modulo N benchmark#2409
denialhaag wants to merge 5 commits into
mainfrom
codex/add-controlled-multiplication-modulo-n

Conversation

@denialhaag

@denialhaag denialhaag commented Sep 5, 2026

Copy link
Copy Markdown
Member

Description

🤖 AI text below 🤖

Add a controlled multiplication modulo N benchmark based on Figures 5 and 6 of Beauregard's circuit for Shor's algorithm: https://arxiv.org/abs/quant-ph/0205095

Each instance prepares the control and multiplicand registers in a uniform superposition, then conditionally writes multiplier * multiplicand mod modulus to an n + 1-qubit accumulator. The logical result preserves the control, multiplicand, and accumulator so the analytic reference checks their full correlation.

Expose the benchmark through validated C++ and Python APIs, strict instance specifications and manifests, command-line discovery, and structured MLIR generation. The generator retains the modular Fourier-adder schedule, including its multi-controlled phase operations and work-qubit cleanup.

This PR is stacked on #2408.

AI notice

This PR and its contents were created with the assistance of GPT-5.6 Sol via Codex.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@denialhaag denialhaag added feature New feature or request c++ Anything related to C++ code python Anything related to Python code MLIR Anything related to MLIR labels Sep 5, 2026
@denialhaag denialhaag self-assigned this Sep 5, 2026
@denialhaag
denialhaag force-pushed the codex/add-controlled-multiplication-modulo-n branch from 83fc28f to 9c5d25f Compare September 5, 2026 17:34
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.59615% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bench/JSON.cpp 86.3% 3 Missing ⚠️
...bench/programs/ControlledMultiplicationModuloN.cpp 98.1% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@denialhaag denialhaag added this to the v4.0.0 - IEEE Quantum Week milestone Sep 6, 2026
@mergify mergify Bot added the conflict label Sep 7, 2026
Base automatically changed from codex/add-classical-qft-adder to codex/add-quantum-qft-adder September 7, 2026 15:07
An error occurred while trying to automatically change base from codex/add-quantum-qft-adder to codex/add-teleportation-benchmark September 8, 2026 13:55
@denialhaag
denialhaag force-pushed the codex/add-controlled-multiplication-modulo-n branch from f0f26ef to 2e8f20e Compare September 8, 2026 14:01
@denialhaag
denialhaag changed the base branch from codex/add-quantum-qft-adder to main September 8, 2026 14:04
@mergify mergify Bot removed the conflict label Sep 8, 2026
Assisted-by: GPT-5.6 Sol via Codex
Assisted-by: GPT-5.6 Sol via Codex
Assisted-by: GPT-5.6 Sol via Codex
Assisted-by: GPT-5.6 Sol via Codex
Use the consolidated QFT utility and the family-specific Python test
layout. Move execution sampling to the native MLIR test and rely on the
shared registry test for jeff serialization.

Keep direction- and register-aware checks for every QFT stage. Update the
binding documentation and plan to match the current contracts.

Assisted-by: GPT-5.6 Sol via Codex
@denialhaag
denialhaag force-pushed the codex/add-controlled-multiplication-modulo-n branch from 2e8f20e to d6beeff Compare September 8, 2026 14:54

@denialhaag denialhaag left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, this is mostly testing the QCProgramBuilder. Please simplify the tests to something meaningful.

Comment thread src/bench/JSON.cpp
Comment on lines +428 to +446
[[nodiscard]] ControlledMultiplicationModuloN
parseControlledMultiplicationModuloNParameters(const Json& parameters,
const std::string_view source) {
rejectUnknownKeys(parameters, {"multiplier", "modulus"}, source,
"$/parameters");
try {
return ControlledMultiplicationModuloN({
.multiplier = stringValue(
required(parameters, "multiplier", source, "$/parameters"), source,
"$/parameters/multiplier"),
.modulus =
stringValue(required(parameters, "modulus", source, "$/parameters"),
source, "$/parameters/modulus"),
});
} catch (const std::invalid_argument& error) {
fail(source, "$/parameters", error.what());
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three ControlledMultiplicationModuloN functions below are just above GHZ. Let's keep the order consistent.

Comment on lines +32 to +33
[[nodiscard]] std::string subtract(const std::string_view minuend,
const std::string_view subtrahend) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a less manual way of doing this. Same for the helper functions below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double-check whether this can be simplified?

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

Labels

c++ Anything related to C++ code feature New feature or request MLIR Anything related to MLIR python Anything related to Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant