Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings to state and stats #657

Merged
merged 8 commits into from
Jan 6, 2024
Merged
Changes from 1 commit
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
38 changes: 35 additions & 3 deletions src/stats_state.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
"""
$(TYPEDEF)

Stores the optimization run's statistics that is returned
in the `stats` field of the `OptimizationResult`.

## Fields
- `iterations`: number of iterations
- `time`: time taken to run the solver
- `fevals`: number of function evaluations
- `gevals`: number of gradient evaluations
- `hevals`: number of hessian evaluations

Default values for all the field are set to 0 and hence even when
you might expect non-zero values due to unavilability of the information
from the solver it would be 0.
"""
struct OptimizationStats
iterations::Int
time::Float64
Expand All @@ -7,9 +23,24 @@
hevals::Int
end

OptimizationStats(; iterations = 0, time = 0.0, fevals = 0, gevals = 0, hevals = 0) =
function OptimizationStats(; iterations = 0, time = 0.0, fevals = 0, gevals = 0, hevals = 0)

Check warning on line 26 in src/stats_state.jl

View check run for this annotation

Codecov / codecov/patch

src/stats_state.jl#L26

Added line #L26 was not covered by tests
OptimizationStats(iterations, time, fevals, gevals, hevals)
end

"""
$(TYPEDEF)

Stores the optimization run's state at the current iteration
and is passed to the callback function as the first argument.

## Fields
- `iteration`: current iteration
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `iteration`: current iteration
- `iter`: current iteration

- `u`: current solution
- `objective`: current objective value
- `gradient`: current gradient
- `hessian`: current hessian
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `gradient`: current gradient
- `hessian`: current hessian
- `gradient`: current gradient
- `hessian`: current hessian

grad, hes

Make the naming match everything else, we can't just have one thing different.

- `solver_state`: if the solver has its own state object then it is stored here
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `solver_state`: if the solver has its own state object then it is stored here
- `original`: if the solver has its own state object then it is stored here

for uniformity.

"""
struct OptimizationState{X, O, G, H, S}
iteration::Int
u::X
Expand All @@ -19,6 +50,7 @@
solver_state::S
end

OptimizationState(; iteration = 0, u = nothing, objective = nothing,
gradient = nothing, hessian = nothing, solver_state = nothing) =
function OptimizationState(; iteration = 0, u = nothing, objective = nothing,

Check warning on line 53 in src/stats_state.jl

View check run for this annotation

Codecov / codecov/patch

src/stats_state.jl#L53

Added line #L53 was not covered by tests
gradient = nothing, hessian = nothing, solver_state = nothing)
OptimizationState(iteration, u, objective, gradient, hessian, solver_state)
end
Loading