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

Refactoring CircuitComponent #446

Closed apchytr closed 1 month ago

apchytr commented 2 months ago

Context: A proposal to change CircuitComponent's signature to accept Wires optionally. Additionally, removing CCViews in the hopes of reintroducing a better solution.

Description of the Change: CircuitComponent's signature changes from

    def __init__(
        self,
        representation: Optional[Bargmann | Fock] = None,
        modes_out_bra: Optional[Sequence[int]] = None,
        modes_in_bra: Optional[Sequence[int]] = None,
        modes_out_ket: Optional[Sequence[int]] = None,
        modes_in_ket: Optional[Sequence[int]] = None,
        name: Optional[str] = None,
    ) -> None:

to

    def __init__(
        self,
        representation: Optional[Bargmann | Fock] = None,
        wires: Wires | Sequence[tuple[int]] | None = None,
        name: Optional[str] = None,
    ) -> None:

where the Sequence[tuple[int]] would be (modes_out_bra, modes_in_bra, modes_out_ket, modes_in_ket).

Benefits: Cleaner signature for circ components. Pylint issue fixed with the removal of CCViews.

Possible Drawbacks: modes_out_bra, modes_in_bra, modes_out_ket, modes_in_ket are no longer kwargs and instead a length 4 sequence. This could be more prone to errors. However, my initial thinking is that the classes exposed to users (eg gates or states) would handle constructing the sequence so we wouldnt have to worry about that.

codecov[bot] commented 2 months ago

Codecov Report

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

Project coverage is 88.85%. Comparing base (3a111fc) to head (4a94a7f).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #446 +/- ## =========================================== + Coverage 88.80% 88.85% +0.04% =========================================== Files 100 100 Lines 7024 6999 -25 =========================================== - Hits 6238 6219 -19 + Misses 786 780 -6 ``` | [Files](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI) | Coverage Δ | | |---|---|---| | [mrmustard/lab\_dev/circuit\_components.py](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?src=pr&el=tree&filepath=mrmustard%2Flab_dev%2Fcircuit_components.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI#diff-bXJtdXN0YXJkL2xhYl9kZXYvY2lyY3VpdF9jb21wb25lbnRzLnB5) | `97.68% <100.00%> (+1.90%)` | :arrow_up: | | [...tard/lab\_dev/circuit\_components\_utils/trace\_out.py](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?src=pr&el=tree&filepath=mrmustard%2Flab_dev%2Fcircuit_components_utils%2Ftrace_out.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI#diff-bXJtdXN0YXJkL2xhYl9kZXYvY2lyY3VpdF9jb21wb25lbnRzX3V0aWxzL3RyYWNlX291dC5weQ==) | `100.00% <ø> (ø)` | | | [mrmustard/lab\_dev/states/base.py](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?src=pr&el=tree&filepath=mrmustard%2Flab_dev%2Fstates%2Fbase.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI#diff-bXJtdXN0YXJkL2xhYl9kZXYvc3RhdGVzL2Jhc2UucHk=) | `96.19% <ø> (ø)` | | | [mrmustard/lab\_dev/transformations/base.py](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?src=pr&el=tree&filepath=mrmustard%2Flab_dev%2Ftransformations%2Fbase.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI#diff-bXJtdXN0YXJkL2xhYl9kZXYvdHJhbnNmb3JtYXRpb25zL2Jhc2UucHk=) | `97.19% <ø> (ø)` | | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?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/446?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XanaduAI). Last update [3a111fc...4a94a7f](https://app.codecov.io/gh/XanaduAI/MrMustard/pull/446?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).