Skip to content

Commit

Permalink
Play with warmup method and add polyhedral method (#140)
Browse files Browse the repository at this point in the history
* deacrease perturbation in random_warmup

* add `:polyhedral` method

* add kwargs options for homotopy solver

* all parameter complex in warmup homotopy
  • Loading branch information
oameye authored Jan 4, 2024
1 parent b90ad5e commit 659dd36
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/solve_homotopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ A steady state result for 1000 parameter points
"""
function get_steady_states(prob::Problem, swept_parameters::ParameterRange, fixed_parameters::ParameterList;
method=:warmup, threading = Threads.nthreads() > 1, show_progress=true,
sorting="nearest", classify_default=true, seed=nothing)
sorting="nearest", classify_default=true, seed=nothing, kwargs...)

# set seed if provided
!isnothing(seed) && Random.seed!(seed)
Expand All @@ -108,8 +108,9 @@ function get_steady_states(prob::Problem, swept_parameters::ParameterRange, fixe

input_array = _prepare_input_params(prob, swept_parameters, unique_fixed)
# feed the array into HomotopyContinuation, get back an similar array of solutions
raw = _get_raw_solution(prob, input_array;
sweep=swept_parameters, method=method, threading=threading, show_progress=show_progress, seed=seed)
raw = _get_raw_solution(
prob, input_array; sweep=swept_parameters, method=method, threading=threading,
show_progress=show_progress, seed=seed, kwargs...)

# extract all the information we need from results
#rounded_solutions = unique_points.(HomotopyContinuation.solutions.(getindex.(raw, 1)); metric = EuclideanNorm(), atol=1E-14, rtol=1E-8)
Expand Down Expand Up @@ -249,20 +250,20 @@ end
"A random warmup solution is computed to use as `start_parameters` in the homotopy."
function _solve_warmup(problem::Problem, params_1D, sweep; threading, show_progress)
# complex perturbation of the warmup parameters
complex_pert = [1e-2 * issubset(p, keys(sweep)) * randn(ComplexF64) for p in problem.parameters]
complex_pert = [1e-5 * randn(ComplexF64) for p in problem.parameters]
real_pert = ones(length(params_1D[1]))
warmup_parameters = params_1D[end÷2] .* (real_pert + complex_pert)

warmup_solution =
HC.solve(problem.system;
HC.solve(problem.system; start_system=:total_degree,
target_parameters=warmup_parameters, threading=threading, show_progress=show_progress
)
return warmup_parameters, warmup_solution
end

"Uses HomotopyContinuation to solve `problem` at specified `parameter_values`."
function _get_raw_solution(problem::Problem, parameter_values;
sweep=ParameterRange(), method=:warmup, threading=false, show_progress=true, seed=nothing)
sweep=ParameterRange(), method=:warmup, threading=false, show_progress=true, seed=nothing, kwargs...)
# HomotopyContinuation accepts 1D arrays of parameter sets
params_1D = reshape(parameter_values, :, 1)

Expand All @@ -274,18 +275,18 @@ function _get_raw_solution(problem::Problem, parameter_values;
HC.solve(
problem.system, HC.solutions(warmup_solution);
start_parameters=warmup_parameters, target_parameters=parameter_values,
threading=threading, show_progress=show_progress, seed=seed
threading=threading, show_progress=show_progress, seed=seed, kwargs...
)
elseif method==:total_degree
elseif method==:total_degree || method==:polyhedral
result_full = Array{Vector{Any}, 1}(undef, length(parameter_values))
if show_progress
bar = Progress(length(parameter_values), 1, "Solving via total degree homotopy ...", 50)
bar = Progress(length(parameter_values), 1, "Solving via $method homotopy ...", 50)
end
for i in eachindex(parameter_values) # do NOT thread this
p = parameter_values[i]
show_progress ? next!(bar) : nothing
result_full[i] = [
HC.solve(problem.system; start_system=:total_degree,
HC.solve(problem.system; start_system=method,
target_parameters=p, threading=threading, show_progress=false, seed=seed), p]
end
else
Expand Down

2 comments on commit 659dd36

@oameye
Copy link
Member Author

@oameye oameye commented on 659dd36 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/98192

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.0 -m "<description of version>" 659dd3617aa499fa812b946be53876846758641c
git push origin v0.8.0

Please sign in to comment.