Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set param update #665

Merged
merged 39 commits into from
Mar 12, 2020
Merged

Set param update #665

merged 39 commits into from
Mar 12, 2020

Conversation

lrennels
Copy link
Collaborator

@lrennels lrennels commented Feb 28, 2020

@ckingdon95 and @lrennels to fix the doctests, including adding mim-next branches to FUND and DICE2010, and any other tutorial changes we need.

@corakingdon
Copy link
Collaborator

corakingdon commented Mar 3, 2020

Line 671: Is there a need to treat count == 1 as and special case? Won't the loop will handle this? The only diff is param_name vs nameof(param_ref), which I'm not sure are different.

For some reason, yes there are cases in some of the tests where these are different. I was just explaining to Lisa (but maybe should have said it in the general slack channel) that this fix only appears to work for flat models and not all composite models. It does work for some of the composites in the tests files though. I think it has to do with if the parameters have different names. This is definitely not a full/clean implementation though. I just pushed it for Lisa to be able to look at.

@rjplevin
Copy link
Collaborator

rjplevin commented Mar 3, 2020

I'm surprised it works sinceconnect_param!() disconnects prior connections to the same external parameter name.

@corakingdon
Copy link
Collaborator

I'm surprised it works sinceconnect_param!() disconnects prior connections to the same external parameter name.

I think it only disconnects parameters for that component, not for all things bound to that external parameter. For example, the following works now (and works in the mimi-next branches on FUND and DICE2010):

@defcomp A begin
    p1 = Parameter()
end

@defcomp B begin
    p1 = Parameter()
end

m = Model()
set_dimension!(m, :time, 10)
add_comp!(m, A)
add_comp!(m, B)
set_param!(m, :p1, 5)

run(m)
m[:A, :p1] == m[:B, :p1] == 5

@rjplevin
Copy link
Collaborator

rjplevin commented Mar 3, 2020

Great -- maybe it's simpler than I expected!

@lrennels
Copy link
Collaborator Author

lrennels commented Mar 4, 2020

Looks like we're failing a test in test_timesteparrays.jl where we fail to throw an exception. Logging it here to look into. I'm a bit confused, because looking the output there are no missing values In the resulting arrays, so I guess an error should not be thrown, but I am not sure how the order events has changed so that this functions properly.

update Ok that was dumb of me, this was before we had our rules about parameters having the same name! I changed the code so we have two distinct components with distinct parameters. Just to make sure, we're not throwing any kind of flags when two components have the same parameter right, we're assuming the user is aware of that meaning they both get set to the same thing?

@defcomp foo begin
    par = Parameter(index=[time])
    var = Variable(index=[time])
    function run_timestep(p, v, d, t)
        if is_last(t)
            v.var[t] = 0
        else
            v.var[t] = p.par[t+1]   # This is where the error will be thrown, if connected to an internal variable that has not yet been computed.
        end
    end
end

years = 2000:2010

m = Model()
set_dimension!(m, :time, years)
add_comp!(m, foo, :first)
add_comp!(m, foo, :second)
connect_param!(m, :second => :par, :first => :var)
set_param!(m, :first, :par, 1:length(years))

@test_throws MissingException run(m)

@codecov
Copy link

codecov bot commented Mar 4, 2020

Codecov Report

Merging #665 into master will decrease coverage by 1.05%.
The diff coverage is 84.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #665      +/-   ##
==========================================
- Coverage   80.24%   79.19%   -1.06%     
==========================================
  Files          39       39              
  Lines        2743     2840      +97     
==========================================
+ Hits         2201     2249      +48     
- Misses        542      591      +49
Impacted Files Coverage Δ
src/core/model.jl 81.81% <ø> (ø) ⬆️
src/core/types/params.jl 70% <ø> (+3.33%) ⬆️
src/core/show.jl 9.37% <0%> (-0.15%) ⬇️
src/core/types/instances.jl 72.13% <0%> (ø) ⬆️
src/core/types/core.jl 90.47% <0%> (-4.53%) ⬇️
src/core/instances.jl 78.3% <100%> (ø) ⬆️
src/core/types/defs.jl 76.56% <100%> (-2.75%) ⬇️
src/core/defmodel.jl 88.46% <100%> (ø) ⬆️
src/core/connections.jl 87.5% <100%> (-2.78%) ⬇️
src/core/paths.jl 82.35% <100%> (-5.89%) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d02bb6...323fe94. Read the comment docs.

@davidanthoff davidanthoff marked this pull request as ready for review March 12, 2020 22:31
@davidanthoff davidanthoff merged commit fb2481e into master Mar 12, 2020
@davidanthoff davidanthoff deleted the set-param-update branch March 12, 2020 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants