+1 for PythonCall.jl. It just makes life so much easier.
Install:
(dragonfly) pkg> add CondaPkg, PythonCall
julia> using CondaPkg
(dragonfly) pkg> conda add numpy
(dragonfly) pkg> conda add --pip dragonfly-opt
(dragonfly) pkg> conda resolve
Run:
julia> using PythonCall
julia> @pyexec("""
global my_min, minimise_function, func
from dragonfly import minimise_function
def func(x):
return -x**2 - x + 1
def my_min(domain, max_capital):
return minimise_function(func, domain, max_capital)
""")
julia> my_min(domain, max_capital) = @pyeval("my_min")(domain, max_capital)
my_min (generic function with 1 method)
julia> min_val, min_pt, history = my_min(pylist([[-10, 10]]), 20);
Optimisation with bo(ei-ucb-ttei-add_ucb) using capital 20.0 (return_value)
Capital spent on initialisation: 5.0000(0.2500).
Legend: <iteration_number> (<num_successful_queries>, <fraction_of_capital_spent>):: curr_max=<current_maximum_value>, acqs=<num_times_each_acquisition_was_used>
#013 (011, 0.550):: curr_max=109.00000, acqs=[ei:1, ucb:2, ttei:0, add_ucb:3],
#022 (021, 1.050):: curr_max=109.00000, acqs=[ei:2, ucb:4, ttei:2, add_ucb:8],
julia> @info :Result min_val min_pt
┌ Info: Result
│ min_val = Python float: -108.99999999999993
└ min_pt = Python ndarray: array([10.])
You can also work with the python function directly:
julia> @py import dragonfly: minimise_function
julia> minimise_function
Python function: <function minimise_function at 0x7fe59d1745e0>
but that goes beyond my knowledge of how this dragonfly
package works, and mixing julia and python objects can get a bit more dicey than just wrapping everything into a julia function
Edit: wow
julia> using PythonCall
julia> @py import dragonfly: minimise_function
julia> func(x) = -x[1]^2 - x[1] + 1
func (generic function with 1 method)
julia> min_val, min_pt, history = minimise_function(func, pylist([[-10, 10]]), 20);
julia> @info :Result min_val min_pt
┌ Info: Result
│ min_val = Python float: -108.99999999999993
└ min_pt = Python ndarray: array([10.])