Skip to content

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Aug 1, 2025

Handle None return values consistently with other protocols, to mean that any fallback option should be skipped (xref #1655). This allows us to remove the redundant implementations and eliminate redundant executions of the same logic during decomposition, as well as prevent potential bugs where an important aspect of the context could be ignored.

Fixes #7535

Additionally fixes #7384 since DecompositionContext is never None anymore after the removal of the redundant implementations.

@daxfohl daxfohl requested review from vtomole and a team as code owners August 1, 2025 16:32
@daxfohl daxfohl requested a review from maffoo August 1, 2025 16:32
@github-actions github-actions bot added the size: M 50< lines changed <250 label Aug 1, 2025
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.50%. Comparing base (c7f10ac) to head (c6e836f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7553      +/-   ##
==========================================
- Coverage   97.50%   97.50%   -0.01%     
==========================================
  Files        1103     1103              
  Lines       99640    99661      +21     
==========================================
+ Hits        97154    97174      +20     
- Misses       2486     2487       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dstrain115
Copy link
Collaborator

I suppose this is fine, but does it change any behavior? I am a bit worried since decompose is very sensitive to some workflows, so I want to be sure we are not messing anyone up or causing backwards incompatibilities.

@daxfohl
Copy link
Collaborator Author

daxfohl commented Aug 6, 2025

It doesn't change behavior of any of the gates in cirq; it just prevents cirq from executing the same decomposition handlers twice unnecessarily. For gates defined outside of cirq, it would only change behavior if the gate had a _decompose_with_context_ that returns None and also has a _decompose_ that is expected to handle cases where _decompose_with_context_ returns None. That seems like a weird way to implement anything, but, Hyrum's Law.

In such a case, the simplest fix would be to change that gate's _decompose_with_context_ to return NotImplemented instead of None, since NotImplemented preserves the fallback behavior.

@daxfohl
Copy link
Collaborator Author

daxfohl commented Aug 11, 2025

The last commit also updated the type signatures of the handler functions since DecompositionContext is never None anymore (fixing #7384). It did not change any logic.

@daxfohl daxfohl added this pull request to the merge queue Aug 14, 2025
Merged via the queue into quantumlib:main with commit 4103b8b Aug 14, 2025
35 checks passed
@daxfohl daxfohl deleted the decompose-context-none branch August 14, 2025 21:45
ddddddanni pushed a commit to ddddddanni/Cirq that referenced this pull request Aug 25, 2025
…mlib#7553)

Handle `None` return values consistently with other protocols, to mean
that any fallback option should be skipped (xref
quantumlib#1655). This allows us to
remove the redundant implementations and eliminate redundant executions
of the same logic during decomposition, as well as prevent potential
bugs where an important aspect of the context could be ignored.

Fixes quantumlib#7535

Additionally fixes quantumlib#7384 since DecompositionContext is never None
anymore after the removal of the redundant implementations.
ddddddanni pushed a commit to ddddddanni/Cirq that referenced this pull request Sep 1, 2025
…mlib#7553)

Handle `None` return values consistently with other protocols, to mean
that any fallback option should be skipped (xref
quantumlib#1655). This allows us to
remove the redundant implementations and eliminate redundant executions
of the same logic during decomposition, as well as prevent potential
bugs where an important aspect of the context could be ignored.

Fixes quantumlib#7535

Additionally fixes quantumlib#7384 since DecompositionContext is never None
anymore after the removal of the redundant implementations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decompose doesn't follow standard for None return values DecompositionContext is never None
2 participants