Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
version:
- '1.10'
- '1.11'
- '1.12'
os:
- ubuntu-latest
arch:
Expand Down
1 change: 1 addition & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

[pip.deps]
build = ""
fides = ""
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Fides"
uuid = "18b51ec4-043b-11f0-1953-6f1d11d509fa"
version = "1.1.0"
version = "1.2.0"

[deps]
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
Expand Down
1 change: 1 addition & 0 deletions src/Fides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const InputVector = Union{Vector{<:Real}, ComponentVector{<:Real}}

include(joinpath(@__DIR__, "hessian_update.jl"))
const HessianUpdate = Union{BB, SR1, BG, BFGS, DFP, Broyden, CustomHessian}
const HessianApproximation = Union{BB, SR1, BG, BFGS, DFP, Broyden}

include(joinpath(@__DIR__, "problem.jl"))
include(joinpath(@__DIR__, "options.jl"))
Expand Down
54 changes: 26 additions & 28 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,52 +74,50 @@ function _solve(prob::FidesProblem, hess_update::HessianUpdate,
np_py.asarray(lb), options = options_py,
verbose = verbose_py)
end
runtime = @elapsed begin
res = fides_opt_py.minimize(np_py.asarray(prob.x0))

if hess_update isa CustomHessian || hess_update.init_with_hess == false
runtime = @elapsed begin
res = fides_opt_py.minimize(np_py.asarray(prob.x0))
end
# An initialization Hessian has been provided by the user
else
hess_init_py = _get_hess_init_py(hess_update)
runtime = @elapsed begin
res = fides_opt_py.minimize(np_py.asarray(prob.x0), hess0 = hess_init_py)
end
end
return FidesSolution(PythonCall.pyconvert(Float64, res[0]),
PythonCall.pyconvert(Vector{Float64}, res[1]),
PythonCall.pyconvert(Int64, fides_opt_py.iteration), runtime,
PythonCall.pyconvert(Symbol, fides_opt_py.exitflag._name_))
end

function _get_hess_update_py(hess_update::HessianUpdate)
hess_update_py = _get_hess_method(hess_update)
_init_hess!(hess_update_py, hess_update.init_hess)
return hess_update_py
end

function _get_hess_method(hess_update::Union{BB, BG, SR1})
function _get_hess_update_py(hess_update::Union{BB, BG, SR1})
if hess_update isa BB
return hess_update_py = fides_py.BB(init_with_hess = hess_update.init_with_hess)
return hess_update_py = fides_py.BB()
elseif hess_update isa BG
return hess_update_py = fides_py.BG(init_with_hess = hess_update.init_with_hess)
return hess_update_py = fides_py.BG()
elseif hess_update isa SR1
return hess_update_py = fides_py.SR1(init_with_hess = hess_update.init_with_hess)
return hess_update_py = fides_py.SR1()
end
end
function _get_hess_method(hess_update::Union{BFGS, DFP})
@unpack init_with_hess, enforce_curv_cond, init_hess = hess_update
function _get_hess_update_py(hess_update::Union{BFGS, DFP})
enforce_curv_cond = hess_update.enforce_curv_cond
if hess_update isa BFGS
return hess_update_py = fides_py.BFGS(init_with_hess = init_with_hess,
enforce_curv_cond = enforce_curv_cond)
return hess_update_py = fides_py.BFGS(enforce_curv_cond = enforce_curv_cond)
elseif hess_update isa DFP
return hess_update_py = fides_py.DFP(init_with_hess = init_with_hess,
enforce_curv_cond = enforce_curv_cond)
return hess_update_py = fides_py.DFP(enforce_curv_cond = enforce_curv_cond)
end
end
function _get_hess_method(hess_update::Broyden)
@unpack phi, init_with_hess, enforce_curv_cond, init_hess = hess_update
return fides_py.Broyden(phi = phi, init_with_hess = init_with_hess,
enforce_curv_cond = enforce_curv_cond)
function _get_hess_update_py(hess_update::Broyden)
@unpack phi, enforce_curv_cond = hess_update
return fides_py.Broyden(phi = phi, enforce_curv_cond = enforce_curv_cond)
end

function _init_hess!(hess_update_py, init_hess)::Nothing
isnothing(init_hess) && return nothing
dim = size(init_hess)[1]
init_hess_py = np_py.array(init_hess)
hess_update_py.init_mat(dim, init_hess_py)
return nothing
function _get_hess_init_py(hess_update::HessianApproximation)
@assert hess_update.init_with_hess == true "Function for user provided Hessian \
called even though Hessian not provided. Please report as bug on GitHub"
return np_py.array(hess_update.init_hess)
end

function _get_init_with_hess(init_hess)::Bool
Expand Down
Loading