Skip to content

Acceptance criteria: validate inputs and handle compartments, missing populations and final-year windows #559

Open

Description

@RomeshA

Found in review of #539.

Problem

The acceptance_criteria mechanism (rejection sampling on a windowed mean of a variable) has several unhandled edge cases, all reproduced on the branch:

  • Naming a compartment or characteristic instead of a parameter raises AttributeError: 'Compartment' object has no attribute '_is_dynamic'.
  • Naming a population that does not exist raises KeyError: 'evaluate_at' when sorting, because the setup loop never assigned the key.
  • A t_range ending at or after the final simulation year raises IndexError in np.where(self.t > t_range[1])[0].
  • If no (parameter, population) match is found at evaluation time, a_t_val is unbound.
  • acceptance_criteria=[] is a mutable default in run_sim, run_sampled_sims, _run_sampled_sim, run_model and Model.__init__, and the dicts are mutated in place (evaluate_at, assessed_value).

Implementation plan

  1. Validate criteria in Model.build(): check the variable exists in the named population via self.get_pop(pop).get_variable(name), raise ModelError naming the offending criterion otherwise.
  2. Support compartments, characteristics and parameters uniformly: treat anything without _is_dynamic (compartments, characteristics) as evaluable at runtime, and parameters according to _is_dynamic.
  3. If t_range[1] >= self.t[-1], set evaluate_at = np.inf so the criterion is checked in the final evaluate_all pass.
  4. Change defaults to None and copy the criteria list in Model.__init__ (already deep-copied, so just fix the signatures).
  5. Add a small AcceptanceCriterion dataclass or at least a documented schema, and tests for each of the cases above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions