Skip to content

[Task]: Make parameter validation happen before modifying simulation state #58

Description

@sepandhaghighi

Describe the feature you want to add

Refactor the simulate() method in DrugReleaseModel so that model parameters are validated before any simulation state is modified.

Currently, simulate() assigns new values to _time_points before calling _validate_parameters(). If parameter validation fails, the model can be left with partially updated simulation state.

Describe your proposed solution

Move the _validate_parameters() call before assigning new values to _time_points and _release_profile.

Calculate the time points and release profile using local variables first, and only update the model's internal state after validation and model evaluation have completed successfully.

The implementation should follow this flow:

  1. Validate duration and time_step.
  2. Validate model parameters.
  3. Calculate the time points in a local variable.
  4. Calculate the release profile in a local variable.
  5. Assign the calculated values to _time_points and _release_profile.

This ensures that an unsuccessful simulation does not overwrite or partially modify an existing successful simulation.

Describe alternatives you've considered, if relevant

An alternative would be to restore the previous _time_points and _release_profile values if validation or calculation fails.

However, calculating the new simulation data locally and committing it only after successful completion is simpler and avoids the need for rollback logic.

Additional context

No response

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions