small stuff

This commit is contained in:
Benoît Sierro
2021-11-01 08:39:00 +01:00
parent f4ca0350f0
commit 9cea2178b3

View File

@@ -79,7 +79,7 @@ class Variationer:
len_to_test = len(values[0]) len_to_test = len(values[0])
if not all(len(v) == len_to_test for v in values[1:]): if not all(len(v) == len_to_test for v in values[1:]):
raise VariationSpecsError( 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) num_vars.append(len_to_test)
if len(num_vars) == 0: if len(num_vars) == 0:
@@ -172,8 +172,7 @@ class VariationDescriptor(BaseModel):
str_list = [] str_list = []
for p_name, p_value in self.flat: for p_name, p_value in self.flat:
ps = p_name.replace("/", "").replace("\\", "").replace(PARAM_SEPARATOR, "") ps, vs = self._format_single_pair(p_name, p_value)
vs = self.format_value(p_name, p_value).replace("/", "").replace(PARAM_SEPARATOR, "")
str_list.append(ps + PARAM_SEPARATOR + vs) str_list.append(ps + PARAM_SEPARATOR + vs)
tmp_name = PARAM_SEPARATOR.join(str_list) tmp_name = PARAM_SEPARATOR.join(str_list)
if not add_identifier: if not add_identifier:
@@ -182,6 +181,11 @@ class VariationDescriptor(BaseModel):
self.identifier + PARAM_SEPARATOR + self.branch.identifier + PARAM_SEPARATOR + tmp_name 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": def __getitem__(self, key) -> "VariationDescriptor":
return VariationDescriptor( return VariationDescriptor(
raw_descr=self.raw_descr[key], index=self.index[key], separator=self.separator 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 from p.iter_parents()
yield self 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 @property
def flat(self) -> list[tuple[str, Any]]: def flat(self) -> list[tuple[str, Any]]:
out = [] out = []