diff options
author | Vratko Polak <vrpolak@cisco.com> | 2023-10-17 16:31:35 +0200 |
---|---|---|
committer | Vratko Polak <vrpolak@cisco.com> | 2023-10-18 08:10:06 +0000 |
commit | e5dbe10d9599b9a53fa07e6fadfaf427ba6d69e3 (patch) | |
tree | 147b7972bea35a093f6644e63c5f1fb4e4b2c9a0 /resources/libraries/python/MLRsearch/trimmed_stat.py | |
parent | c6dfb6c09c5dafd1d522f96b4b86c5ec5efc1c83 (diff) |
feat(MLRsearch): MLRsearch v7
Replaces MLRv2, suitable for "big bang" upgrade across CSIT.
PyPI metadata updated only partially (full edits will come separately).
Pylint wants less complexity, but the differences are only minor.
+ Use the same (new CSIT) defaults everywhere, also in Python library.
+ Update also PLRsearch to use the new result class.
+ Make upper bound optional in UTI.
+ Fix ASTF approximate duration detection.
+ Do not keep approximated_receive_rate (for MRR) in result structure.
Change-Id: I03406f32d5c93f56b527cb3f93791b61955dfd74
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'resources/libraries/python/MLRsearch/trimmed_stat.py')
-rw-r--r-- | resources/libraries/python/MLRsearch/trimmed_stat.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/resources/libraries/python/MLRsearch/trimmed_stat.py b/resources/libraries/python/MLRsearch/trimmed_stat.py new file mode 100644 index 0000000000..0076644aa3 --- /dev/null +++ b/resources/libraries/python/MLRsearch/trimmed_stat.py @@ -0,0 +1,78 @@ +# Copyright (c) 2023 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Module defining TrimmedStat class.""" + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Optional + +from .discrete_load import DiscreteLoad +from .load_stats import LoadStats +from .target_spec import TargetSpec + + +@dataclass +class TrimmedStat(LoadStats): + """Load stats trimmed to a single target. + + Useful mainly for reporting the overall results. + """ + + def __post_init__(self) -> None: + """Initialize load value and check there is one target to track.""" + super().__post_init__() + if len(self.target_to_stat) != 1: + raise ValueError(f"No single target: {self.target_to_stat!r}") + + @staticmethod + def for_target(stats: LoadStats, target: TargetSpec) -> TrimmedStat: + """Return new instance with only one target in the mapping. + + :param stats: The load stats instance to trim. + :param target: The one target which should remain in the mapping. + :type stats: LoadStats + :type target: TargetSpec + :return: Newly created instance. + :rtype: TrimmedStat + """ + return TrimmedStat( + rounding=stats.rounding, + int_load=stats.int_load, + target_to_stat={target: stats.target_to_stat[target]}, + ) + + @property + def conditional_throughput(self) -> Optional[DiscreteLoad]: + """Compute conditional throughput from the load. + + Target stat has dur_rat_sum and good_long. + The code here adds intended load and handles the case min load is hit. + If min load is not a lower bound, None is returned. + + :return: Conditional throughput assuming self is a relevant lower bound. + :rtype: Optional[DiscreteLoad] + :raises RuntimeError: If target is unclear or load is spurious. + """ + target = list(self.target_to_stat.keys())[0] + _, pes = self.estimates(target) + if not pes: + if int(self): + raise RuntimeError(f"Not a lower bound: {self}") + return None + # TODO: Verify self is really the clo? + stat = self.target_to_stat[target] + loss_ratio = stat.dur_rat_sum / stat.good_long + ret = self * (1.0 - loss_ratio) + return ret |