-
Notifications
You must be signed in to change notification settings - Fork 35
WIP Add payload retrieval function for SimulationInstance #543
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
Conversation
Ah interesting, yes I guess that gets to the heart of whether something like a post trial function would be considered part of the more general |
I have to admit I'm not familiar enough with the design right now to have an opinion. I think either you can decide, or we discuss it on Fri? |
I'm pretty sure it would make more sense for there to be a payload field in the I'll try to make those changes to Mimi on this branch and we can look at it/discuss on Friday. |
I just added the very small changes. I realized that creating an actual field in the Flow:
Example: using Mimi
@defcomp c begin
end
m = Model()
set_dimension!(m, :time, 1:2)
add_comp!(m, c)
function post_trial(sim_inst::SimulationInstance, trialnum::Int, ntimesteps::Int, tup::Union{Nothing, Tuple})
data = Mimi.payload(sim_inst)
data[trialnum] = trialnum
end
sim_def = @defsim begin
end
trials = 10
original_payload = zeros(trials)
Mimi.set_payload!(sim_def, original_payload)
sim_inst = run(sim_def, m, trials, post_trial_func = post_trial)
Mimi.payload(sim_def) == original_payload # in the original defintion, it's still zeros
Mimi.payload(sim_inst) == collect(1:trials) # in the instance, it's now 1:10
Mimi.payload(sim_inst.sim_def) == original_payload # the definition stored in the instance still holds the unmodified payload object |
Sounds good to me, I think keeping the central tenets of an immutable definition and a mutable instance is great and then we can play off of that. I think a test is failing with |
@ckingdon95 since we can't merge until all tests pass, can you merge in the master branch which will fix the failure of the dependency testing? |
Codecov Report
@@ Coverage Diff @@
## master #543 +/- ##
=========================================
+ Coverage 83.7% 83.81% +0.1%
=========================================
Files 27 27
Lines 2123 2125 +2
=========================================
+ Hits 1777 1781 +4
+ Misses 346 344 -2
Continue to review full report at Codecov.
|
I think this method should be added in order to more easily access a payload object during a post trial function. Without it, the user has to do
Mimi.payload(sim_inst.sim_def)
.I'm wondering though if it would make more sense for a copy of the payload object to be created as a field in SimulationInstance, instead of having it be stored in the copy of the simulation definition. Thoughts? @lrennels @davidanthoff