Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Expose the tag that is used in dual number with
ForwardAD()
to the user. This lets the user pass the tagnothing
to prevent Julia from compiling the entire Dual chain every time that the objective function is redefined.If not careful, this could lead to ForwardDiff getting confused with overlapping dual chains (e.g., when the objective function already uses dual numbers for internal computations), so it must be used with caution.
Example
Tested in Julia v1.10.2:
Running the optimization while we let
ForwardAD()
automatically define a tag based on the givenf
function:This takes ~140 seconds on my laptop, with most of the time being spent in the first function evaluation since Julia is compiling the objective function with dual numbers tagged to the current in-line definition of
f
.Manually setting the dual tag to
nothing:
It still takes ~140 secs the first time we run the optimization, but if we redefine
f
with newaeroargs...
and callSNOW.minimize(f, x0, ng, lx, ux, lg, ug, options)
again now it only takes ~8 seconds.