Skip to content

Commit

Permalink
add progress bar, fix startup config, release v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Jun 20, 2024
1 parent 0304744 commit ea12536
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name = "ParameterSpace"
uuid = "1cbe449d-ba56-45e5-b823-2aefb7650dd9"
authors = ["islent <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
DataFrames = "1"
IterTools = "1"
ProgressMeter = "1"
julia = "1.6.0"
14 changes: 7 additions & 7 deletions src/ParameterSpace.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module ParameterSpace

using IterTools, DataFrames, Printf
using ProgressMeter

import Base: iterate, length

export
Parameter,

write_parameter_file,
analyse_function, analyse_program

Expand Down Expand Up @@ -34,7 +34,7 @@ end
########## Analyse Functions ##########

"""
function analyse_function(f::Function, Params::Array{Parameter,1}, arg...;)
function analyse_function(f::Function, Params::Array{Parameter,1}, arg...; kw...)
Tuning the function `f` over some of its arguments defined in `Params`. The outputs of `f` are stored in a `DataFrame`.
Expand All @@ -52,7 +52,7 @@ params = [Parameter("y", 2, 0:0.1:0.5)]
result = analyse_function(g, params, 1.0)
```
"""
function analyse_function(f::Function, Params::Array{Parameter,1}, arg...;)
function analyse_function(f::Function, Params, arg...; kw...)
# Construct parameter space
Space = Iterators.product([p.Range for p in Params]...)

Expand All @@ -73,12 +73,12 @@ function analyse_function(f::Function, Params::Array{Parameter,1}, arg...;)
tuning[!, Symbol(p.Name)] = Any[]
end
tuning[!, :result] = Any[]
for s in Space
@showprogress for s in Space
# Prepare for the argument list
for i in 1:length(Params)
args[Params[i].Index] = s[i]
end
push!(tuning, (s..., f(args...)))
push!(tuning, (s..., f(args...; kw...)))
end

return tuning
Expand Down Expand Up @@ -151,7 +151,7 @@ end
result = analyse_program(command, content, "param.txt", params, analyse, args = [-15])
```
"""
function analyse_program(command::Cmd, content::String, filename::String, Params::Array{Parameter,1}, analyse::Function = emptyfunction; args = [], OutputDir = "output")
function analyse_program(command::Cmd, content::String, filename::String, Params, analyse::Function = emptyfunction; args = [], OutputDir = "output")
# Construct parameter space
Space = Iterators.product([p.Range for p in Params]...)

Expand All @@ -164,7 +164,7 @@ function analyse_program(command::Cmd, content::String, filename::String, Params
end
tuning[!,:result] = Any[]

for s in Space
@showprogress for s in Space
folder = join(map(string, s), ", ")
mkdir(folder)
cd(folder)
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ end

@testset "Tuning program" begin
script = joinpath(pwd(), "program.jl")
command = `julia $script`
command = `julia --startup-file=no $script`

params = [Parameter("x", 1, [1,10,100]),
Parameter("y", 2, [1000,10000])]

content = "x = %d, y = %d"

# param.txt is writen before running the program, we simply read the file
function analyse(x::Int)
f = readlines("param.txt")
return length(f[1]) + x
Expand Down

0 comments on commit ea12536

Please sign in to comment.