Skip to content

Commit 5fc6a31

Browse files
committed
Assign SciML-specific lint checks
1 parent 1888d2f commit 5fc6a31

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

petab/v2/core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,13 +1210,18 @@ def __init__(
12101210
array_data_files: list[ArrayData] | None = None,
12111211
config: ProblemConfig = None,
12121212
):
1213-
from ..v2.lint import default_validation_tasks
1213+
from ..v2.lint import default_validation_tasks, sciml_validation_tasks
12141214

12151215
self.config = config
12161216
self.models: list[Model] = models or []
1217-
self.validation_tasks: list[ValidationTask] = (
1218-
default_validation_tasks.copy()
1219-
)
1217+
if config.extensions and config.extensions[C.SCIML]:
1218+
self.validation_tasks: list[ValidationTask] = (
1219+
sciml_validation_tasks.copy()
1220+
)
1221+
else:
1222+
self.validation_tasks: list[ValidationTask] = (
1223+
default_validation_tasks.copy()
1224+
)
12201225

12211226
self.observable_tables = observable_tables or [ObservableTable()]
12221227
self.condition_tables = condition_tables or [ConditionTable()]

petab/v2/lint.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,40 @@ def run(self, problem: Problem) -> ValidationIssue | None:
992992
return None
993993

994994

995+
class CheckHybridizationTable(ValidationTask):
996+
"""Validate the SciML hybridization table."""
997+
998+
def run(self, problem: Problem) -> ValidationIssue | None:
999+
messages = []
1000+
1001+
condition_targets = {
1002+
c.target_id for ct in problem.conditions for c in ct.changes
1003+
}
1004+
nn_input_ids = {
1005+
inp.input_id for nn in problem.neural_networks for inp in nn.inputs
1006+
}
1007+
hyb_target_ids = {hyb.target_id for hyb in problem.hybridizations}
1008+
hyb_target_vals = {hyb.target_value for hyb in problem.hybridizations}
1009+
1010+
# Hybridization targets are not also targets in the condition table
1011+
if culprits := (hyb_target_ids & condition_targets):
1012+
messages.append(
1013+
f"Hybridization target ids `{culprits}` are also "
1014+
"target ids in the condition table."
1015+
)
1016+
# NN inputs are not used as target values
1017+
if culprits := (hyb_target_vals & nn_input_ids):
1018+
messages.append(
1019+
"The following neural net inputs were used as target values "
1020+
f"in the Hybridization tbale: `{culprits}`. Please simplify."
1021+
)
1022+
1023+
if messages:
1024+
return ValidationError("\n".join(messages))
1025+
1026+
return None
1027+
1028+
9951029
def get_valid_parameters_for_parameter_table(
9961030
problem: Problem,
9971031
) -> set[str]:
@@ -1192,3 +1226,13 @@ def get_placeholders(
11921226
CheckInitialChangeSymbols(),
11931227
CheckMappingTable(),
11941228
]
1229+
1230+
#: Validation tasks that should be run PEtab SciML problems
1231+
sciml_validation_tasks = [
1232+
CheckHybridizationTable(),
1233+
] + list(
1234+
set(default_validation_tasks)
1235+
- {
1236+
CheckAllParametersPresentInParameterTable(),
1237+
}
1238+
)

0 commit comments

Comments
 (0)