Arithmetic cleanup and protocol-based interfaces

Open
#82 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@ChiaraLeadbeater is already working on this.

Since Oct 8, 2026.

Assessment

This issue has not been assessed yet.

Description

enhancement

Arithmetic is becoming cluttered as implementations and operation variants accumulate. This epic tracks a cleanup that introduces shared protocols, making arithmetic primitives easier to maintain, compose, and swap within higher-level algorithms.

A possible starting point is an Adder protocol exposing add and add_with_carry:

@guppy.protocol
class Adder:
    @guppy.require(unitary=True)
    def add[n: nat](
        self,
        a: array[qubit, n],
        b: array[qubit, n],
    ) -> None: ...

    @guppy.require(unitary=True)
    def add_with_carry[n: nat](
        self,
        a: array[qubit, n],
        b: array[qubit, n],
        carry: qubit,
    ) -> None: ...

This is a suggestion; the exact interfaces and capability requirements should be explored before committing to a design.

Scope:

  • Establish consistent arithmetic interfaces and operation semantics.
  • Separate shared interfaces from implementation-specific details.
  • Allow consuming algorithms to select compatible arithmetic implementations.
  • Simplify module organization and reduce duplication.

Coordination with Guppy:

This work needs to be carried out very carefully in conjunction with the struct rewrite and support for custom dagger, control, and controlled-dagger modifiers coming in Guppy v1.2.x. Protocol design and implementation migration should be coordinated with that work, checking how each modifier interacts with protocol methods and structs before consolidating existing operation variants. The proposed interface should remain provisional until those interactions are understood.

Suggested sub-issues and nested sub-issues:

  • Design arithmetic protocols
    • Prototype an Adder protocol.
    • Determine how controlled, inverse, and unitary capabilities should be represented.
    • Validate the design against the Guppy v1.2.x struct rewrite and custom dagger, control, and controlled-dagger modifiers.
  • Migrate addition and subtraction
    • Adapt Cuccaro and Gidney adders.
    • Integrate subtraction with the shared interfaces.
  • Extend to other arithmetic primitives
    • Assess protocols for incrementers and comparators.
    • Refactor multiplication and exponentiation to consume shared interfaces.

This epic should be delivered incrementally through linked sub-issues, with nested sub-issues for implementation-specific work. The breakdown can evolve as the protocol design is explored.

Dominant language
Python
Stars
12
Forks
1
Avg merge
3d 1h
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Quantinuum/guppyalgos

All issues in Quantinuum/guppyalgos

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.