Skip to content

✨ Support wide Qiskit register comparisons - #2348

Merged
simon1hofmann merged 2 commits into
mainfrom
codex/wide-cbit-qiskit-comparisons
Sep 4, 2026
Merged

✨ Support wide Qiskit register comparisons#2348
simon1hofmann merged 2 commits into
mainfrom
codex/wide-cbit-qiskit-comparisons

Conversation

@simon1hofmann

@simon1hofmann simon1hofmann commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Description

Support exact Qiskit interchange for unsigned comparisons between one complete
named classical register wider than 64 bits and one same-width integer literal.
Both operand orders and all unsigned equality and ordering predicates are
supported.

The implementation keeps the current MLIR representation: cbit.read
materializes the register value and arith.cmpi compares it with an integer
constant. Export recognizes this direct shape, and import emits the same
operations. Only this direct register-and-literal form bypasses the generic
64-bit limit. Computed or packed unsigned expressions and signed comparisons
wider than 64 bits remain unsupported.

Normalized unsigned literals use llvm::APInt. The Python boundary transfers
integers as unsigned hexadecimal text, preserving large positive values without
depending on Python's decimal string-conversion limit.

The branch is based directly on current main and contains one focused commit.
The Qiskit support documentation describes the direct-wide boundary.

Validation

  • Built mqt-core-mlir-bindings against LLVM/MLIR 23.1.
  • Passed all seven focused wide-comparison and rejection cases.
  • Passed all 261 tests in test/python/test_mlir_qiskit_translation.py.
  • Covered 65-, 151-, and 301-bit values, reversed operands, and Python's
    decimal digit limit.
  • Confirmed computed unsigned and signed comparisons wider than 64 bits remain
    rejected.
  • Regenerated stubs without a generated-file diff.
  • Passed uvx nox -s lint and git diff --check.
  • uvx nox -s cpp-lint -- origin/main could not start locally because this
    host does not provide the required clang-tidy 22; hosted CI remains
    authoritative for that check.

Codex assisted with the implementation, tests, branch update, review, and this
description.

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.
  • No changelog entry is needed for this unreleased functionality.
  • No migration instructions are 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.

@mergify mergify Bot added the conflict label Sep 3, 2026
@simon1hofmann
simon1hofmann force-pushed the codex/wide-cbit-qiskit-comparisons branch from bbfc021 to ae1e71f Compare September 3, 2026 13:51
@mergify mergify Bot removed the conflict label Sep 3, 2026
@simon1hofmann
simon1hofmann force-pushed the codex/wide-cbit-qiskit-comparisons branch from ae1e71f to 94a6725 Compare September 3, 2026 14:36
@simon1hofmann simon1hofmann self-assigned this Sep 3, 2026
@simon1hofmann simon1hofmann added this to the MLIR Support milestone Sep 3, 2026
@simon1hofmann simon1hofmann added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Sep 3, 2026
@mergify mergify Bot added the conflict label Sep 3, 2026
Base automatically changed from codex/2289-bit-register-casts to main September 4, 2026 06:53
Preserve unsigned literals with APInt and allow direct complete-register
comparisons beyond 64 bits. Keep computed and signed wide expressions
rejected, and exchange Python integers through hexadecimal.

Assisted-by: GPT-5.6 Sol via Codex

Signed-off-by: Simon Hofmann <simon.t.hofmann@tum.de>
Let validation enforce direct wide comparisons and reuse generic emission
without a separate predicate reversal table. Normalize tuple conditions
through the same expression path, preserving Boolean values and folding
out-of-range equalities to false.

Cover all six predicates in both operand orders, jeff conversion, tuple
conditions, and invalid wide register mappings. Keep export unchanged.

Assisted-by: Codex
Signed-off-by: Lukas Burgholzer <burgholzer@me.com>

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Took this for a spin and it is much leaner now. Tests still pass, so I am pretty confident this is ready to go in 🚀
If you agree, feel free to merge!

@simon1hofmann
simon1hofmann merged commit 98c57ae into main Sep 4, 2026
22 checks passed
@simon1hofmann
simon1hofmann deleted the codex/wide-cbit-qiskit-comparisons branch September 4, 2026 10:19
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 enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants