Skip to content

Commit 545e151

Browse files
committed
add keyword writemode, release v0.1.3
1 parent 6269d27 commit 545e151

4 files changed

Lines changed: 42 additions & 20 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
version:
14-
- '1.11.0'
14+
- '1.11.5'
1515
os:
1616
- ubuntu-latest
1717
- macOS-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ParameterSpace"
22
uuid = "1cbe449d-ba56-45e5-b823-2aefb7650dd9"
33
authors = ["islent <[email protected]>"]
4-
version = "0.1.2"
4+
version = "0.1.3"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

src/ParameterSpace.jl

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ result = analyse_function(g, params, 1.0)
7575
```
7676
"""
7777
function 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
209210
result = 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("../")

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ end
3131
return length(f[1]) + x
3232
end
3333

34-
tuning = analyse_program(command, content, "param.txt", params, analyse, args = [-15])
34+
tuning = analyse_program(command, content, "param.txt", params, analyse, args = [-15];
35+
folder = "output/program"
36+
)
3537
@test sum(tuning.result) == 9
3638
end

0 commit comments

Comments
 (0)