From c2aeb138cfb90f3ff55a1ee8babd0f936c2d6417 Mon Sep 17 00:00:00 2001 From: Benoit Fanchon Date: Wed, 21 Jan 2026 18:34:48 +0100 Subject: [PATCH] PCVL-1148 XXXFockState interface aligned with BasicState --- perceval/utils/states.py | 24 ------------------- tests/utils/test_basicstate.py | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 tests/utils/test_basicstate.py diff --git a/perceval/utils/states.py b/perceval/utils/states.py index 42d26c145..ddaba3df0 100644 --- a/perceval/utils/states.py +++ b/perceval/utils/states.py @@ -152,15 +152,9 @@ def merge(self, other: State) -> State: def __add__(self, other) -> State | StateVector | BSDistribution: return StateVector() - def __radd__(self, other) -> State | StateVector | BSDistribution: - return StateVector() - def __sub__(self, other) -> State | StateVector | BSDistribution: return StateVector() - def __rsub__(self, other) -> State | StateVector | BSDistribution: - return StateVector() - @property def has_polarization(self) -> bool: return False @@ -169,24 +163,6 @@ def has_polarization(self) -> bool: def has_annotations(self) -> bool: return False - def separate_state(self) -> list[FockState]: - """ - :return: A list of states where each state represents a collection of indistinguishable photons from the original state - """ - - def split_state(self) -> dict[int, FockState]: - """ - :return: A dict of states where each state represents a collection of indistinguishable photons from the original state, - associated with the noise tag they were defined with. - """ - - def partition(self, photon_nb: list[int]) -> list[list[FockState]]: - """ - :param photon_nb: a list of photon numbers. The sum of this list must be equal to self.n - :return: A list containing all lists of states such that the merge of all these states is self, - where each state of the sublists has the number of photons specified in ``photon_nb``. - """ - def clear_annotations(self) -> FockState: """ :return: A new state where the photons are on the same modes as self, with no noise or annotations. diff --git a/tests/utils/test_basicstate.py b/tests/utils/test_basicstate.py new file mode 100644 index 000000000..3b80b927c --- /dev/null +++ b/tests/utils/test_basicstate.py @@ -0,0 +1,44 @@ +# MIT License +# +# Copyright (c) 2022 Quandela +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# As a special exception, the copyright holders of exqalibur library give you +# permission to combine exqalibur with code included in the standard release of +# Perceval under the MIT license (or modified versions of such code). You may +# copy and distribute such a combined system following the terms of the MIT +# license for both exqalibur and Perceval. This exception for the usage of +# exqalibur is limited to the python bindings used by Perceval. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from perceval.utils.states import AnnotatedFockState, BasicState, FockState, NoisyFockState + + +def not_implemented_from_BasicState(ClassName): + res = [attr for attr in BasicState.__dict__ if not hasattr(ClassName, attr)] + res.remove("__weakref__") + return res + + +def test_FockStates_interface(): + assert len( not_implemented_from_BasicState(FockState) ) == 0, "Some methods declared in BasicState are not implemented" + + assert len( not_implemented_from_BasicState(NoisyFockState) ) == 0, "Some methods declared in BasicState are not implemented" + + assert len( not_implemented_from_BasicState(AnnotatedFockState) ) == 0, "Some methods declared in BasicState are not implemented"