Potentially change how build
handles default values
#702
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current behavior for setting default values is that the build function calls
_set_defaults!
on the model definition before running the model. The_set_defaults!
function creates external parameters for any unconnected parameters that have default values. This means that the model definition is modified by therun
function. Specifically, there will be extra parameters in the external_params list after running that weren't there before. This could cause confusion, in particular about when a user can useset_param!
versusupdate_param!
to change a parameter's value.This PR changes the behavior of the
build
function such that the_set_defaults!
function is called on the deepcopy of the model definition that gets stored in the created model instance, instead of on the original model definition. I think this makes for more intuitive behavior of the parameters. See the added test file here for the expected behavior.I've marked this as draft because we should definitely discuss this.
Note: if we go with this, we'll need to check if there are cases in the models' code that use set_param/update_param at the wrong time