Skip to content

feat: add abstractify helper function to core.operator module#9694

Open
andrijapau wants to merge 46 commits into
fix/skip-child-constructor-if-abstractfrom
feat/abstractify-operator
Open

feat: add abstractify helper function to core.operator module#9694
andrijapau wants to merge 46 commits into
fix/skip-child-constructor-if-abstractfrom
feat/abstractify-operator

Conversation

@andrijapau

@andrijapau andrijapau commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Context:

We wish to have a helper function that can "abstractify" various types of data. Specfically, this is useful for abstractifying operators for integration with graph decomposition.

Description of the Change:

This PR,

  • add abstractify dispatcher function
  • registers various types for the abstractify function
from pennylane.core.operator import Operator2
from pennylane.core.operator.utils import abstractify

class SimpleOp(Operator2):
    
    dynamic_argnames= ("a",)
    
    def __init__(self, a, wires) -> None:
        super().__init__(a, wires)

op = SimpleOp(1.5, wires=[0])

so,

>>> abstractify(op)
SimpleOp(a=AbstractArray((), float64, weak_type=True), wires=AbstractWires(1))

Benefits: Utility function is created.

Possible Drawbacks: None identified.

[sc-122587]

@andrijapau andrijapau added the WIP 🚧 Work-in-progress label Jun 17, 2026
@andrijapau andrijapau changed the title feat: add operator2 dispatch for abstractify feat: add abstractify helper function Jun 17, 2026
Comment thread pennylane/core/operator/operator2.py Outdated
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (e035045) to head (18effe1).

Additional details and impacted files
@@                           Coverage Diff                           @@
##           fix/skip-child-constructor-if-abstract    #9694   +/-   ##
=======================================================================
  Coverage                                   99.46%   99.46%           
=======================================================================
  Files                                         629      630    +1     
  Lines                                       69071    69112   +41     
=======================================================================
+ Hits                                        68700    68742   +42     
+ Misses                                        371      370    -1     

☔ View full report in Codecov by Harness.
📢 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.

@PennyLaneAI PennyLaneAI deleted a comment from github-actions Bot Jun 17, 2026
Comment thread doc/releases/changelog-dev.md Outdated
andrijapau and others added 3 commits June 19, 2026 10:59
Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
Comment thread pennylane/core/operator/operator2.py Outdated
return _is_op(l) or _is_wires(l)


@abstractify.register(ABCOperatorMeta)

@andrijapau andrijapau Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using the metaclass for dispatch seems to work. Anything subtle I'm missing?

@andrijapau andrijapau requested a review from astralcai June 19, 2026 15:05
Comment thread pennylane/core/operator/operator2.py Outdated
if x.__class__.__name__ == "AbstractArray":
# will always be a numpy dtype
return x.dtype.name
return np.dtype(x.dtype).name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be reverted very soon

Co-authored-by: Mudit Pandey <18223836+mudit2812@users.noreply.github.com>
@andrijapau andrijapau requested a review from mudit2812 June 19, 2026 17:32
Comment thread pennylane/core/operator/operator2.py Outdated
Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
@andrijapau andrijapau requested a review from astralcai June 22, 2026 15:21
@andrijapau andrijapau added review-ready 👌 PRs which are ready for review by someone from the core team. do not merge ⚠️ Do not merge the pull request until this label is removed labels Jun 22, 2026
Comment thread tests/core/operator/test_operator2.py Outdated
return AbstractWires(len(val))


@abstractify.register(AbstractArray | AbstractWires)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should this go in typing.py? Only issue there is we pick up a dependency for typing to core.operator.

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

Labels

do not merge ⚠️ Do not merge the pull request until this label is removed review-ready 👌 PRs which are ready for review by someone from the core team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants