Skip to content

Commit 453c609

Browse files
committed
..
1 parent 01a9497 commit 453c609

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

petab/v2/core.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,10 @@ class Parameter(BaseModel):
861861
prior_distribution: PriorDistribution | None = Field(
862862
alias=C.PRIOR_DISTRIBUTION, default=None
863863
)
864-
865-
# TODO priors
866-
# pydantic vs. petab.v1.priors.Prior
864+
#: Prior distribution parameters.
865+
prior_parameters: list[float] = Field(
866+
alias=C.PRIOR_PARAMETERS, default_factory=list
867+
)
867868

868869
#: :meta private:
869870
model_config = ConfigDict(
@@ -882,13 +883,22 @@ def _validate_id(cls, v):
882883
raise ValueError(f"Invalid ID: {v}")
883884
return v
884885

886+
@field_validator("prior_parameters", mode="before")
887+
@classmethod
888+
def _validate_prior_parameters(cls, v):
889+
if isinstance(v, str):
890+
v = v.split(C.PARAMETER_SEPARATOR)
891+
elif not isinstance(v, Sequence):
892+
v = [v]
893+
894+
return [float(x) for x in v]
895+
885896
@field_validator("estimate", mode="before")
886897
@classmethod
887898
def _validate_estimate_before(cls, v):
888899
if isinstance(v, bool):
889900
return v
890901

891-
# TODO: clarify whether extra whitespace is allowed
892902
if isinstance(v, str):
893903
v = v.strip().lower()
894904
if v == "true":
@@ -932,8 +942,6 @@ def _validate(self) -> Self:
932942
):
933943
raise ValueError("Lower bound must be less than upper bound.")
934944

935-
# TODO parameterScale?
936-
937945
# TODO priorType, priorParameters
938946

939947
return self

petab/v2/problem.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,9 @@ def add_parameter(
976976
if prior_dist is not None:
977977
record[PRIOR_DISTRIBUTION] = prior_dist
978978
if prior_pars is not None:
979-
if not isinstance(prior_pars, str):
979+
if isinstance(prior_pars, Sequence) and not isinstance(
980+
prior_pars, str
981+
):
980982
prior_pars = PARAMETER_SEPARATOR.join(map(str, prior_pars))
981983
record[PRIOR_PARAMETERS] = prior_pars
982984
record.update(kwargs)
@@ -1117,6 +1119,7 @@ def model_dump(self, **kwargs) -> dict[str, Any]:
11171119
'lb': 0.0,
11181120
'nominal_value': None,
11191121
'prior_distribution': None,
1122+
'prior_parameters': [],
11201123
'ub': 1.0}]}
11211124
"""
11221125
res = {

0 commit comments

Comments
 (0)