Skip to content

Fix Add.build_call_graph CNOT count for unequal register bitsizes - #1986

Open
Pyhroff wants to merge 1 commit into
quantumlib:mainfrom
Pyhroff:fix/add-unequal-bitsize-call-graph
Open

Pyhroff wants to merge 1 commit into
quantumlib:mainfrom
Pyhroff:fix/add-unequal-bitsize-call-graph

Conversation

@Pyhroff

@Pyhroff Pyhroff commented Oct 24, 2026

Copy link
Copy Markdown

Fixes #1818.

Summary

  • In Add.decompose_from_registers, when �_dtype.bitsize < b_dtype.bitsize (m < n), the left building block elides
  • 1 - m CNOTs (treating missing high bits of � as |0>), the top-bit CNOT (len(input_bits) == len(output_bits)) is omitted, and the right building block elides 2 * (n - 1 - m) CNOTs.
  • Previously, Add.build_call_graph unconditionally returned
    _cnot = (n - 2) * 6 + 3, causing gate.t_complexity() == gate.decompose_bloq().t_complexity() and �ssert_equivalent_bloq_counts to fail whenever �_dtype.bitsize < b_dtype.bitsize (or when �_dtype.bitsize == 1).
  • Updated Add.build_call_graph to account for m = self.a_dtype.bitsize vs
    = self.b_dtype.bitsize (yielding (n - 2) * 3 + 2 + 3 * m - 3 CNOTs when m < n, (n - 2) * 6 + 3 when m == n, and 1 CNOT when
    == 1) and added parametrized regression tests in �ddition_test.py.

@google-cla

google-cla Bot commented Oct 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

Addition call_graph inconsistent with decomposition for registers with unequal bitsizes

1 participant