@@ -75,8 +75,9 @@ result = analyse_function(g, params, 1.0)
7575```
7676"""
7777function analyse_function (func:: Function , Params, arg... ;
78- folder = " output" ,
79- filename = " ParameterSpace_log.csv" ,
78+ folder:: AbstractString = " output" ,
79+ filename:: AbstractString = " ParameterSpace_log.csv" ,
80+ writemode:: AbstractString = " w" ,
8081 kw...
8182)
8283 # Construct parameter space
@@ -101,12 +102,12 @@ function analyse_function(func::Function, Params, arg...;
101102 end
102103 tuning[! , :result ] = Any[]
103104
104- if ! isnothing (folder)
105- if ! isdir (folder)
106- mkpath (folder)
107- end
105+ if ! isdir (folder)
106+ mkpath (folder)
107+ end
108108
109- file = open (joinpath (folder, filename), " w" )
109+ file = open (joinpath (folder, filename), writemode)
110+ if writemode == " w"
110111 write (file, join (names (tuning), " ;" ) * " \n " )
111112 end
112113
@@ -209,43 +210,62 @@ end
209210result = analyse_program(command, content, "param.txt", params, analyse, args = [-15])
210211```
211212"""
212- function analyse_program (command:: Cmd , content:: String , filename:: String , Params, analyse:: Function = emptyfunction;
213- args = [], outputdir = " output" ,
213+ function analyse_program (command:: Cmd , content:: AbstractString , paramfilename:: AbstractString , Params, analyse:: Function = emptyfunction;
214+ args = [],
215+ folder:: AbstractString = " output" ,
216+ filename:: AbstractString = " ParameterSpace_log.csv" ,
217+ writemode:: AbstractString = " w" ,
218+ kw...
214219)
215220 # Construct parameter space
216221 Cases = collect (Iterators. product ([p. Range for p in Params]. .. ))
217222 @info " Total parameter combinations: $(length (Cases)) "
218223
219- if ! isdir (outputdir )
220- mkpath (outputdir )
224+ if ! isdir (folder )
225+ mkpath (folder )
221226 end
222- cd (outputdir )
227+ cd (folder )
223228
224229 tuning = DataFrame ()
225230 for p in Params
226231 tuning[! ,Symbol (p. Name)] = Any[]
227232 end
228233 tuning[! ,:result ] = Any[]
229234
235+ file = open (filename, writemode)
236+ if writemode == " w"
237+ write (file, join (names (tuning), " ;" ) * " \n " )
238+ end
239+
230240 try
231241 progress = Progress (length (Cases); desc = " Exploring parameter space: " )
232242 for c in eachindex (Cases)
233- folder = join (map (string, Cases[c]), " , " )
234- mkdir (folder )
235- cd (folder )
236- write_parameter_file (filename , content, Cases[c])
243+ folder_tuning = join (map (string, Cases[c]), " , " )
244+ mkdir (folder_tuning )
245+ cd (folder_tuning )
246+ write_parameter_file (paramfilename , content, Cases[c])
237247 run (command)
238- push! (tuning, (Cases[c]. .. , analyse (args... )))
248+ result = analyse (args... ; kw... )
249+ coord = (Cases[c]. .. , result)
250+ push! (tuning, coord)
239251 cd (" ../" )
240252
253+ if ! isnothing (folder)
254+ write (file, join (string .(coord), " ;" ) * " \n " )
255+ flush (file)
256+ end
257+
241258 next! (progress, showvalues = [
242259 (" case" , c),
243260 (" params" , Cases[c]),
261+ (" result" , result),
244262 ])
245263 end
264+ close (file)
246265 catch e
247266 throw (e)
248267 finally
268+ close (file)
249269 end
250270
251271 cd (" ../" )
0 commit comments