XanaduAI / MrMustard

A differentiable bridge between phase space and Fock space
https://mrmustard.readthedocs.io/
Apache License 2.0
78 stars 25 forks source link

Move reduce to ArrayAnsatz and include calls in dunder methods #453

Closed apchytr closed 1 month ago

apchytr commented 1 month ago

Context: Dunder methods on ArrayAnsatz such as __add__ currently fail if the shapes of the arrays do not match (e.g. adding a (1, 2, 2) and a (1, 3, 3) array). This PR includes calls to reduce in these dunder methods exploiting the fact we can just pad the smaller array with zeros making them compatible.

Description of the Change: reduce has been moved to ArrayAnsatz and __add__, __mul__ and __truediv__ make use of calls to reduce. Additionally, some cleanup such as reordering methods alphabetically.

Benefits: Interactions between ArrayAnsatz of different fock cutoffs are more flexible

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.88%. Comparing base (4085e25) to head (a8a50d7).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #453 +/- ## =========================================== + Coverage 88.86% 88.88% +0.02% =========================================== Files 100 100 Lines 7007 7020 +13 =========================================== + Hits 6227 6240 +13 Misses 780 780 ``` | [Files](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/453?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI) | Coverage Δ | | |---|---|---| | [mrmustard/physics/ansatze.py](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/453?src=pr&el=tree&filepath=mrmustard%2Fphysics%2Fansatze.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI#diff-bXJtdXN0YXJkL3BoeXNpY3MvYW5zYXR6ZS5weQ==) | `96.33% <100.00%> (+0.21%)` | :arrow_up: | | [mrmustard/physics/representations.py](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/453?src=pr&el=tree&filepath=mrmustard%2Fphysics%2Frepresentations.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI#diff-bXJtdXN0YXJkL3BoeXNpY3MvcmVwcmVzZW50YXRpb25zLnB5) | `99.51% <100.00%> (-0.03%)` | :arrow_down: | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/453?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/453?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI). Last update [4085e25...a8a50d7](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/453?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI).