From 9cea2178b3bb0f69c7220dea6c9e8777a1e053e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Mon, 1 Nov 2021 08:39:00 +0100 Subject: [PATCH] small stuff --- src/scgenerator/_utils/variationer.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/scgenerator/_utils/variationer.py b/src/scgenerator/_utils/variationer.py index 2e8ba9f..20181ad 100644 --- a/src/scgenerator/_utils/variationer.py +++ b/src/scgenerator/_utils/variationer.py @@ -79,7 +79,7 @@ class Variationer: len_to_test = len(values[0]) if not all(len(v) == len_to_test for v in values[1:]): raise VariationSpecsError( - f"variable items should all have the same number of parameters" + "variable items should all have the same number of parameters" ) num_vars.append(len_to_test) if len(num_vars) == 0: @@ -172,8 +172,7 @@ class VariationDescriptor(BaseModel): str_list = [] for p_name, p_value in self.flat: - ps = p_name.replace("/", "").replace("\\", "").replace(PARAM_SEPARATOR, "") - vs = self.format_value(p_name, p_value).replace("/", "").replace(PARAM_SEPARATOR, "") + ps, vs = self._format_single_pair(p_name, p_value) str_list.append(ps + PARAM_SEPARATOR + vs) tmp_name = PARAM_SEPARATOR.join(str_list) if not add_identifier: @@ -182,6 +181,11 @@ class VariationDescriptor(BaseModel): self.identifier + PARAM_SEPARATOR + self.branch.identifier + PARAM_SEPARATOR + tmp_name ) + def _format_single_pair(self, p_name: str, p_value: Any) -> tuple[str, str]: + ps = p_name.replace("/", "").replace("\\", "").replace(PARAM_SEPARATOR, "") + vs = self.format_value(p_name, p_value).replace("/", "").replace(PARAM_SEPARATOR, "") + return ps, vs + def __getitem__(self, key) -> "VariationDescriptor": return VariationDescriptor( raw_descr=self.raw_descr[key], index=self.index[key], separator=self.separator @@ -235,6 +239,13 @@ class VariationDescriptor(BaseModel): yield from p.iter_parents() yield self + @property + def short(self) -> str: + """shortened description of the simulation""" + return " ".join( + self._format_single_pair(p, v)[1] for p, v in self.flat if p not in {"fiber", "num"} + ) + @property def flat(self) -> list[tuple[str, Any]]: out = []