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

Pcvl 846 incompatible heralds and detectors should not be simulated #519

Conversation

Aubaert
Copy link
Contributor

@Aubaert Aubaert commented Jan 17, 2025

Draft PR for now since the test with probs will only work after merging with #515 that removes a normalization that currently raises a warning.

@@ -332,6 +334,9 @@ def samples(self,
* physical_perf is the performance computed from the detected photon filter
* logical_perf is the performance computed from the post-selection
"""
if not self.checker.check_heralds_detectors(self._heralds, self._detectors):
return {"results": BSSamples(), "physical_perf": 1, "logical_perf": 0}
Copy link
Contributor

Choose a reason for hiding this comment

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

"physical_perf": 1 c'est de la triche, non ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oui, complètement, mais j'ai même pas envie de la calculer dans ce cas là


@staticmethod
def check_heralds_detectors(heralds: dict[int, int] | None, detectors: list[IDetector | None] | None) -> bool:
if heralds is not None and detectors is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if heralds and detectors:, non ?
(et plus bas aussi)

for k, v in heralds.items():
detector = detectors[k]
if detector is not None:
max_val = detectors[k].max_value
Copy link
Contributor

Choose a reason for hiding this comment

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

detectors[k] => detector ?

p.min_detected_photons_filter(0)
p.with_input(BasicState([1, 1]))

with LogChecker(mock_warn):
Copy link
Contributor

Choose a reason for hiding this comment

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

Je pense que ce test ne devrait vérifier que le comportement de check_heralds_detectors(...).

En l'état n'importe quel warning du simulateur va cacher une éventuelle erreur dans check_heralds_detectors.

@Aubaert Aubaert marked this pull request as ready for review January 20, 2025 10:32
from perceval.utils.logging import channel, get_logger


class SimulatorChecker:
Copy link
Contributor

Choose a reason for hiding this comment

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

This class is not usefull, you should put check_heralds_detectors as a stand alone method (maybe in the detector file ?)

@@ -55,6 +55,7 @@ class DetectionType(Enum):


class IDetector(AComponent, ABC):
max_value: int
Copy link
Contributor

Choose a reason for hiding this comment

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

max_value is a very generic name for this variable, consider max_detected_photons or max_detections

Copy link
Contributor

Choose a reason for hiding this comment

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

/!\ max_value is here a python class attribute and not a property
(hopefully it has no consequences here but it could if we implement a new detector class and forgot to declare the max_value property)
you should do:

from abc import ABC, abstractmethod
...
class IDetector(AComponent, ABC):
    @property
    @abstractmethod
    def max_value(self):
        pass

@patch.object(pcvl.utils.logging.ExqaliburLogger, "warn")
def test_incompatible_heralds_slos(mock_warn):
checker = SimulatorChecker()
detector_th = Detector.threshold()
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test also with a perfect detector (Detector.pnr())

@@ -32,7 +32,7 @@
from unittest.mock import patch

import perceval as pcvl
from perceval import BSDistribution
from perceval import BSDistribution, Herald, BSSamples
Copy link
Contributor

Choose a reason for hiding this comment

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

Why new import in this file ?

@Aubaert Aubaert merged commit 1f817a9 into Quandela:release/0.12.1 Jan 23, 2025
4 checks passed
@Aubaert Aubaert deleted the PCVL-846-incompatible-heralds-and-detectors-should-not-be-simulated branch January 31, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants