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

function to save results in an efficient file #335

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Hackaton/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "Hackaton"
uuid = "54770aa0-30bd-4802-936f-8f0ece771688"
authors = ["Ssalazar12 <[email protected]>"]
version = "0.1.0"
5 changes: 5 additions & 0 deletions Hackaton/src/Hackaton.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Hackaton

greet() = print("Hello World!")

end # module Hackaton
46 changes: 46 additions & 0 deletions src/save_results.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using FileIO


function export_results_dict(res::Result)
# takes an instance of the Result Structure and ommits the NaN's
# by creating a dictionary at each elelement of Result.solutions
# which only saves the non-Nan indices and values

dimensions_parameters = size(res.solutions)
dimension_solutions = length(res.solutions[1])

# THis is a janky way of asking whether we sweep through 1 or 2 parameters
if length(dimensions_parameters) == 1
M=Array{Dict}(undef, dimensions_parameters[1])
elseif length(dimensions_parameters) == 2
M=Array{Dict}(undef, dimensions_parameters[1],dimensions_parameters[2])
end

# Iterate over each of the array elements
for iter in eachindex(res.solutions)
A = res.solutions[iter]
value_list= []
key_list = []
# ask wether the solution is NaN
for i in 1:dimension_solutions
if isnan(A[i][1]) == false
push!(key_list, i)
push!(value_list, A[i])
end
end
# save a dictionary at each element of the M matrix
M[iter] = Dict(key_list .=> value_list)
end
return M
end

# Example for some result obtained by result = get_steady_states(harmonic_eq2, varied, fixed)

MM = export_results_dict(result);

save("dict_version.jld2", Dict("solution_matrix" => MM, "classes" => result.classes,
"swept_parameters" => result.swept_parameters, "jacobian"=>result.jacobian,
"num_solutions" => length(result.solutions[1,1])))