@@ -166,7 +166,7 @@ Whether internal variables are updates is determined by `always_update`.
166166This method does not perform any print itself but relies on it's children's print.
167167
168168It also sets the sub solvers active parameter, see |`DebugWhenActive`}(#ref).
169- Here, the `activattion_offset ` can be used to specify whether it refers to _this_ iteration,
169+ Here, the `activation_offset ` can be used to specify whether it refers to _this_ iteration,
170170the `i`th, when this call is _before_ the iteration, then the offset should be 0,
171171for the _next_ iteration, that is if this is called _after_ an iteration, it has to be set to 1.
172172Since usual debug is happening after the iteration, 1 is the default.
@@ -346,22 +346,25 @@ print the current cost function value, see [`get_cost`](@ref).
346346* `format="\$ prefix %f"`: format to print the output
347347* `io=stdout`: default stream to print the debug to.
348348* `long=false`: short form to set the format to `f(x):` (default) or `current cost: ` and the cost
349+ * `at_init=true`: whether to print also at initialization
349350"""
350351mutable struct DebugCost <: DebugAction
351352 io:: IO
352353 format:: String
354+ at_init:: Bool
353355 function DebugCost (;
354- long:: Bool = false , io:: IO = stdout , format = long ? " current cost: %f" : " f(x): %f"
356+ long:: Bool = false , io:: IO = stdout , format = long ? " current cost: %f" : " f(x): %f" ,
357+ at_init:: Bool = true ,
355358 )
356- return new (io, format)
359+ return new (io, format, at_init )
357360 end
358361end
359362function (d:: DebugCost )(p:: AbstractManoptProblem , st:: AbstractManoptSolverState , k:: Int )
360- (k >= 0 ) && Printf. format (d. io, Printf. Format (d. format), get_cost (p, get_iterate (st)))
363+ (k >= (d . at_init ? 0 : 1 ) ) && Printf. format (d. io, Printf. Format (d. format), get_cost (p, get_iterate (st)))
361364 return nothing
362365end
363366function show (io:: IO , di:: DebugCost )
364- return print (io, " DebugCost(; format=\" $(escape_string (di. format)) \" )" )
367+ return print (io, " DebugCost(; format=\" $(escape_string (di. format)) \" , at_init= $(di . at_init) )" )
365368end
366369status_summary (di:: DebugCost ) = " (:Cost, \" $(escape_string (di. format)) \" )"
367370
@@ -371,22 +374,23 @@ status_summary(di::DebugCost) = "(:Cost, \"$(escape_string(di.format))\")"
371374print a small divider (default `" | "`).
372375
373376# Constructor
374- DebugDivider(div,print )
377+ DebugDivider(div, io=stdout, at_init=true )
375378
376379"""
377380mutable struct DebugDivider{TypeIO <: IO } <: DebugAction
378381 io:: TypeIO
379382 divider:: String
380- DebugDivider (divider = " | " ; io:: IO = stdout ) = new {typeof(io)} (io, divider)
383+ at_init:: Bool
384+ DebugDivider (divider = " | " ; io:: IO = stdout , at_init:: Bool = true ) = new {typeof(io)} (io, divider, at_init)
381385end
382386function (d:: DebugDivider )(:: AbstractManoptProblem , :: AbstractManoptSolverState , k:: Int )
383- if k >= 0 && ! isempty (d. divider)
387+ if k >= (d . at_init ? 0 : 1 ) && ! isempty (d. divider)
384388 print (d. io, d. divider)
385389 end
386390 return nothing
387391end
388392function show (io:: IO , di:: DebugDivider )
389- return print (io, " DebugDivider(; divider=\" $(escape_string (di. divider)) \" )" )
393+ return print (io, " DebugDivider(; divider=\" $(escape_string (di. divider)) \" , at_init= $(di . at_init) )" )
390394end
391395status_summary (di:: DebugDivider ) = " \" $(escape_string (di. divider)) \" "
392396
@@ -399,26 +403,27 @@ how to print the entry.
399403# Additional fields
400404
401405* `field`: symbol the entry can be accessed with within [`AbstractManoptSolverState`](@ref)
406+ * `at_init`: whether to print also at initialization
402407
403408# Constructor
404409
405- DebugEntry(f; prefix="\$ f:", format = "\$ prefix %s", io=stdout)
406-
410+ DebugEntry(f; prefix="\$ f:", format = "\$ prefix %s", io=stdout, at_init=true)
407411"""
408412mutable struct DebugEntry <: DebugAction
409413 io:: IO
410414 format:: String
411415 field:: Symbol
412- function DebugEntry (f:: Symbol ; prefix = " $f :" , format = " $prefix %s" , io:: IO = stdout )
413- return new (io, format, f)
416+ at_init:: Bool
417+ function DebugEntry (f:: Symbol ; prefix = " $f :" , format = " $prefix %s" , io:: IO = stdout , at_init:: Bool = true )
418+ return new (io, format, f, at_init)
414419 end
415420end
416421function (d:: DebugEntry )(:: AbstractManoptProblem , st:: AbstractManoptSolverState , k)
417- (k >= 0 ) && Printf. format (d. io, Printf. Format (d. format), getfield (st, d. field))
422+ (k >= (d . at_init ? 0 : 1 ) ) && Printf. format (d. io, Printf. Format (d. format), getfield (st, d. field))
418423 return nothing
419424end
420425function show (io:: IO , di:: DebugEntry )
421- return print (io, " DebugEntry(:$(di. field) ; format=\" $(escape_string (di. format)) \" )" )
426+ return print (io, " DebugEntry(:$(di. field) ; format=\" $(escape_string (di. format)) \" , at_init= $(di . at_init) )" )
422427end
423428
424429"""
@@ -429,6 +434,7 @@ Display information about the feasibility of the current iterate
429434# Fields
430435* `format`: a vector of symbols and string formatting the output
431436* `io`: default stream to print the debug to.
437+ * `at_init`: whether to print also at initialization
432438
433439The following symbols are filled with values
434440
@@ -449,15 +455,17 @@ format to print the output.
449455DebugFeasibility(
450456 format=["feasible: ", :Feasible];
451457 io::IO=stdout,
458+ at_init::Bool=true,
452459)
453460
454461"""
455462mutable struct DebugFeasibility <: DebugAction
456463 format:: Vector{Union{String, Symbol}}
457464 io:: IO
458- function DebugFeasibility (format = [" feasible: " , :Feasible ]; io:: IO = stdout , atol = NaN )
465+ at_init:: Bool
466+ function DebugFeasibility (format = [" feasible: " , :Feasible ]; io:: IO = stdout , atol = NaN , at_init:: Bool = true )
459467 isnan (atol) || (@warn " Providing atol= directly to DebugFeasibility is deprecated. Use the keyword for the ConstrainedObjective instead. The value provided here ($(atol) ) is ignored" )
460- return new (format, io)
468+ return new (format, io, at_init )
461469 end
462470end
463471function (d:: DebugFeasibility )(
@@ -485,12 +493,12 @@ function (d::DebugFeasibility)(
485493 (f === :TotalEq ) && (s *= " $(sum (abs .(eqc_nz); init = 0.0 )) " )
486494 (f === :TotalInEq ) && (s *= " $(sum (ineqc_pos; init = 0.0 )) " )
487495 end
488- print (d. io, (k > 0 ) ? s : " " )
496+ print (d. io, (k >= (d . at_init ? 0 : 1 ) ) ? s : " " )
489497 return nothing
490498end
491499function show (io:: IO , d:: DebugFeasibility )
492500 sf = " [" * (join ([e isa String ? " \" $e \" " : " :$e " for e in d. format], " , " )) * " ]"
493- return print (io, " DebugFeasibility($sf )" )
501+ return print (io, " DebugFeasibility($sf , at_init= $(d . at_init) )" )
494502end
495503function status_summary (d:: DebugFeasibility )
496504 sf = " [" * (join ([e isa String ? " \" $e \" " : " :$e " for e in d. format], " , " )) * " ]"
@@ -514,10 +522,11 @@ That way you can print the value in this case as well.
514522* `msg`: if the `check` fails, this message is displayed
515523* `type`: symbol specifying the type of display, possible values `:print`, `: warn`, `:info`, `:error`,
516524 where `:print` prints to `io`.
525+ * `at_init`: whether to print also at initialization
517526
518527# Constructor
519528
520- DebugIfEntry(field, check=(>(0)); type=:warn, message=":\$ f is nonnegative", io=stdout)
529+ DebugIfEntry(field, check=(>(0)); type=:warn, message=":\$ f is nonnegative", io=stdout, at_init=true )
521530
522531"""
523532mutable struct DebugIfEntry{F} <: DebugAction
@@ -526,14 +535,15 @@ mutable struct DebugIfEntry{F} <: DebugAction
526535 field:: Symbol
527536 msg:: String
528537 type:: Symbol
538+ at_init:: Bool
529539 function DebugIfEntry (
530- f:: Symbol , check:: F = (> (0 )); type = :warn , message = " :\$ f nonpositive." , io:: IO = stdout
540+ f:: Symbol , check:: F = (> (0 )); type = :warn , message = " :\$ f nonpositive." , io:: IO = stdout , at_init :: Bool = true
531541 ) where {F}
532- return new {F} (io, check, f, message, type)
542+ return new {F} (io, check, f, message, type, at_init )
533543 end
534544end
535545function (d:: DebugIfEntry )(:: AbstractManoptProblem , st:: AbstractManoptSolverState , k)
536- if (k >= 0 ) && (! d. check (getfield (st, d. field)))
546+ if (k >= (d . at_init ? 0 : 1 ) ) && (! d. check (getfield (st, d. field)))
537547 format = Printf. Format (d. msg)
538548 msg = ! (' %' ∈ d. msg) ? d. msg : Printf. format (format, getfield (st, d. field))
539549 d. type === :warn && (@warn " $(msg) " )
@@ -544,7 +554,7 @@ function (d::DebugIfEntry)(::AbstractManoptProblem, st::AbstractManoptSolverStat
544554 return nothing
545555end
546556function show (io:: IO , di:: DebugIfEntry )
547- return print (io, " DebugIfEntry(:$(di. field) , $(di. check) ; type=:$(di. type) )" )
557+ return print (io, " DebugIfEntry(:$(di. field) , $(di. check) ; type=:$(di. type) , at_init= $(di . at_init) )" )
548558end
549559
550560@doc """
@@ -694,25 +704,28 @@ debug for the current iterate (stored in `get_iterate(o)`).
694704* `format="\$ prefix %s"`: format how to print the current iterate
695705* `long=false`: whether to have a long (`"current iterate:"`) or a short (`"p:"`) prefix default
696706* `prefix`: (see `long` for default) set a prefix to be printed before the iterate
707+ * `at_init=true`: whether to print also at initialization
697708"""
698709mutable struct DebugIterate <: DebugAction
699710 io:: IO
700711 format:: String
712+ at_init:: Bool
701713 function DebugIterate (;
702714 io:: IO = stdout ,
703715 long:: Bool = false ,
704716 prefix = long ? " current iterate:" : " p:" ,
705717 format = " $prefix %s" ,
718+ at_init:: Bool = false ,
706719 )
707- return new (io, format)
720+ return new (io, format, at_init )
708721 end
709722end
710723function (d:: DebugIterate )(:: AbstractManoptProblem , st:: AbstractManoptSolverState , k:: Int )
711- (k > 0 ) && Printf. format (d. io, Printf. Format (d. format), get_iterate (st))
724+ (k >= (d . at_init ? 0 : 1 ) ) && Printf. format (d. io, Printf. Format (d. format), get_iterate (st))
712725 return nothing
713726end
714727function show (io:: IO , di:: DebugIterate )
715- return print (io, " DebugIterate(; format=\" $(escape_string (di. format)) \" )" )
728+ return print (io, " DebugIterate(; format=\" $(escape_string (di. format)) \" , at_init= $(di . at_init) )" )
716729end
717730status_summary (di:: DebugIterate ) = " (:Iterate, \" $(escape_string (di. format)) \" )"
718731
@@ -1081,7 +1094,7 @@ It can also be set to `:No` to deactivate the warning, but this makes this Actio
10811094All other symbols are handled as if they were `:Always:`
10821095
10831096# Example
1084- DebugWaranIfFieldNotFinite (:Gradient)
1097+ DebugWarnIfFieldNotFinite (:Gradient)
10851098
10861099Creates a [`DebugAction`] to track whether the gradient does not get `Nan` or `Inf`.
10871100"""
@@ -1140,7 +1153,7 @@ It can also be set to `:No` to deactivate the warning, but this makes this Actio
11401153All other symbols are handled as if they were `:Always:`
11411154
11421155# Example
1143- DebugWaranIfFieldNotFinite (:Gradient)
1156+ DebugWarnIfFieldNotFinite (:Gradient)
11441157
11451158Creates a [`DebugAction`] to track whether the gradient does not get `Nan` or `Inf`.
11461159"""
@@ -1207,7 +1220,6 @@ function (d::DebugWarnIfStepsizeCollapsed)(
12071220 amp:: AbstractManoptProblem , st:: AbstractManoptSolverState , k:: Int
12081221 )
12091222 (k < 1 ) && (return nothing )
1210- s = st. stepsize
12111223 if d. status != = :No
12121224 if get_last_stepsize (amp, st, k) ≤ d. stop_when_stepsize_less
12131225 @warn " Backtracking stopped because the stepsize fell below the threshold $(d. stop_when_stepsize_less) ."
@@ -1377,6 +1389,7 @@ Note that the Shortcut symbols should all start with a capital letter.
13771389
13781390* `:Cost` creates a [`DebugCost`](@ref)
13791391* `:Change` creates a [`DebugChange`](@ref)
1392+ * `:Feasibility` creates a [`DebugFeasibility`](@ref)
13801393* `:Gradient` creates a [`DebugGradient`](@ref)
13811394* `:GradientChange` creates a [`DebugGradientChange`](@ref)
13821395* `:GradientNorm` creates a [`DebugGradientNorm`](@ref)
0 commit comments