Skip to content

PCVL 1267 EMT - Dectector loss balancing - #772

Open
Benoit-F-Q wants to merge 6 commits into
Quandela:developfrom
Benoit-F-Q:PCVL_1267_Loss_balancing
Open

PCVL 1267 EMT - Dectector loss balancing#772
Benoit-F-Q wants to merge 6 commits into
Quandela:developfrom
Benoit-F-Q:PCVL_1267_Loss_balancing

Conversation

@Benoit-F-Q

Copy link
Copy Markdown
Contributor

No description provided.

)
valid.warned = True
return res
valid.warned = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Giving attributes to functions can be misleading and error-prone, you can use a bool defined outside this method


def extend_computation(self, computation: Computation, noise: NoiseModel) -> list[Computation]:
comp = deepcopy(computation)
comp.command = "probs"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comp.command.name = ...

return math.prod([(1 / ratios[k.photon2mode(i)]) for i in range(k.n)], start = v)

res = copy(results[0]) # We are going to modify this to keep custom fields as much as we can
assert len(ratios) == computation.experiment.m, "Loss ratios do not match the distribution lengths."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Already done in self._validate_ratios()


class DetectorBalancing(AbstractMitigation):

APPLY_MIN_PHOTONS = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we don't remove the heralds, postselection and min_photons_filter, we can set these to False

def test_recombination():
expected, sub_results = prepare_test()
noise = NoiseModel()
noise.loss_ratios = [1., 1.]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We'll need to decide where to put this

return math.prod([(1 / ratios[k.photon2mode(i)]) for i in range(k.n)], start = v)
ratios = noise.loss_ratios
if len(ratios) < computation.experiment.m:
warnings.warn(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

get_logger().warning()

Comment thread perceval/utils/noise_model.py Outdated
if values:
valids = [math.isfinite(v) and v > 0. for v in values]
if not all(valids):
warnings.warn(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same

RuntimeWarning,
)
self._loss_ratios = [ v if valid else 1. for v, valid in zip(values, valids) ]
#TODO: divide by max(valid_ratios) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, but this should be done before replacing invalid values by 1

@Benoit-F-Q Benoit-F-Q Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We need precise specs on this.

Setting [ .1, .1 ], I'd imagined that modes 0 and 1 have 90% loss and other modes are perfect

The "median scaled to 100%" thing seems specific to perf <-> noise methods

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, you're right
In that case, something here should ensure that the values are not greater than 1

# Note: we do not know if it behaves correctly with Feef-Forward

APPLY_MIN_PHOTONS = False
APPLY_LOGICAL_SELECTION = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we don't change the states, this can also be set to False

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.

2 participants