Skip to content

Commit 25c13a9

Browse files
committed
Improve inference in solve pipeline
This package makes heavy use of polyalgorithms. This provides a lot of flexibility and performance, but one downside is that it hinders inferrability. The lack of inferrability does not seem to cause serious performance issues, but it does stand in the way of being able to precompile the package via direct-chain-of-inference. (See #643 for issues that prevent usage of PrecompileTools.jl, which otherwise would be an easy solution because it circumvents the need for high-quality inference.) The goal of this PR is to make at least a subset of the `solve` pipeline (specifically, the part I'm using!) inferrable. It targets the following usage: ```julia solver, starts = solver_startsolutions(S, sols; start_parameters, target_parameters, ishomogeneous=false) Ssolve = solve(solver, starts; show_progress=false) ``` where `S` is a `CompiledSystem`. The eventual goal is that if users write their code this way, the entire pipeline can inferred and thus precompiled. To get closer to this goal, this PR adds: - the `ishomogeneous` keyword to bypass a non-inferrable branch in `parameter_homotopy` - several `Base.@constprop :aggressive` annotations to help the compiler optimize branches that depend on keyword arguments
1 parent 6a6ce86 commit 25c13a9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/solve.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ function solver_startsolutions(
128128
p₀ = generic_parameters,
129129
target_parameters = p₀,
130130
compile::Union{Bool,Symbol} = COMPILE_DEFAULT[],
131+
ishomogeneous::Union{Bool,Nothing} = nothing,
131132
start_subspace = nothing,
132133
target_subspace = nothing,
133134
intrinsic = nothing,
134135
kwargs...,
135136
)
137+
Base.@constprop :aggressive
136138
!isnothing(seed) && Random.seed!(seed)
137139

138140

@@ -159,6 +161,7 @@ function solver_startsolutions(
159161
start_parameters = start_parameters,
160162
target_parameters = target_parameters,
161163
compile = compile,
164+
ishomogeneous = ishomogeneous,
162165
kwargs...,
163166
)
164167
elseif start_system == :polyhedral
@@ -221,9 +224,11 @@ function parameter_homotopy_tracker(
221224
F::Union{System,AbstractSystem};
222225
tracker_options = TrackerOptions(),
223226
endgame_options = EndgameOptions(),
227+
ishomogeneous::Union{Bool,Nothing} = nothing,
224228
kwargs...,
225229
)
226-
H = parameter_homotopy(F; kwargs...)
230+
Base.@constprop :aggressive
231+
H = parameter_homotopy(F; ishomogeneous = ishomogeneous, kwargs...)
227232
EndgameTracker(H; tracker_options = tracker_options, options = endgame_options)
228233
end
229234

@@ -243,13 +248,16 @@ function parameter_homotopy(
243248
tracker_options = TrackerOptions(),
244249
endgame_options = EndgameOptions(),
245250
compile::Union{Bool,Symbol} = COMPILE_DEFAULT[],
251+
ishomogeneous::Union{Bool,Nothing} = nothing,
246252
kwargs...,
247253
)
254+
Base.@constprop :aggressive
248255
unsupported_kwargs(kwargs)
249256
m, n = size(F)
250257
H = ParameterHomotopy(fixed(F; compile = compile), start_parameters, target_parameters)
251258
f = System(F)
252-
if is_homogeneous(f)
259+
ish = isnothing(ishomogeneous) ? is_homogeneous(f) : ishomogeneous
260+
if ish
253261
vargroups = variable_groups(f)
254262
if vargroups === nothing
255263
m (n - 1) || throw(FiniteException(n - 1 - m))

0 commit comments

Comments
 (0)