From ccb221b2055afe2785a458567b302ad3e7da3429 Mon Sep 17 00:00:00 2001 From: "Velimir (monty) Vesselinov" Date: Thu, 8 Aug 2024 06:53:10 -0600 Subject: [PATCH] code changes minor --- src-old/MadsDocumentation.jl | 2 -- src-old/MadsPlotPy.jl | 1 - src/MadsAnasol.jl | 1 - src/MadsBayesInfoGap.jl | 2 +- src/MadsCreate.jl | 1 - src/MadsDisplay.jl | 1 - src/MadsExecute.jl | 2 -- src/MadsFunc.jl | 12 ++++++---- src/MadsHelp.jl | 1 - src/MadsHelpers.jl | 3 --- src/MadsIO.jl | 5 ---- src/MadsKriging.jl | 1 - src/MadsLevenbergMarquardt.jl | 3 --- src/MadsMisc.jl | 43 ++++++++++------------------------ src/MadsModules.jl | 1 - src/MadsMonteCarlo.jl | 3 +++ src/MadsObservations.jl | 3 --- src/MadsParallel.jl | 1 - src/MadsParameters.jl | 2 -- src/MadsPlot.jl | 5 ---- src/MadsSVR.jl | 1 - src/MadsSensitivityAnalysis.jl | 1 - src/MadsSineTransformations.jl | 2 -- 23 files changed, 24 insertions(+), 73 deletions(-) diff --git a/src-old/MadsDocumentation.jl b/src-old/MadsDocumentation.jl index 26c2d52f..6802e742 100644 --- a/src-old/MadsDocumentation.jl +++ b/src-old/MadsDocumentation.jl @@ -19,7 +19,6 @@ function getfunctionargumentsold(f::Function, m::Base.MethodList, l::Integer=get end return sort(unique(mp)) end - @doc """ Get function arguments @@ -54,7 +53,6 @@ function getfunctionkeywordsold(f::Function, m::Base.MethodList, l::Integer=getm end return sort(unique(mp)) end - @doc """ Get function keywords diff --git a/src-old/MadsPlotPy.jl b/src-old/MadsPlotPy.jl index 4969b9fa..b8fd0049 100644 --- a/src-old/MadsPlotPy.jl +++ b/src-old/MadsPlotPy.jl @@ -63,7 +63,6 @@ function plotgrid(madsdata::AbstractDict, parameters::AbstractDict; addtitle::Bo plotgrid(madsdata, s; addtitle=addtitle, title=title, filename=filename, format=format) end end - @doc """ Plot a 3D grid solution based on model predictions in array `s`, initial parameters, or user provided parameter values diff --git a/src/MadsAnasol.jl b/src/MadsAnasol.jl index 8d122fb0..cdcc0947 100644 --- a/src/MadsAnasol.jl +++ b/src/MadsAnasol.jl @@ -507,7 +507,6 @@ function computemass(madsfiles::Union{Regex,String}; time::Number=0, path::Abstr end return lambda, mass_injected, mass_reduced end - @doc """ Compute injected/reduced contaminant mass (for a given set of mads input files when "path" is provided) diff --git a/src/MadsBayesInfoGap.jl b/src/MadsBayesInfoGap.jl index 1ac03759..0e0c9532 100644 --- a/src/MadsBayesInfoGap.jl +++ b/src/MadsBayesInfoGap.jl @@ -41,7 +41,7 @@ function makebigdt!(madsdata::AbstractDict, choice::AbstractDict) madsinfo("Decision parameter $(paramname) set to $c.") end makeloglikelihood = makearrayconditionalloglikelihood(madsdata) - logprior = makearrayfunction(madsdata, makelogprior(madsdata)) + logprior = Mads.makearrayfunction(madsdata, makelogprior(madsdata)) nominalparams = getparamsinit(madsdata) f = makemadscommandfunction(madsdata; calczeroweightobs=true, calcpredictions=true) function likelihoodparamsmax(horizon::Real) diff --git a/src/MadsCreate.jl b/src/MadsCreate.jl index 0551beb5..31d31a91 100644 --- a/src/MadsCreate.jl +++ b/src/MadsCreate.jl @@ -297,7 +297,6 @@ function createproblem(madsdata::AbstractDict, predictions::AbstractDict) end return madsdata_c end - @doc """ Create a new Mads problem where the observation targets are computed based on the model predictions diff --git a/src/MadsDisplay.jl b/src/MadsDisplay.jl index afd288fe..affd10f4 100644 --- a/src/MadsDisplay.jl +++ b/src/MadsDisplay.jl @@ -137,7 +137,6 @@ function display(o; gwo=nothing, gho=nothing, gw=gwo, gh=gho) print("\r") end end - @doc """ Display image file diff --git a/src/MadsExecute.jl b/src/MadsExecute.jl index 935377af..8f6affc3 100644 --- a/src/MadsExecute.jl +++ b/src/MadsExecute.jl @@ -22,7 +22,6 @@ function checknodedir(dir::AbstractString, waittime::Float64=10.) # 10 seconds end return true end - @doc """ Check if a directory is readable @@ -111,7 +110,6 @@ function runcmd(cmdstring::AbstractString; quiet::Bool=Mads.quiet, pipe::Bool=fa end return r end - @doc """ Run external command and pipe stdout and stderr diff --git a/src/MadsFunc.jl b/src/MadsFunc.jl index a7a23f7e..06353bd9 100644 --- a/src/MadsFunc.jl +++ b/src/MadsFunc.jl @@ -352,7 +352,6 @@ function makemadsreusablefunction(paramkeys::AbstractVector, obskeys::AbstractVe return madscommandfunction end end - @doc """ Make Reusable Mads function to execute a forward model simulation (automatically restarts if restart data exists) @@ -382,8 +381,7 @@ Returns: - restart directory where reusable model results will be stored """ -function getrestartdir(madsdata::AbstractDict, suffix::AbstractString="") - restartdir = "" +function getrestartdir(madsdata::AbstractDict, suffix::AbstractString="", restartdir::AbstractString="") if haskey(madsdata, "RestartDir") restartdir = madsdata["RestartDir"] if !isdir(restartdir) @@ -409,7 +407,11 @@ function getrestartdir(madsdata::AbstractDict, suffix::AbstractString="") end end if restartdir == "" - restartdir = getmadsrootname(madsdata; version=true) * "_restart" + rdir = getmadsrootname(madsdata; version=true) + if rdir == "" + return rdir + end + restartdir = rdir * "_restart" if !isdir(restartdir) try recursivemkdir(restartdir; filename=false) @@ -419,7 +421,7 @@ function getrestartdir(madsdata::AbstractDict, suffix::AbstractString="") end end end - if suffix != "" + if suffix != "" && restartdir != "" restartdir = joinpath(restartdir, suffix) recursivemkdir(restartdir; filename=false) end diff --git a/src/MadsHelp.jl b/src/MadsHelp.jl index 46833e00..140de804 100644 --- a/src/MadsHelp.jl +++ b/src/MadsHelp.jl @@ -128,7 +128,6 @@ function functions(m::Union{Symbol, Module}, string::AbstractString=""; shortout n > 0 && string == "" && @info("Number of functions in module $m: $n") return functions end - @doc """ List available functions in the MADS modules: diff --git a/src/MadsHelpers.jl b/src/MadsHelpers.jl index 27cf64ef..2af5848a 100644 --- a/src/MadsHelpers.jl +++ b/src/MadsHelpers.jl @@ -309,7 +309,6 @@ function haskeyword(madsdata::AbstractDict, class::AbstractString, keyword::Abst return false end end - @doc """ Check for a `keyword` in a `class` within the Mads dictionary `madsdata` @@ -345,7 +344,6 @@ function addkeyword!(madsdata::AbstractDict, class::AbstractString, keyword::Abs push!(madsdata[class], keyword) end end - @doc """ Add a `keyword` in a `class` within the Mads dictionary `madsdata` @@ -373,7 +371,6 @@ function deletekeyword!(madsdata::AbstractDict, class::AbstractString, keyword:: end end end - @doc """ Delete a `keyword` in a `class` within the Mads dictionary `madsdata` diff --git a/src/MadsIO.jl b/src/MadsIO.jl index 2520ea80..2ff0899a 100644 --- a/src/MadsIO.jl +++ b/src/MadsIO.jl @@ -808,7 +808,6 @@ function setnewmadsfilename(filename::AbstractString) end return joinpath(dir, filename) end - @doc """ Set new mads file name @@ -1079,7 +1078,6 @@ end searchdir(key::Regex; path::AbstractString = ".") = filter(x->occursin(key, x), readdir(path)) searchdir(key::AbstractString; path::AbstractString = ".") = filter(x->occursin(key, x), readdir(path)) - @doc """ Get files in the current directory or in a directory defined by `path` matching pattern `key` which can be a string or regular expression @@ -1102,7 +1100,6 @@ Examples: filterkeys(dict::AbstractDict, key::Regex) = key == r"" ? collect(keys(dict)) : filter(x->occursin(key, x), collect(keys(dict))) filterkeys(dict::AbstractDict, key::AbstractString = "") = key == "" ? collect(keys(dict)) : filter(x->occursin(key, x), collect(keys(dict))) - @doc """ Filter dictionary keys based on a string or regular expression @@ -1113,7 +1110,6 @@ argtext=Dict("dict"=>"dictionary", indexkeys(dict::AbstractDict, key::Regex) = key == r"" ? findall(collect(keys(dict))) : findall(x->occursin(key, x), collect(keys(dict))) indexkeys(dict::AbstractDict, key::AbstractString = "") = key == "" ? findall(collect(keys(dict))) : findall(x->occursin(key, x), collect(keys(dict))) - @doc """ Find indexes for dictionary keys based on a string or regular expression @@ -1124,7 +1120,6 @@ argtext=Dict("dict"=>"dictionary", getdictvalues(dict::AbstractDict, key::Regex) = map(y->(y, dict[y]), filterkeys(dict, key)) getdictvalues(dict::AbstractDict, key::AbstractString = "") = map(y->(y, dict[y]), filterkeys(dict, key)) - @doc """ Get dictionary values for keys based on a string or regular expression diff --git a/src/MadsKriging.jl b/src/MadsKriging.jl index ec6c86e0..555ead8a 100644 --- a/src/MadsKriging.jl +++ b/src/MadsKriging.jl @@ -205,7 +205,6 @@ end function estimationerror(w::AbstractVector, covmat::AbstractMatrix, covvec::AbstractVector, cov0::Number) return cov0 + LinearAlgebra.dot(w, covmat * w) - 2 * LinearAlgebra.dot(w, covvec) end - @doc """ Estimate kriging error diff --git a/src/MadsLevenbergMarquardt.jl b/src/MadsLevenbergMarquardt.jl index 33050377..afab24c1 100644 --- a/src/MadsLevenbergMarquardt.jl +++ b/src/MadsLevenbergMarquardt.jl @@ -33,7 +33,6 @@ function residuals(madsdata::AbstractDict) resultdict = Mads.forward(madsdata) residuals(madsdata, collect(values(resultdict))) end - @doc """ Compute residuals @@ -79,7 +78,6 @@ function of(madsdata::AbstractDict; filter::Union{AbstractVector,AbstractRange,C resultdict = Mads.forward(madsdata) of(madsdata, collect(values(resultdict)); filter=filter) end - @doc """ Compute objective function @@ -249,7 +247,6 @@ function makelmfunctions(madsdata::AbstractDict; parallel_gradients::Bool=parall end return f_lm, g_lm, o_lm end - @doc """ Make forward model, gradient, objective functions needed for Levenberg-Marquardt optimization diff --git a/src/MadsMisc.jl b/src/MadsMisc.jl index 92f90cbe..7d928c3d 100644 --- a/src/MadsMisc.jl +++ b/src/MadsMisc.jl @@ -3,16 +3,18 @@ import OrderedCollections import DocumentFunction import Printf -#= -function makearrayfunction_vector(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) - function arrayfunction(arrayparameters::AbstractVector) - return f(arrayparameters) - end - return arrayfunction -end -=# +""" +Make a version of the function `f` that accepts an array containing the optimal parameter values -function makearrayfunction_dictionary(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) +$(DocumentFunction.documentfunction(makearrayfunction; +argtext=Dict("madsdata"=>"MADS problem dictionary", + "f"=>"function [default=`makemadscommandfunction(madsdata)`]"))) + +Returns: + +- function accepting an array containing the optimal parameter values +""" +function makearrayfunction(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) optparamkeys = getoptparamkeys(madsdata) initparams = Mads.getparamdict(madsdata) function arrayfunction_merge(arrayparameters::AbstractVector) @@ -30,25 +32,8 @@ function makearrayfunction_dictionary(madsdata::AbstractDict, f::Function=makema end end -function makearrayfunction(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) - # arrayfunction = vectorflag ? makearrayfunction_vector(madsdata, f) : makearrayfunction_dictionary(madsdata, f) - makearrayfunction_dictionary(madsdata, f) -end - -@doc """ -Make a version of the function `f` that accepts an array containing the optimal parameter values - -$(DocumentFunction.documentfunction(makearrayfunction; -argtext=Dict("madsdata"=>"MADS problem dictionary", - "f"=>"function [default=`makemadscommandfunction(madsdata)`]"))) - -Returns: - -- function accepting an array containing the optimal parameter values -""" makearrayfunction - function makedoublearrayfunction_vector(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) - arrayfunction = makearrayfunction(madsdata, f) + arrayfunction = Mads.makearrayfunction(madsdata, f) function doublearrayfunction(arrayparameters::AbstractMatrix) nr = size(arrayparameters, 2) vectorresult = Array{Float64}(undef, nr) @@ -61,7 +46,7 @@ function makedoublearrayfunction_vector(madsdata::AbstractDict, f::Function=make end function makedoublearrayfunction_dictionary(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) - arrayfunction = makearrayfunction(madsdata, f) + arrayfunction = Mads.makearrayfunction(madsdata, f) obskeys = getobskeys(madsdata) function doublearrayfunction(arrayparameters::AbstractVector) dictresult = arrayfunction(arrayparameters) @@ -75,11 +60,9 @@ function makedoublearrayfunction_dictionary(madsdata::AbstractDict, f::Function= end return doublearrayfunction end - function makedoublearrayfunction(madsdata::AbstractDict, f::Function=makemadscommandfunction(madsdata)) doublearrayfunction = vectorflag ? makedoublearrayfunction_vector(madsdata, f) : makedoublearrayfunction_dictionary(madsdata, f) end - @doc """ Make a version of the function `f` that accepts an array containing the optimal parameter values, and returns an array of observations diff --git a/src/MadsModules.jl b/src/MadsModules.jl index fd24c8f3..3fea83f3 100644 --- a/src/MadsModules.jl +++ b/src/MadsModules.jl @@ -379,7 +379,6 @@ function tag(madsmodule::AbstractString, versionsym::Symbol=:patch) @warn("$(madsmodule) cannot be tagged!") end end - @doc """ Tag Mads modules with a default argument `:patch` diff --git a/src/MadsMonteCarlo.jl b/src/MadsMonteCarlo.jl index 059bdb08..fee83809 100644 --- a/src/MadsMonteCarlo.jl +++ b/src/MadsMonteCarlo.jl @@ -184,6 +184,9 @@ function emceesampling(madsdata::AbstractDict, p0::AbstractMatrix; filename::Abs arrayloglikelihood = (x)->Core.eval(Main, :arrayloglikelihood_distributed)(x) end numsamples_perwalker_burnin = div(burnin, numwalkers) + if numsamples_perwalker_burnin == 0 + numsamples_perwalker_burnin = 10 + end numsamples = numsamples_perwalker_burnin * numwalkers @info("AffineInvariantMCMC burning stage (total number of executions $(numsamples), final burning chain size $(numsamples_perwalker_burnin * numwalkers))...") burninchain, _ = AffineInvariantMCMC.sample(arrayloglikelihood, numwalkers, p0, numsamples_perwalker_burnin, 1; filename="", load=false, save=false, rng=Mads.rng) diff --git a/src/MadsObservations.jl b/src/MadsObservations.jl index d1b027be..faf15770 100644 --- a/src/MadsObservations.jl +++ b/src/MadsObservations.jl @@ -274,7 +274,6 @@ function setobstime!(madsdata::AbstractDict, rx::Regex, obskeys::AbstractVector= end end end - @doc """ Set observation time based on the observation name in the MADS problem dictionary @@ -301,7 +300,6 @@ function setobsweights!(madsdata::AbstractDict, v::AbstractVector, obskeys::Abst setweight!(madsdata["Observations"][obskeys[i]], v[i]) end end - @doc """ Set observation weights in the MADS problem dictionary @@ -530,7 +528,6 @@ function createobservations!(madsdata::AbstractDict, observation::AbstractDict; end madsdata["Observations"] = observationsdict end - @doc """ Create observations in the MADS problem dictionary based on `time` and `observation` vectors diff --git a/src/MadsParallel.jl b/src/MadsParallel.jl index 87f130ea..d5027808 100644 --- a/src/MadsParallel.jl +++ b/src/MadsParallel.jl @@ -252,7 +252,6 @@ function setdir() dir = Distributed.remotecall_fetch(()->pwd(), 1) setdir(dir) end - @doc """ Set the working directory (for parallel environments) diff --git a/src/MadsParameters.jl b/src/MadsParameters.jl index 3f59307a..066783c5 100644 --- a/src/MadsParameters.jl +++ b/src/MadsParameters.jl @@ -395,7 +395,6 @@ function getoptparams(madsdata::AbstractDict, parameterarray::AbstractArray=getp return parameterarray end end - @doc """ Get optimizable parameters @@ -954,7 +953,6 @@ function boundparameters!(madsdata::AbstractDict, pardict::AbstractDict) end return nothing end - @doc """ Bound model parameters based on their ranges diff --git a/src/MadsPlot.jl b/src/MadsPlot.jl index eae9325c..87d31123 100644 --- a/src/MadsPlot.jl +++ b/src/MadsPlot.jl @@ -381,7 +381,6 @@ function plotmatches(madsdata::AbstractDict, dict_in::AbstractDict; plotdata::Bo end return nothing end - @doc """ Plot the matches between model predictions and observations @@ -585,7 +584,6 @@ function plotwellSAresults(madsdata::AbstractDict, result::AbstractDict, wellnam !quiet && Mads.display(p; gw=8Gadfly.inch, gh=vsize) return nothing end - @doc """ Plot the sensitivity analysis results for all the wells in the MADS problem dictionary (wells class expected) @@ -836,7 +834,6 @@ function spaghettiplots(madsdata::AbstractDict, paramdictarray::OrderedCollectio end return nothing end - @doc """ Generate separate spaghetti plots for each `selected` (`type != null`) model parameter @@ -1035,7 +1032,6 @@ function spaghettiplot(madsdata::AbstractDict, matrix::AbstractMatrix; plotdata: !quiet && Mads.display(pl; gw=8Gadfly.inch, gh=vsize) return nothing end - @doc """ Generate a combined spaghetti plot for the `selected` (`type != null`) model parameter @@ -1112,7 +1108,6 @@ function plotseries(X::Union{AbstractMatrix,AbstractVector}, filename::AbstractS plotseriesengine(m, filename; names=names, kw...) end end - @doc """ Create plots of data series diff --git a/src/MadsSVR.jl b/src/MadsSVR.jl index 0efaeb16..795c8bae 100644 --- a/src/MadsSVR.jl +++ b/src/MadsSVR.jl @@ -48,7 +48,6 @@ function svrtraining(madsdata::AbstractDict, numberofsamples::Integer=100; addmi end svrtraining(madsdata, paramarray; kw...) end - @doc """ Train SVR diff --git a/src/MadsSensitivityAnalysis.jl b/src/MadsSensitivityAnalysis.jl index 6ed840ed..c1dc6002 100644 --- a/src/MadsSensitivityAnalysis.jl +++ b/src/MadsSensitivityAnalysis.jl @@ -420,7 +420,6 @@ function getparamrandom(madsdata::AbstractDict, parameterkey::Union{Symbol, Abst end return nothing end - @doc """ Get independent sampling of model parameters defined in the MADS problem dictionary diff --git a/src/MadsSineTransformations.jl b/src/MadsSineTransformations.jl index 7293d2a1..c6c36e99 100644 --- a/src/MadsSineTransformations.jl +++ b/src/MadsSineTransformations.jl @@ -14,7 +14,6 @@ function asinetransform(params::AbstractVector, lowerbounds::AbstractVector, upp sineparams = asin.((sineparams .- lowerbounds) ./ (upperbounds .- lowerbounds) .* 2 .- 1) return sineparams end - @doc """ Arcsine transformation of model parameters @@ -45,7 +44,6 @@ function sinetransform(sineparams::AbstractVector, lowerbounds::AbstractVector, params[indexlogtransformed] = 10 .^ params[indexlogtransformed] return params end - @doc """ Sine transformation of model parameters