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:
- Validate
duration and time_step.
- Validate model parameters.
- Calculate the time points in a local variable.
- Calculate the release profile in a local variable.
- 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
Describe the feature you want to add
Refactor the
simulate()method inDrugReleaseModelso that model parameters are validated before any simulation state is modified.Currently,
simulate()assigns new values to_time_pointsbefore 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_pointsand_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:
durationandtime_step._time_pointsand_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_pointsand_release_profilevalues 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