Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: support class attributes in unevaluated_expression #375

Merged
merged 4 commits into from
Dec 18, 2023

Conversation

redeboer
Copy link
Member

Warning

BlattWeisskopfSquared switched its arguments: z now comes before angular_momentum, so that angular_momentum can be used as a keyword argument, like in the example below.

The @unevaluated_expression() now supports class attributes by marking them with typing.ClassVar. For instance:

from __future__ import annotations

import sympy as sp
from ampform.sympy import unevaluated_expression
from typing import Any, ClassVar

@unevaluated_expression
class BlattWeisskopfSquared(sp.Expr):
    angular_momentum: Any
    z: Any
    max_angular_momentum: ClassVar[int | None] = None
    _latex = R"B_{{{angular_momentum}}}^2\left({z}\right)"

    def evaluate(self) -> sp.Expr: ...

z = sp.Symbol("z")
ff1 = BlattWeisskopfSquared(z, angular_momentum=1)
ff2 = BlattWeisskopfSquared(z, angular_momentum=2)
assert ff1.max_angular_momentum is None
assert ff2.max_angular_momentum is None
BlattWeisskopfSquared.max_angular_momentum = 3
assert ff1.max_angular_momentum is 3
assert ff2.max_angular_momentum is 3

@redeboer redeboer added ⚠️ Interface Breaking changes to the API ⚙️ Enhancement Improvements and optimizations of existing features labels Dec 18, 2023
@redeboer redeboer self-assigned this Dec 18, 2023
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@redeboer redeboer enabled auto-merge (squash) December 18, 2023 14:10
@redeboer redeboer merged commit ef0c5ad into main Dec 18, 2023
23 checks passed
@redeboer redeboer deleted the unevaluated-expression-class-attributes branch December 18, 2023 14:14
redeboer added a commit that referenced this pull request Dec 22, 2023
* BREAK: switch arguments of `BlattWeisskopfSquared`
* MAINT: rewrite `BlattWeisskopfSquared` with decorator
* MAINT: test ClassVar of `BlattWeisskopfSquared`
@redeboer redeboer added this to the 0.14.8 milestone Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ Enhancement Improvements and optimizations of existing features ⚠️ Interface Breaking changes to the API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant