Skip to content

Commit

Permalink
code changes minor
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Aug 8, 2024
1 parent a1f1be8 commit ccb221b
Show file tree
Hide file tree
Showing 23 changed files with 24 additions and 73 deletions.
2 changes: 0 additions & 2 deletions src-old/MadsDocumentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function getfunctionargumentsold(f::Function, m::Base.MethodList, l::Integer=get
end
return sort(unique(mp))
end

@doc """
Get function arguments
Expand Down Expand Up @@ -54,7 +53,6 @@ function getfunctionkeywordsold(f::Function, m::Base.MethodList, l::Integer=getm
end
return sort(unique(mp))
end

@doc """
Get function keywords
Expand Down
1 change: 0 additions & 1 deletion src-old/MadsPlotPy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MadsAnasol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/MadsBayesInfoGap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/MadsCreate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MadsDisplay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function display(o; gwo=nothing, gho=nothing, gw=gwo, gh=gho)
print("\r")
end
end

@doc """
Display image file
Expand Down
2 changes: 0 additions & 2 deletions src/MadsExecute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function checknodedir(dir::AbstractString, waittime::Float64=10.) # 10 seconds
end
return true
end

@doc """
Check if a directory is readable
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/MadsFunc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MadsHelp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions src/MadsHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
5 changes: 0 additions & 5 deletions src/MadsIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ function setnewmadsfilename(filename::AbstractString)
end
return joinpath(dir, filename)
end

@doc """
Set new mads file name
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MadsKriging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/MadsLevenbergMarquardt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function residuals(madsdata::AbstractDict)
resultdict = Mads.forward(madsdata)
residuals(madsdata, collect(values(resultdict)))
end

@doc """
Compute residuals
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
43 changes: 13 additions & 30 deletions src/MadsMisc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MadsModules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions src/MadsMonteCarlo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/MadsObservations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MadsParallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ function setdir()
dir = Distributed.remotecall_fetch(()->pwd(), 1)
setdir(dir)
end

@doc """
Set the working directory (for parallel environments)
Expand Down
2 changes: 0 additions & 2 deletions src/MadsParameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ function getoptparams(madsdata::AbstractDict, parameterarray::AbstractArray=getp
return parameterarray
end
end

@doc """
Get optimizable parameters
Expand Down Expand Up @@ -954,7 +953,6 @@ function boundparameters!(madsdata::AbstractDict, pardict::AbstractDict)
end
return nothing
end

@doc """
Bound model parameters based on their ranges
Expand Down
5 changes: 0 additions & 5 deletions src/MadsPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit ccb221b

Please sign in to comment.