Skip to content

Commit 6a8d6de

Browse files
An idea to provide Hints and Errors on Keywords (#503)
* First few steps towards handling Keywords. * Start a first list. * export keywords_accepted as an interface function. * Simplify `origins` to always be a vector. * Bump version number. --------- Co-authored-by: Mateusz Baran <mateuszbaran89@gmail.com>
1 parent a91e67a commit 6a8d6de

48 files changed

Lines changed: 583 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ The file was started with Version `0.4`.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9-
## [candidate] September 8, 2025
9+
## [0.5.22] September 09, 2025
1010

1111
### Added
1212

13+
* a `keywords_accepted(f, mode=:warn; kwargs...)` function that verifies that all keywords are accepted by a certain function.
14+
* an internal function `calls_with_kwargs(f)` to indicate which functions `f` passes `kwargs...` to.
15+
* a `KeywordsErrorMode` preference parameter to control how keywords that are not used/allowed should be treated. Values are `"none"`, `"warn"` (default), and `"error"`.
1316
* Add Distance over Gradients (RDoG) stepsize: `DistanceOverGradientsStepsize` and factory `DistanceOverGradients`, a learning‑rate‑free, curvature‑aware stepsize with `show`/`repr` and tests on Euclidean, Sphere, and Hyperbolic manifolds.
1417

18+
### Fixed
19+
* the typo in the name `AdaptiveRgularizationWithCubicsModelObjective` is fixed to `AdaptiveRegularizationWithCubicsModelObjective`.
20+
1521
## [0.5.21] September 5, 2025
1622

1723
### Added
1824

25+
* a system to track keywords, warning when unused ones are passed and a static way to explore possible keywords.
1926
* a `warm_start_factor` field to `ProximalGradientMethodBacktrackingStepsize` to allow to scale the stepsize in the backtracking procedure.
2027
* a `gradient=` keyword in several `Stepsize`s, such that one can avoid to internally avoid computing the gradient again.
2128
* used the ``gradient=` keyword in

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Manopt"
22
uuid = "0fc0a36d-df90-57f3-8f93-d78a9fc72bb5"
33
authors = ["Ronny Bergmann <manopt@ronnybergmann.net>"]
4-
version = "0.5.21"
4+
version = "0.5.22"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

docs/src/plans/index.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,30 @@ You can further activate a “Tutorial” mode by `set_parameter!(:Mode, "Tutori
5858
Manopt.is_tutorial_mode
5959
```
6060

61-
# A factory for providing manifold defaults
61+
## A factory for providing manifold defaults
6262

6363
In several cases a manifold might not yet be known at the time a (keyword) argument should be provided. Therefore, any type with a manifold default can be wrapped into a factory.
6464

6565
```@docs
6666
Manopt.ManifoldDefaultsFactory
6767
Manopt._produce_type
68+
```
69+
70+
## Keyword arguments and their verification
71+
72+
Internally `Manopt.jl` passes keywords for the (high-level) solver
73+
functions to several inner functions, e.g. to add debug or caching.
74+
Besides the documentation, one can check with the internal function [`Manopt.accepted_keywords`](@ref) which keywords a solver accepts.
75+
76+
A solver also warns, if a keyword is passed, that is not handled by the
77+
solver or any of the inner functions it calls.
78+
79+
```@docs
80+
Manopt.Keywords
81+
Manopt.accepted_keywords
82+
Manopt.ManoptKeywordError
83+
Manopt.add!
84+
Manopt.calls_with_kwargs
85+
Manopt.direct_keywords
86+
Manopt.keywords_accepted
6887
```

docs/src/solvers/adaptive-regularization-with-cubics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ Manopt.LanczosState
3232
There is a generic objective, that implements the sub problem
3333

3434
```@docs
35-
AdaptiveRagularizationWithCubicsModelObjective
35+
AdaptiveRegularizationWithCubicsModelObjective
3636
```
3737

3838
Since the sub problem is given on the tangent space, you have to provide
3939

4040
```
41-
arc_obj = AdaptiveRagularizationWithCubicsModelObjective(mho, σ)
41+
arc_obj = AdaptiveRegularizationWithCubicsModelObjective(mho, σ)
4242
sub_problem = DefaultProblem(TangentSpaceAt(M,p), arc_obj)
4343
```
4444

ext/ManoptRecursiveArrayToolsExt.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ end
8080
function alternating_gradient_descent(
8181
M::ProductManifold, ago::ManifoldAlternatingGradientObjective, p; kwargs...
8282
)
83+
Manopt.keywords_accepted(alternating_gradient_descent; kwargs...)
8384
q = copy(M, p)
8485
return alternating_gradient_descent!(M, ago, q; kwargs...)
8586
end
@@ -110,6 +111,7 @@ function alternating_gradient_descent!(
110111
retraction_method::AbstractRetractionMethod = default_retraction_method(M, typeof(p)),
111112
kwargs...,
112113
)
114+
Manopt.keywords_accepted(alternating_gradient_descent!; kwargs...)
113115
dagmo = Manopt.decorate_objective!(M, agmo; kwargs...)
114116
dmp = DefaultManoptProblem(M, dagmo)
115117
agds = AlternatingGradientDescentState(

src/Manopt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ include("solvers/conjugate_gradient_descent.jl")
194194
include("solvers/conjugate_residual.jl")
195195
include("solvers/cyclic_proximal_point.jl")
196196
include("solvers/difference_of_convex_algorithm.jl")
197-
include("solvers/difference-of-convex-proximal-point.jl")
197+
include("solvers/difference_of_convex_proximal_point.jl")
198198
include("solvers/DouglasRachford.jl")
199199
include("solvers/exact_penalty_method.jl")
200200
include("solvers/projected_gradient_method.jl")
@@ -481,6 +481,7 @@ export adaptive_regularization_with_cubics,
481481
gradient_descent!,
482482
interior_point_Newton,
483483
interior_point_Newton!,
484+
keywords_accepted,
484485
LevenbergMarquardt,
485486
LevenbergMarquardt!,
486487
mesh_adaptive_direct_search,
@@ -516,7 +517,7 @@ export solve!
516517
export ApproxHessianFiniteDifference, ApproxHessianSymmetricRankOne, ApproxHessianBFGS
517518
export update_hessian!, update_hessian_basis!
518519
export ExactPenaltyCost, ExactPenaltyGrad, AugmentedLagrangianCost, AugmentedLagrangianGrad
519-
export AdaptiveRagularizationWithCubicsModelObjective
520+
export AdaptiveRegularizationWithCubicsModelObjective
520521
export ExactPenaltyCost, ExactPenaltyGrad
521522
export SmoothingTechnique, LinearQuadraticHuber, LogarithmicSumOfExponentials
522523
#

src/documentation_glossary.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ define!(:LaTeX, :bar, (letter) -> raw"\bar" * "$(letter)")
6565
define!(:LaTeX, :big, raw"\big")
6666
define!(:LaTeX, :bigl, raw"\bigl")
6767
define!(:LaTeX, :bigr, raw"\bigr")
68+
define!(:LaTeX, :biggl, raw"\biggl")
69+
define!(:LaTeX, :biggr, raw"\biggr")
6870
define!(:LaTeX, :Big, raw"\Big")
6971
define!(:LaTeX, :Bigl, raw"\Bigl")
7072
define!(:LaTeX, :Bigr, raw"\Bigr")
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@doc """
2-
AdaptiveRagularizationWithCubicsModelObjective
2+
AdaptiveRegularizationWithCubicsModelObjective
33
44
A model for the adaptive regularization with Cubics
55
@@ -17,40 +17,40 @@ cf. Eq. (33) in [AgarwalBoumalBullinsCartis:2020](@cite)
1717
1818
# Constructors
1919
20-
AdaptiveRagularizationWithCubicsModelObjective(mho, σ=1.0)
20+
AdaptiveRegularizationWithCubicsModelObjective(mho, σ=1.0)
2121
2222
with either an [`AbstractManifoldHessianObjective`](@ref) `objective` or an decorator containing such an objective.
2323
"""
24-
mutable struct AdaptiveRagularizationWithCubicsModelObjective{
24+
mutable struct AdaptiveRegularizationWithCubicsModelObjective{
2525
E <: AbstractEvaluationType,
2626
O <: Union{ManifoldHessianObjective, AbstractDecoratedManifoldObjective},
2727
R,
2828
} <: AbstractManifoldSubObjective{E, O}
2929
objective::O
3030
σ::R
3131
end
32-
function AdaptiveRagularizationWithCubicsModelObjective(
32+
function AdaptiveRegularizationWithCubicsModelObjective(
3333
mho::O, σ::R = 1.0
3434
) where {
3535
E, O <: Union{AbstractManifoldHessianObjective{E}, AbstractDecoratedManifoldObjective{E}}, R,
3636
}
37-
return AdaptiveRagularizationWithCubicsModelObjective{E, O, R}(mho, σ)
37+
return AdaptiveRegularizationWithCubicsModelObjective{E, O, R}(mho, σ)
3838
end
3939
function set_parameter!(
40-
f::AdaptiveRagularizationWithCubicsModelObjective,
40+
f::AdaptiveRegularizationWithCubicsModelObjective,
4141
::Union{Val{:σ}, Val{:RegularizationParameter}},
4242
σ,
4343
)
4444
f.σ = σ
4545
return f
4646
end
4747

48-
get_objective(arcmo::AdaptiveRagularizationWithCubicsModelObjective) = arcmo.objective
48+
get_objective(arcmo::AdaptiveRegularizationWithCubicsModelObjective) = arcmo.objective
4949

5050
@doc """
51-
get_cost(TpM, trmo::AdaptiveRagularizationWithCubicsModelObjective, X)
51+
get_cost(TpM, trmo::AdaptiveRegularizationWithCubicsModelObjective, X)
5252
53-
Evaluate the tangent space [`AdaptiveRagularizationWithCubicsModelObjective`](@ref)
53+
Evaluate the tangent space [`AdaptiveRegularizationWithCubicsModelObjective`](@ref)
5454
5555
```math
5656
m(X) = f(p) + ⟨$(_tex(:grad)) f(p), X ⟩_p + $(_tex(:frac, "1", "2"))$(_tex(:Hess)) f(p)[X], X⟩_p
@@ -60,7 +60,7 @@ m(X) = f(p) + ⟨$(_tex(:grad)) f(p), X ⟩_p + $(_tex(:frac, "1", "2")) ⟨$(_t
6060
at `X`, cf. Eq. (33) in [AgarwalBoumalBullinsCartis:2020](@cite).
6161
"""
6262
function get_cost(
63-
TpM::TangentSpace, arcmo::AdaptiveRagularizationWithCubicsModelObjective, X
63+
TpM::TangentSpace, arcmo::AdaptiveRegularizationWithCubicsModelObjective, X
6464
)
6565
M = base_manifold(TpM)
6666
p = TpM.point
@@ -69,13 +69,13 @@ function get_cost(
6969
Y = get_objective_hessian(M, arcmo, p, X)
7070
return c + inner(M, p, G, X) + 1 / 2 * inner(M, p, Y, X) + arcmo.σ / 3 * norm(M, p, X)^3
7171
end
72-
function get_cost_function(arcmo::AdaptiveRagularizationWithCubicsModelObjective)
72+
function get_cost_function(arcmo::AdaptiveRegularizationWithCubicsModelObjective)
7373
return (TpM, X) -> get_cost(TpM, arcmo, X)
7474
end
7575
@doc """
76-
get_gradient(TpM, trmo::AdaptiveRagularizationWithCubicsModelObjective, X)
76+
get_gradient(TpM, trmo::AdaptiveRegularizationWithCubicsModelObjective, X)
7777
78-
Evaluate the gradient of the [`AdaptiveRagularizationWithCubicsModelObjective`](@ref)
78+
Evaluate the gradient of the [`AdaptiveRegularizationWithCubicsModelObjective`](@ref)
7979
8080
```math
8181
$(_tex(:grad)) m(X) = $(_tex(:grad)) f(p) + $(_tex(:Hess)) f(p)[X]
@@ -85,22 +85,22 @@ $(_tex(:grad)) m(X) = $(_tex(:grad)) f(p) + $(_tex(:Hess)) f(p)[X]
8585
at `X`, cf. Eq. (37) in [AgarwalBoumalBullinsCartis:2020](@cite).
8686
"""
8787
function get_gradient(
88-
TpM::TangentSpace, arcmo::AdaptiveRagularizationWithCubicsModelObjective, X
88+
TpM::TangentSpace, arcmo::AdaptiveRegularizationWithCubicsModelObjective, X
8989
)
9090
M = base_manifold(TpM)
9191
p = TpM.point
9292
G = get_objective_gradient(M, arcmo, p)
9393
return G + get_objective_hessian(M, arcmo, p, X) + arcmo.σ * norm(M, p, X) * X
9494
end
9595
function get_gradient!(
96-
TpM::TangentSpace, Y, arcmo::AdaptiveRagularizationWithCubicsModelObjective, X
96+
TpM::TangentSpace, Y, arcmo::AdaptiveRegularizationWithCubicsModelObjective, X
9797
)
9898
M = base_manifold(TpM)
9999
p = TpM.point
100100
get_objective_hessian!(M, Y, arcmo, p, X)
101101
Y .= Y + get_objective_gradient(M, arcmo, p) + arcmo.σ * norm(M, p, X) * X
102102
return Y
103103
end
104-
function get_gradient_function(arcmo::AdaptiveRagularizationWithCubicsModelObjective)
104+
function get_gradient_function(arcmo::AdaptiveRegularizationWithCubicsModelObjective)
105105
return (TpM, X) -> get_gradient(TpM, arcmo, X)
106106
end

src/plans/augmented_lagrangian_plan.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
_doc_AL_Cost(iter) = "$(_tex(:Cal, "L"))_{ρ^{($iter)}}(p, μ^{($iter)}, λ^{($iter)})"
2-
_doc_AL_Cost_long = raw"""
2+
_doc_AL_Cost_long = """
33
```math
4-
\mathcal L_\rho(p, μ, λ)
5-
= f(x) + $(_tex(:frac, "ρ", "2")) \biggl(
6-
\sum_{j=1}^n \Bigl( h_j(p) + $(_tex(:frac, "λ_j", "ρ")) \Bigr)^2
7-
+
8-
\sum_{i=1}^m \max\Bigl\{ 0, $(_tex(:frac, "μ_i", "ρ} + g_i(p) \Bigr\"))^2
9-
\Bigr)
4+
$(_tex(:Cal, "L"))_ρ(p, μ, λ)
5+
= f(x) + $(_tex(:frac, "ρ", "2"))$(_tex(:biggl))(
6+
$(_tex(:sum, "j=1", "n"))$(_tex(:Bigl))(
7+
h_j(p) + $(_tex(:frac, "λ_j", "ρ"))
8+
$(_tex(:Bigr)))^2
9+
+
10+
$(_tex(:sum, "i=1", "m"))$(_tex(:max))$(_tex(:set, "0, $(_tex(:frac, "μ_i", "ρ")) + g_i(p)"))^2
11+
$(_tex(:biggr)))
1012
```
1113
"""
1214

0 commit comments

Comments
 (0)