Commit c9b49413 authored by William F Godoy's avatar William F Godoy
Browse files

Generate data in csv format for all steps

parent 2208738b
...@@ -8,6 +8,7 @@ Glob = "c27321d9-0574-5035-807b-f59d2c89b15c" ...@@ -8,6 +8,7 @@ Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a" GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
[compat] [compat]
julia = "1" julia = "1"
...@@ -20,6 +21,3 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" ...@@ -20,6 +21,3 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
[targets] [targets]
test = ["Test"] test = ["Test"]
...@@ -6,17 +6,17 @@ import Exio ...@@ -6,17 +6,17 @@ import Exio
function main() function main()
#### Configuration section ###### #### Configuration section ######
## exio_init requires three inputs and returns a handler of type exioH ## exio_init requires three inputs and returns a handler of type exioH
# only supported: AmrexCastro # only supported: AmrexCastro
app::String = "AmrexCastro" app::String = "AmrexCastro"
# location where several run outputs are located they must have a common prefix # location where several run outputs are located they must have a common prefix
outputPrefix::String = "/home/wgodoy/workspace/Castro/Exec/hydro_tests/Sedov/case" outputPrefix::String = "/home/wgodoy/workspace/Castro/Exec/hydro_tests/Sedov/case"
# file name inside outputs directories # file name inside outputs directories
logFile::String = "run.log" logFile::String = "run.log"
################################# #################################
# init Exio (can create as many entities as needed) # init Exio (can create as many entities as needed)
exio = Exio.exio_init(app, outputPrefix, logFile) exio = Exio.exio_init(app, outputPrefix, logFile)
# create a linear model based on provided runs (the larger, the better) # create a linear model based on provided runs (the larger, the better)
......
...@@ -11,9 +11,11 @@ Pkg.add("DataFrames") ...@@ -11,9 +11,11 @@ Pkg.add("DataFrames")
Pkg.add("GLM") Pkg.add("GLM")
Pkg.add("Plots") Pkg.add("Plots")
Pkg.add("PackageCompiler") Pkg.add("PackageCompiler")
Pkg.add("Flux")
Pkg.add("CSV")
using PackageCompiler using PackageCompiler
create_sysimage([:Glob, :Plots, :GLM, :DataFrames], sysimage_path = "jexio_deps.so") create_sysimage([:Glob, :Plots, :GLM, :DataFrames, :Flux, :CSV], sysimage_path = "jexio_deps.so")
exit() exit()
...@@ -11,7 +11,14 @@ mutable struct Amrex <: AbstractAmrex ...@@ -11,7 +11,14 @@ mutable struct Amrex <: AbstractAmrex
Amrex(outputPrefix::String, runlogFile::String) = new( Amrex(outputPrefix::String, runlogFile::String) = new(
"Amrex", "Amrex",
outputPrefix, outputPrefix,
["max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level", "caseID"], [
"max_step",
"amr.check_int",
"amr.plot_int",
"amr.n_cell",
"amr.max_level",
"caseID",
],
["plots_size", "checkpoints_size"], ["plots_size", "checkpoints_size"],
runlogFile, runlogFile,
) )
......
...@@ -3,6 +3,8 @@ include("../helper/helperSystem.jl") ...@@ -3,6 +3,8 @@ include("../helper/helperSystem.jl")
import DataFrames import DataFrames
import GLM import GLM
import Plots
import CSV
struct AmrexCastro <: AbstractAmrex struct AmrexCastro <: AbstractAmrex
app::String app::String
...@@ -44,7 +46,8 @@ function run_linear_models(extractor::AmrexCastro) ...@@ -44,7 +46,8 @@ function run_linear_models(extractor::AmrexCastro)
for key in keys(extractor.outputs) for key in keys(extractor.outputs)
if (key == "plots_size") if (key == "plots_size")
_run_linear_model_plots_size(extractor, X) #_run_linear_model_plots_size(extractor, X)
_run_linear_models_plots_size_step(extractor, X)
end end
end end
end end
...@@ -102,6 +105,69 @@ function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame ...@@ -102,6 +105,69 @@ function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame
end end
function _run_linear_models_plots_size_step(extractor::AmrexCastro, X::DataFrames.DataFrame)
# using Flux ML for 1st order fitting
# input with total_cells * output_number
Xd::Array{Int64,1} = []
# output directory size
Yd::Array{Float64,1} = []
# output Level0 directory size
Yd_Level0::Array{Float64,1} = []
caseIDs::Array{String,1} = []
outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
for (index,outputDir) in enumerate(outputDirs)
inputFile::String = _get_input_file(extractor, outputDir)
parameters = _input_parser(extractor, inputFile)
rootPlotName = get(parameters, "amr.plot_file", "")
# rootCheckpointName = get(parameters, "amr.plot_file", "")
# find all directories with rootPlotName and get its size
# root of _plt directories
plotFileDirs = helper_get_prefix_directories(string(outputDir, "/", rootPlotName))
plotsSize::Int64 = 0
counter::Int32 = 1
# extract ncells
ncells = X["amr.ncells"][index]
# caseID
caseID = helper_get_relative_path(outputDir)
for plotFileDir in plotFileDirs
# Xd
push!( Xd, counter*ncells)
# Yd
sizeDir::Int64 = helper_get_directory_size(plotFileDir)
plotsSize += sizeDir
push!( Yd, plotsSize)
# caseID
push!(caseIDs, string(caseID,"/",helper_get_relative_path(plotFileDir) ) )
counter = counter + 1
end
end
data = [(Xd,Yd)]
df::DataFrames.DataFrame = DataFrames.DataFrame( plots_cells = Xd, plots_size = Yd, caseID = caseIDs)
println(df)
CSV.write("plot_size.csv", df, header=true)
#display(Plots.scatter(Xd, Yd))
#readline()
end
function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.DataFrame) function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.DataFrame)
outputDirs = helper_get_prefix_directories(extractor.outputPrefix) outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
...@@ -129,22 +195,20 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data ...@@ -129,22 +195,20 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data
end end
println(plotsSizesData) println(plotsSizesData)
# Prepare the X independent variables in the linear model # Prepare the X independent variables in the linear model
XNames::Array{String} = extractor.outputs["plots_size"] XNames::Array{String} = extractor.outputs["plots_size"]
col1 = Symbol("amr.nplot_files") col1 = Symbol("amr.nplot_files")
col2 = Symbol("amr.ncells") col2 = Symbol("amr.ncells")
insert!(plotsSizesData, 2 ,X[!,col1] .* X[!,col2], :new_data) insert!(plotsSizesData, 2, X[!, col1] .* X[!, col2], :new_data)
#plotsSizesData[!,col1] = #plotsSizesData[!,col1] =
#for XName in XNames #for XName in XNames
#columnName = Symbol(XName) #columnName = Symbol(XName)
# this syntax [!, symbol] does not make a copy, use [:, symbol] for copies # this syntax [!, symbol] does not make a copy, use [:, symbol] for copies
#plotsSizesData[!, columnName] = X[!, columnName] #plotsSizesData[!, columnName] = X[!, columnName]
#end #end
# formula from https://discourse.julialang.org/t/glm-jl-with-unknown-column-names/20692/5 # formula from https://discourse.julialang.org/t/glm-jl-with-unknown-column-names/20692/5
...@@ -152,7 +216,7 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data ...@@ -152,7 +216,7 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data
predictors = Symbol.(names(plotsSizesData)[2:end]) predictors = Symbol.(names(plotsSizesData)[2:end])
println(plotsSizesData) println(plotsSizesData)
f = @eval(GLM.@formula($response ~ (+)( $(predictors...)))) f = @eval(GLM.@formula($response ~ (+)($(predictors...))))
ols = GLM.lm(f, plotsSizesData) ols = GLM.lm(f, plotsSizesData)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment