Skip to content

Add approximation_degree to CommutativeCancellation and wire presets - #16679

Open
philipjpark wants to merge 8 commits into
Qiskit:mainfrom
philipjpark:fix-issue-14115
Open

Add approximation_degree to CommutativeCancellation and wire presets#16679
philipjpark wants to merge 8 commits into
Qiskit:mainfrom
philipjpark:fix-issue-14115

Conversation

@philipjpark

Copy link
Copy Markdown

Why was this PR needed?

Fixes #14115. transpile(..., approximation_degree=...) already reaches passes like RemoveIdentityEquivalent, but not CommutativeCancellation: the Python pass never accepted or forwarded the degree to Rust cancel_commutations (which already supports it), and the three preset call sites never passed pass_manager_config.approximation_degree. Cancellation always ran at full precision (1.0).

What does this PR do?

Adds approximation_degree: float | None = 1.0 to CommutativeCancellation, forwards it to cancel_commutations (None1.0), wires it at all three preset sites, and adds test_approximation_degree plus a release note.

What are the relevant issue numbers?

Closes #14115

Screenshots / Recordings (if applicable)

Before: CommutativeCancellation had no approximation_degree; Rust binding already did.
After: Cancellation OK for None / 0.5 / 1.0 — ALL TESTS PASSED

Does this PR meet the acceptance criteria?

  • Tests added for new/changed behavior
  • All tests passing
  • Follows project style guide
  • No breaking changes introduced
  • Documentation updated (if applicable)

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description: Cursor
  • I used the following tool to generate or modify code: Cursor

philipjpark and others added 8 commits July 28, 2026 18:23
Pass pass_manager_config.approximation_degree to CommutativeCancellation at all three preset call sites, add test_approximation_degree, and add a release note. Completes the integration work for Qiskit#14115.

Co-authored-by: Cursor <cursoragent@cursor.com>
The reproduction script was useful for Phase II validation but should not be included in the upstream pull request for Qiskit#14115.

Co-authored-by: Cursor <cursoragent@cursor.com>
Removed the Phase II reproduction script so the branch only contains
the approximation_degree pass wiring, preset changes, test, and release note.
Local validation venv was committed in the Week 6 cleanup commit; drop it and ignore .venv-test so the upstream PR only contains the Qiskit#14115 fix files.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the Qiskit PR limited to the Qiskit#14115 fix files only.

Co-authored-by: Cursor <cursoragent@cursor.com>
@philipjpark
philipjpark requested a review from a team as a code owner July 28, 2026 22:35
@philipjpark
philipjpark requested a review from gadial July 28, 2026 22:35
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 28, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@CLAassistant

CLAassistant commented Jul 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jeevan0920

Copy link
Copy Markdown
Contributor

@gadial Initially started reviewing it but I found that there are some pending PRs already for this same issue.

@philipjpark

Copy link
Copy Markdown
Author

Thanks @jeevan0920, yes, I noted the other open PRs (#14802, #15777, #16491) on #14115 as well. Happy to wait on the maintainer's guidance and make any updates to this PR if needed.

@alexanderivrii alexanderivrii 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.

Overall this looks fine, I have left some comments inline.

Comment on lines +64 to +68
approximation_degree: The threshold used in the average gate fidelity
computation to decide whether pairs of gates can be considered as
canceling or commuting. This can be a floating point value between
0 and 1, or ``None``. If the value is ``None`` the default fidelity
of ``1.0`` is used.

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.

Note that the pass in rust only handles floating-point values for approximation_degree, and not None. Based on the discussion and the decision when integrating SubstitutePi4Rotations and CommutativeOptimization into the transpiler pipeline, for now it's best to restrict the Python pass to also only work with floating-points values.

Comment on lines +102 to +106
approximation_degree = (
self._approximation_degree
if self._approximation_degree is not None
else 1.0
)

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.

Based on the previous comment, it's best to add this "if approximation degree is None, then set it to 1." to builtin_plugins.py.

Comment on lines +1004 to +1007
for approximation_degree in [None, 0.5, 1.0]:
with self.subTest(approximation_degree=approximation_degree):
result = CommutativeCancellation(approximation_degree=approximation_degree)(qc)
self.assertEqual(expected, result)

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.

Arguably this test does not check that approximation_degree affects the pass in any way. Can you think of a circuit where CommutativeCancellation would behave differently when approximation_degree is set to 1.0 (no approximation) vs. say 0.0 (maximal approximation)?

Also, per previous comments, we do not want to support None just yet. But maybe worth checking that not setting approximation_degree gives the same behavior as setting it to 1.0.

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

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add approximation_degree argument to CommutativeCancellation pass and set it in the preset

5 participants