Skip to content

update_param! when originally set by default  #788

@lrennels

Description

@lrennels

We need to revisit how we want set_param! vs. update_param! to work in the case of defaults being set. Current behavior is confusing to users:

  1. If a parameter is set by a default and the model is then run, users expect to be able to call update_param! on the parameter in the model, but this errors because they need to call set_param!. At the very least we should throw a better error telling them to try calling set_param!, but we should also discuss this behavior.
  1. Also comes out in Monte Carlo...

Frank

I'm doing a Monte Carlo with SNEASY and there are a couple parameters with default values. When I try to do an update_param! on them, it throws the error: Cannot update parameter; CO₂_0 not found in composite's external parameters. So to do a Monte Carlo, I have to first do a set_param! with a fake value, and then I can carry out the Monte Carlo runs with the update_param! syntax. Am I misunderstanding how this should work? If so, it seems like default values should only be used for things you never plan to change?

Here's some code to show what I'm talking about.

This errors

using Mimi
using MimiSNEASY
m = MimiSNEASY.get_model()
co2_vals = [281.0, 282.5]
for i = 1:2
	update_param!(m, :CO₂_0, co2_vals[i])
	run(m)
end

This works

using Mimi
using MimiSNEASY
m = MimiSNEASY.get_model()
set_param!(m, :rfco2, :CO₂_0, 10000.0)
co2_vals = [281.0, 282.5]
for i = 1:2
	update_param!(m, :CO₂_0, co2_vals[i])
	run(m)
end

David

Actually, I think I remember now why we did it the way it is right now: the alternative design would be that if one adds a component to a model, and that component has a parameter with a default value, we add an external parameter to the model with that name, set it to the value from the component, and then connect things up. So far so good, but if one then adds another component that has a parameter with the same name that also has a default value, then it is unclear how we would handle that.

Maybe we need a function that "elevates" a default parameter from a component to the model level...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions