Skip to content

Commit

Permalink
Finished solve for simulate ensembles (DARPA-ASKEM#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jClugstor committed Nov 6, 2023
1 parent cafe558 commit ee421e7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ function Ensemble{T}(o::OperationRequest) where {T}
Ensemble{T}(model_ids, operations, weights, sol_mappings, df)
end

# Solves multiple ODEs, performs a weighted sum
# of the solutions.
# Solves multiple ODEs, performs a weighted sum
# of the solutions.
function solve(o::Ensemble{Simulate}; callback)
Expand All @@ -306,16 +308,16 @@ function solve(o::Ensemble{Simulate}; callback)
sol = solve(enprob; saveat = 1, callback);

weights = o.weights
sol_maps = o.sol_mappings[1]
sol_maps = o.sol_mappings

sol_map_states = [state for state in states(systems[1]) if first(values(state.metadata))[2] in Symbol.(values(sol_maps))]

data = [x => vec(sum(stack(weights .* [ind_sol[x] for ind_sol in sol]), dims = 2)) for x in sol_map_states]

state_symbs = [first(values(pair.first.metadata))[2] for pair in data]
state_symbs = [Symbol(pair.first) for pair in data]
state_data = [dat.second for dat in data]
dataframable_pairs = [state => data for (state,data) in zip(state_symbs,state_data)]
DataFrame(:timestamp => sol[1].t, dataframable_pairs...)
DataFrame(:t => sol[1].t, dataframable_pairs...)
end


Expand Down

0 comments on commit ee421e7

Please sign in to comment.