Skip to content

General tuning tools for julia. Dive into the parameter space of functions or external programs.

License

Notifications You must be signed in to change notification settings

JuliaAstroSim/ParameterSpace.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ParameterSpace.jl

General tuning tools for julia. Dive into the parameter space of functions or external programs.

codecov

Install

]add ParameterSpace
using ParameterSpace

Usage

Examples could be found in folder examples

Tuning a function

Let's take a simple function for example:

@inline g(x::Real, y::Real) = x * y

First construct the parameter space:

params = [Parameter("x", 1, 0:2),
          Parameter("y", 2, 0:2)]

which means there would be $3 \times 3 = 9$ combination of parameters in total, and ParameterSpace would help you run tests over all of them by calling the target function iterately:

tuning = analyse_function(g, params)

The returns are stored by DataFrames to give you enough freedom in data processing

julia> tuning = analyse_function(g, params)
9×3 DataFrame
 Row │ x    y    result 
     │ Any  Any  Any    
─────┼──────────────────
   10    0    0
   21    0    0
   32    0    0
   40    1    0
   51    1    1
   62    1    2
   70    2    0
   81    2    2
   92    2    4

If only tuning the second parameter y of function g, the other parameters should be set in order:

params = [Parameter("y", 2, 0:0.1:0.5)]
julia>     result = analyse_function(g, params, 1.0)
6×2 DataFrame
 Row │ y    result 
     │ Any  Any    
─────┼─────────────
   10.0  0.0
   20.1  0.1
   30.2  0.2
   40.3  0.3
   50.4  0.4
   60.5  0.5

Tuning a program

It is assumed that all of the parameters are passed through parameter file. First you need to tell ParameterSpace how to run your program, by define a Cmd:

command = `julia E:/ParameterSpace.jl/examples/simple_program/print.jl`

It may cause issues if you do not run the program from an absolute path.

Then write down the content of parameter file in formatted string:

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

Construct parameter space and use the tuning tool:

params = [Parameter("x", 1, 0:2),
          Parameter("y", 2, 0:2)]

analyse_program(command, content, "param.txt", params)

where "param.txt" defines the name of parameter file.

Each set of parameters would be handled in a seperate sub-folder

There is no general way to pass data from a program to Julia, however it's easy and convenient to analyse the output files automatically if you could provide an anlysis function. The procedure has no difference from tuning a function, and the parameters of analysis function could be set with keyword args::Union{Tuple,Array}:

function analyse(args...)
    ...
    return ...
end

analyse_program(command, content, "param.txt", params, analyse, args = [])

more details in examples/simple_program/

About

General tuning tools for julia. Dive into the parameter space of functions or external programs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages