Skip to content

Commit 466cf21

Browse files
ScienfitzCopilot
andauthored
Improve deserialization validation
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent aeb46b9 commit 466cf21

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

baybe/searchspace/discrete.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,23 @@ def validate_simplex_subspace_from_config(specs: dict, _) -> None:
667667
)
668668

669669
simplex_coefficients = specs.get("simplex_coefficients", None)
670-
if simplex_coefficients is not None and len(simplex_coefficients) != len(
671-
simplex_parameters
672-
):
673-
raise ValueError(
674-
f"'simplex_coefficients' must have one entry per 'simplex_parameters' "
675-
f"entry, but got {len(simplex_coefficients)} coefficient(s) for "
676-
f"{len(simplex_parameters)} parameter(s)."
677-
)
670+
if simplex_coefficients is not None:
671+
try:
672+
simplex_coefficients = converter.structure(
673+
simplex_coefficients, list[float]
674+
)
675+
except (IterableValidationError, TypeError, ValueError) as exc:
676+
raise ValueError(
677+
f"'simplex_coefficients' must be a list of numeric values."
678+
) from exc
679+
680+
if len(simplex_coefficients) != len(simplex_parameters):
681+
raise ValueError(
682+
f"'simplex_coefficients' must have one entry per "
683+
f"'simplex_parameters' entry, but got "
684+
f"{len(simplex_coefficients)} coefficient(s) for "
685+
f"{len(simplex_parameters)} parameter(s)."
686+
)
678687

679688
product_parameters = specs.get("product_parameters", [])
680689
if product_parameters:

0 commit comments

Comments
 (0)