Skip to content

Conversation

@austingmhuang
Copy link
Contributor

@austingmhuang austingmhuang commented Nov 13, 2025

Context:
In pennylane/estimator/estimate.py, when we call _update_counts_from_compressed_op, we get our decomposition function using _get_decomposition, which returns the symbolic class's resource_decomp method. Rather than use that, we should to "cut out the middle man" -- instead of pointing to the symbolic's resource_decomp method, and having that point to the base class's symbolic_resource_decomp method, we can just point directly to the base class's symbolic_resource_decomp method.

Description of the Change:
Update _get_decomposition and _update_counts_from_compressed_op in pennylane/estimator/estimate.py to just call the base class's symbolic resource decomp method with the appropriate params and kwargs.

Now fully supports this UI:

def custom_adj_RZ(target_resource_params):
    return [qre.GateCount(qre.resource_rep(qre.Z))]

rc = qre.ResourceConfig()
rc.set_decomp(qre.RZ, custom_adj_RZ, decomp_type="adj")

res = qre.estimate(
    qre.Adjoint(qre.RZ()),
    config=rc
)

Benefits:
Simplifies the pipeline, improving readability and maintainability.

Possible Drawbacks:
The symbolic classes resource decomp method remains, which can be a source of confusion. A set of code comments is provided.

Related GitHub Issues:
[sc-103387]
[sc-103956]

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@austingmhuang austingmhuang changed the title Refactor symbolic decomp Refactor symbolic resource decomposition methods for resource estimation Nov 13, 2025
@austingmhuang austingmhuang changed the base branch from master to fix_custom_decomp November 13, 2025 16:15
@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (fix_custom_decomp@bf3cb53). Learn more about missing BASE report.

Additional details and impacted files
@@                 Coverage Diff                  @@
##             fix_custom_decomp    #8641   +/-   ##
====================================================
  Coverage                     ?   99.43%           
====================================================
  Files                        ?      587           
  Lines                        ?    61987           
  Branches                     ?        0           
====================================================
  Hits                         ?    61634           
  Misses                       ?      353           
  Partials                     ?        0           

☔ 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.

Copy link
Contributor

@ddhawan11 ddhawan11 left a comment

Choose a reason for hiding this comment

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

Thanks @austingmhuang. I think we should also add tests to make sure that the bug is fixed.

Comment on lines +338 to +339
* The `_get_decomposition` and `_update_counts_from_compressed_op` methods in `pennylane/estimator/estimate.py` were updated to directly call the base class's `symbolic_resource_decomp` method, simplifying the decomposition pipeline.
[(#8641)](https://github.com/PennyLaneAI/pennylane/pull/8641)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please limit this to 100 characters.

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.

3 participants