Skip to content

Commit dd272f5

Browse files
committed
docs: improve docstrings in print.jl following Julia Documentation Standards
- Add complete structure with Arguments, Returns, Notes, and See also sections - Enhance solver-specific will_solver_print methods with detailed documentation - Improve helper function docstrings with comprehensive descriptions - Add proper type specifications and cross-references - Follow Control Toolbox documentation standards
1 parent a050fd2 commit dd272f5

File tree

1 file changed

+125
-8
lines changed

1 file changed

+125
-8
lines changed

src/helpers/print.jl

Lines changed: 125 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ $(TYPEDSIGNATURES)
4848
Check if Ipopt will produce output based on `print_level` option.
4949
5050
Ipopt is silent when `print_level = 0`, verbose otherwise.
51+
52+
# Arguments
53+
- `solver::CTSolvers.Ipopt`: The Ipopt solver instance to check
54+
55+
# Returns
56+
- `Bool`: `true` if Ipopt will print output, `false` otherwise
57+
58+
# Notes
59+
- When `print_level` is not specified, Ipopt defaults to verbose output
60+
- This method allows the display system to conditionally show the `▫` symbol
61+
62+
See also: [`will_solver_print(::CTSolvers.AbstractNLPSolver)`](@ref)
5163
"""
5264
function will_solver_print(solver::CTSolvers.Ipopt)
5365
opts = CTSolvers.options(solver)
@@ -61,6 +73,18 @@ $(TYPEDSIGNATURES)
6173
Check if Knitro will produce output based on `outlev` option.
6274
6375
Knitro is silent when `outlev = 0`, verbose otherwise.
76+
77+
# Arguments
78+
- `solver::CTSolvers.Knitro`: The Knitro solver instance to check
79+
80+
# Returns
81+
- `Bool`: `true` if Knitro will print output, `false` otherwise
82+
83+
# Notes
84+
- When `outlev` is not specified, Knitro defaults to verbose output
85+
- This method allows the display system to conditionally show the `▫` symbol
86+
87+
See also: [`will_solver_print(::CTSolvers.AbstractNLPSolver)`](@ref)
6488
"""
6589
function will_solver_print(solver::CTSolvers.Knitro)
6690
opts = CTSolvers.options(solver)
@@ -75,6 +99,19 @@ Check if MadNLP will produce output based on `print_level` option.
7599
76100
MadNLP is silent when `print_level = MadNLP.ERROR`, verbose otherwise.
77101
Default is `MadNLP.INFO` which prints output.
102+
103+
# Arguments
104+
- `solver::CTSolvers.MadNLP`: The MadNLP solver instance to check
105+
106+
# Returns
107+
- `Bool`: `true` if MadNLP will print output, `false` otherwise
108+
109+
# Notes
110+
- Uses string comparison to avoid requiring MadNLP to be loaded
111+
- Default print level is `MadNLP.INFO` which produces output
112+
- Only `MadNLP.ERROR` level suppresses output
113+
114+
See also: [`will_solver_print(::CTSolvers.AbstractNLPSolver)`](@ref)
78115
"""
79116
function will_solver_print(solver::CTSolvers.MadNLP)
80117
opts = CTSolvers.options(solver)
@@ -97,6 +134,19 @@ Check if MadNCL will produce output based on `print_level` and `ncl_options.verb
97134
MadNCL is silent when either:
98135
- `print_level = MadNLP.ERROR`, or
99136
- `ncl_options.verbose = false`
137+
138+
# Arguments
139+
- `solver::CTSolvers.MadNCL`: The MadNCL solver instance to check
140+
141+
# Returns
142+
- `Bool`: `true` if MadNCL will print output, `false` otherwise
143+
144+
# Notes
145+
- Checks both the global print level and NCL-specific verbose option
146+
- Uses string comparison to avoid requiring MadNLP to be loaded
147+
- Either condition being false will suppress output
148+
149+
See also: [`will_solver_print(::CTSolvers.AbstractNLPSolver)`](@ref)
100150
"""
101151
function will_solver_print(solver::CTSolvers.MadNCL)
102152
opts = CTSolvers.options(solver)
@@ -131,11 +181,28 @@ end
131181
132182
Extract parameter types from strategies and convert to symbols.
133183
134-
Returns a NamedTuple with fields:
135-
- `disc`: Discretizer parameter symbol or `nothing`
136-
- `mod`: Modeler parameter symbol or `nothing`
137-
- `sol`: Solver parameter symbol or `nothing`
138-
- `params`: Vector of non-nothing parameter symbols
184+
This function analyzes the three strategy components (discretizer, modeler, solver)
185+
to determine their parameter types and converts them to symbolic representations
186+
for display purposes.
187+
188+
# Arguments
189+
- `discretizer`: The discretization strategy
190+
- `modeler`: The NLP modeling strategy
191+
- `solver`: The NLP solving strategy
192+
193+
# Returns
194+
- `NamedTuple`: Contains fields:
195+
- `disc`: Discretizer parameter symbol or `nothing`
196+
- `mod`: Modeler parameter symbol or `nothing`
197+
- `sol`: Solver parameter symbol or `nothing`
198+
- `params`: Vector of non-nothing parameter symbols
199+
200+
# Notes
201+
- Uses `CTSolvers.Strategies.get_parameter_type()` to extract parameter types
202+
- Converts parameter types to symbols using `CTSolvers.id()`
203+
- Filters out `nothing` values from the parameters vector
204+
205+
See also: [`_determine_parameter_display_strategy`](@ref)
139206
"""
140207
function _extract_strategy_parameters(discretizer, modeler, solver)
141208
disc_param = CTSolvers.Strategies.get_parameter_type(typeof(discretizer))
@@ -156,9 +223,23 @@ end
156223
157224
Determine how to display parameters based on their values.
158225
159-
Returns a NamedTuple with fields:
160-
- `show_inline`: Whether to show parameters inline with each component
161-
- `common`: Common parameter to show at end, or `nothing`
226+
This function analyzes the parameter symbols to decide whether they should be
227+
displayed inline with each component or as a common parameter at the end.
228+
229+
# Arguments
230+
- `params::Vector`: Vector of parameter symbols
231+
232+
# Returns
233+
- `NamedTuple`: Contains fields:
234+
- `show_inline::Bool`: Whether to show parameters inline with each component
235+
- `common`: Common parameter to show at end, or `nothing`
236+
237+
# Notes
238+
- If no parameters, shows nothing inline and no common parameter
239+
- If all parameters are equal, shows common parameter at end
240+
- If parameters differ, shows each parameter inline with its component
241+
242+
See also: [`_extract_strategy_parameters`](@ref)
162243
"""
163244
function _determine_parameter_display_strategy(params)
164245
if isempty(params)
@@ -178,6 +259,22 @@ end
178259
_print_component_with_param(io, component_id, show_inline, param_sym)
179260
180261
Print a component ID with optional inline parameter.
262+
263+
This helper function formats and prints a component identifier with an optional
264+
parameter displayed inline when appropriate.
265+
266+
# Arguments
267+
- `io::IO`: Output stream for printing
268+
- `component_id::String`: The component identifier to print
269+
- `show_inline::Bool`: Whether to show the parameter inline
270+
- `param_sym`: Parameter symbol to display (can be `nothing`)
271+
272+
# Notes
273+
- Component ID is printed in cyan with bold formatting
274+
- Parameter (if shown) is printed in magenta with bold formatting
275+
- Used by `display_ocp_configuration` for consistent formatting
276+
277+
See also: [`display_ocp_configuration`](@ref)
181278
"""
182279
function _print_component_with_param(io, component_id, show_inline, param_sym)
183280
printstyled(io, component_id; color=:cyan, bold=true)
@@ -192,6 +289,26 @@ end
192289
_build_source_tag(source, common_param, params, show_sources)
193290
194291
Build the source tag for an option based on its source and parameter context.
292+
293+
This helper function creates appropriate tags to indicate where an option
294+
came from (user-specified or computed) and its parameter dependency.
295+
296+
# Arguments
297+
- `source::Symbol`: Either `:user` or `:computed`
298+
- `common_param`: Common parameter for the strategy (can be `nothing`)
299+
- `params::Vector`: Vector of all parameter symbols
300+
- `show_sources::Bool`: Whether to include source information in tags
301+
302+
# Returns
303+
- `String`: The formatted source tag (empty string if no tag needed)
304+
305+
# Notes
306+
- For `:computed` source, shows parameter dependency (e.g., `[gpu-dependent]`)
307+
- For `:user` source, shows `[user]` when `show_sources=true`
308+
- Returns empty string when no tag is appropriate
309+
- Used by `display_ocp_configuration` for option source indication
310+
311+
See also: [`display_ocp_configuration`](@ref)
195312
"""
196313
function _build_source_tag(source, common_param, params, show_sources)
197314
if source == :computed

0 commit comments

Comments
 (0)