From f9c74c74c4cb2daf6d63f33c757401f1621a8498 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Mon, 28 Oct 2024 13:30:01 +0100 Subject: [PATCH 1/5] fead(breaking): update to Manopt 0.5 --- Project.toml | 6 +++--- src/manopt/bounded_norm_update_rule.jl | 4 ++-- src/projected_to.jl | 4 ++-- test/manopt/bounded_norm_update_rule_tests.jl | 6 +++--- test/projection/projected_to_setuptests.jl | 8 ++++---- test/projection/projected_to_tests.jl | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Project.toml b/Project.toml index 8dd68a0..cf90836 100644 --- a/Project.toml +++ b/Project.toml @@ -26,10 +26,10 @@ StaticTools = "86c06d3c-3f03-46de-9781-57580aa96d0a" StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" [compat] -BayesBase = "1.3" +BayesBase = "1.5.0" Bumper = "0.6" Distributions = "0.25" -ExponentialFamily = "1.5" +ExponentialFamily = "1.6" ExponentialFamilyManifolds = "1.2" FastCholesky = "1.3" FillArrays = "1" @@ -38,7 +38,7 @@ LinearAlgebra = "1.10" LoopVectorization = "0.12" Manifolds = "0.9" ManifoldsBase = "0.15" -Manopt = "0.4" +Manopt = "0.5" Random = "1.10" RecursiveArrayTools = "3.2" StableRNGs = "1" diff --git a/src/manopt/bounded_norm_update_rule.jl b/src/manopt/bounded_norm_update_rule.jl index b30d6d2..0f83e9b 100644 --- a/src/manopt/bounded_norm_update_rule.jl +++ b/src/manopt/bounded_norm_update_rule.jl @@ -3,7 +3,7 @@ import Manopt using LoopVectorization """ - BoundedNormUpdateRule(limit; direction = IdentityUpdateRule()) + BoundedNormUpdateRule(limit; direction = Manopt.IdentityUpdateRule()) A `DirectionUpdateRule` is a direction rule that constrains the norm of the direction to a specified limit. @@ -23,7 +23,7 @@ struct BoundedNormUpdateRule{L,D} <: Manopt.DirectionUpdateRule direction::D end -function BoundedNormUpdateRule(limit; direction = IdentityUpdateRule()) +function BoundedNormUpdateRule(limit; direction = Manopt.IdentityUpdateRule()) return BoundedNormUpdateRule(limit, direction) end diff --git a/src/projected_to.jl b/src/projected_to.jl index 875493b..8870384 100644 --- a/src/projected_to.jl +++ b/src/projected_to.jl @@ -108,7 +108,7 @@ The following parameters are available: * `strategy = ExponentialFamilyProjection.DefaultStrategy()`: The strategy to use to compute the gradients. * `niterations = 100`: The number of iterations for the optimization procedure. * `tolerance = 1e-6`: The tolerance for the norm of the gradient. -* `stepsize = ConstantStepsize(0.1)`: The stepsize for the optimization procedure. Accepts stepsizes from `Manopt.jl`. +* `stepsize = ConstantLength(0.1)`: The stepsize for the optimization procedure. Accepts stepsizes from `Manopt.jl`. * `seed`: Optional; Seed for the `rng` * `rng`: Optional; Random number generator * `direction = BoundedNormUpdateRule(static(1.0)`: Direction update rule. Accepts `Manopt.DirectionUpdateRule` from `Manopt.jl`. @@ -117,7 +117,7 @@ Base.@kwdef struct ProjectionParameters{S,I,T,P,D,N,U} strategy::S = DefaultStrategy() niterations::I = 100 tolerance::T = 1e-6 - stepsize::P = ConstantStepsize(0.1) + stepsize::P = ConstantLength(0.1) seed::D = 42 rng::N = StableRNG(seed) direction::U = BoundedNormUpdateRule(static(1.0)) diff --git a/test/manopt/bounded_norm_update_rule_tests.jl b/test/manopt/bounded_norm_update_rule_tests.jl index b0e6904..46e9b93 100644 --- a/test/manopt/bounded_norm_update_rule_tests.jl +++ b/test/manopt/bounded_norm_update_rule_tests.jl @@ -13,10 +13,10 @@ # returning the unbounded gradient as the first argument and a collection of bounded gradients for testing. function apply_update_rules_for_test(p, limit) cpa = DefaultManoptProblem(M, ManifoldGradientObjective(f, grad_f)) - gst = GradientDescentState(M, zero(p)) + gst = GradientDescentState(M; p=zero(p)) Manopt.set_iterate!(gst, M, p) - _, X = IdentityUpdateRule()(cpa, gst, 1) + _, X = Manopt.IdentityUpdateRule()(cpa, gst, 1) X_identity = copy(X) _, X = BoundedNormUpdateRule(limit)(cpa, gst, 1) @@ -79,7 +79,7 @@ @testset "JET tests" begin for limit in (1, 1.0, 1.0f0), p in (zeros(Float64, 3), zeros(Float32, 3)) cpa = DefaultManoptProblem(M, ManifoldGradientObjective(f, grad_f)) - gst = GradientDescentState(M, zero(p)) + gst = GradientDescentState(M; p=zero(p)) @test_opt BoundedNormUpdateRule(limit)(cpa, gst, 1) @test_opt BoundedNormUpdateRule(static(limit))(cpa, gst, 1) @test_opt BoundedNormUpdateRule( diff --git a/test/projection/projected_to_setuptests.jl b/test/projection/projected_to_setuptests.jl index 9fb71f4..07e6e23 100644 --- a/test/projection/projected_to_setuptests.jl +++ b/test/projection/projected_to_setuptests.jl @@ -93,7 +93,7 @@ function test_convergence_nsamples( nsamples_tolerance = _convergence_nsamples_default_tolerance(distribution), nsamples_niterations = _convergence_nsamples_default_niterations(distribution), nsamples_rng = StableRNG(42), - nsamples_stepsize = ConstantStepsize(0.1), + nsamples_stepsize = ConstantLength(0.1), nsamples_required_accuracy = 1e-1, kwargs..., ) @@ -168,7 +168,7 @@ function test_convergence_niterations( niterations_tolerance = _convergence_niterations_default_tolerance(distribution), niterations_nsamples = _convergence_niterations_default_nsamples(distribution), niterations_rng = StableRNG(42), - niterations_stepsize = ConstantStepsize(0.1), + niterations_stepsize = ConstantLength(0.1), niterations_required_accuracy = 1e-1, kwargs..., ) @@ -219,7 +219,7 @@ function test_convergence_niterations_mle( niterations_tolerance = _convergence_niterations_default_tolerance(distribution), niterations_nsamples = _convergence_niterations_default_nsamples(distribution), niterations_rng = StableRNG(42), - niterations_stepsize = ConstantStepsize(0.1), + niterations_stepsize = ConstantLength(0.1), niterations_required_accuracy = 1e-1, kwargs..., ) @@ -268,7 +268,7 @@ function test_convergence_nsamples_mle( nsamples_tolerance = _convergence_nsamples_default_tolerance(distribution), nsamples_niterations = _convergence_nsamples_default_niterations(distribution), nsamples_rng = StableRNG(42), - nsamples_stepsize = ConstantStepsize(0.1), + nsamples_stepsize = ConstantLength(0.1), nsamples_required_accuracy = 1e-1, kwargs..., ) diff --git a/test/projection/projected_to_tests.jl b/test/projection/projected_to_tests.jl index cfd01b3..2633a7e 100644 --- a/test/projection/projected_to_tests.jl +++ b/test/projection/projected_to_tests.jl @@ -54,7 +54,7 @@ @test typeof(get_stopping_criterion(defaultparams)) == typeof(get_stopping_criterion(parameters_from_creation)) # These should pass as soon as `Manopt` implements `==` - @test_broken getstepsize(defaultparams) == getstepsize(parameters_from_creation) + @test getstepsize(defaultparams) == getstepsize(parameters_from_creation) @test_broken get_stopping_criterion(defaultparams) == get_stopping_criterion(parameters_from_creation) @@ -518,7 +518,7 @@ end nothing, ) initialpoint = rand(manifold) - direction = MomentumGradient(manifold, initialpoint) + direction = Manopt.MomentumGradientRule(manifold; p=initialpoint) momentum_parameters = ProjectionParameters(direction = direction, niterations = 1000, tolerance = 1e-8) @@ -529,7 +529,7 @@ end @test approximated isa MvNormalMeanCovariance @test kldivergence(approximated, true_dist) < 0.01 - @test projection.parameters.direction isa MomentumGradient + @test projection.parameters.direction isa Manopt.MomentumGradientRule end @testitem "MomentumGradient direction update rule on samples" begin @@ -547,7 +547,7 @@ end ) initialpoint = rand(rng, manifold) - direction = MomentumGradient(manifold, initialpoint) + direction = Manopt.MomentumGradientRule(manifold; p=initialpoint) momentum_parameters = ProjectionParameters(direction = direction, niterations = 1000, tolerance = 1e-8) @@ -557,5 +557,5 @@ end @test approximated isa MvNormalMeanCovariance @test kldivergence(approximated, true_dist) < 0.01 # Ensure good approximation - @test projection.parameters.direction isa MomentumGradient + @test projection.parameters.direction isa Manopt.MomentumGradientRule end From 1dcb1723e21ba15b98c731f9157c91078d6d7e53 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Thu, 21 Nov 2024 13:55:52 +0100 Subject: [PATCH 2/5] fix: update to new api --- test/projection/projected_to_tests.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/projection/projected_to_tests.jl b/test/projection/projected_to_tests.jl index 2633a7e..7819c75 100644 --- a/test/projection/projected_to_tests.jl +++ b/test/projection/projected_to_tests.jl @@ -547,7 +547,7 @@ end ) initialpoint = rand(rng, manifold) - direction = Manopt.MomentumGradientRule(manifold; p=initialpoint) + direction = MomentumGradient(p=initialpoint) momentum_parameters = ProjectionParameters(direction = direction, niterations = 1000, tolerance = 1e-8) @@ -557,5 +557,6 @@ end @test approximated isa MvNormalMeanCovariance @test kldivergence(approximated, true_dist) < 0.01 # Ensure good approximation - @test projection.parameters.direction isa Manopt.MomentumGradientRule + @show typeof(projection.parameters.direction) + @test projection.parameters.direction isa Manopt.ManifoldDefaultsFactory end From a633eb4c35484b58ea9deb4cec399aeb7811adb3 Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Thu, 21 Nov 2024 13:57:28 +0100 Subject: [PATCH 3/5] test: update to new Manopt API --- test/projection/projected_to_tests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/projection/projected_to_tests.jl b/test/projection/projected_to_tests.jl index 7819c75..a1f7767 100644 --- a/test/projection/projected_to_tests.jl +++ b/test/projection/projected_to_tests.jl @@ -518,7 +518,7 @@ end nothing, ) initialpoint = rand(manifold) - direction = Manopt.MomentumGradientRule(manifold; p=initialpoint) + direction = MomentumGradient(p=initialpoint) momentum_parameters = ProjectionParameters(direction = direction, niterations = 1000, tolerance = 1e-8) @@ -529,7 +529,7 @@ end @test approximated isa MvNormalMeanCovariance @test kldivergence(approximated, true_dist) < 0.01 - @test projection.parameters.direction isa Manopt.MomentumGradientRule + @test projection.parameters.direction isa Manopt.ManifoldDefaultsFactory end @testitem "MomentumGradient direction update rule on samples" begin From 94ef63bb4db8347f704a56c6a6a0e80e66b1ff7a Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Thu, 21 Nov 2024 14:02:43 +0100 Subject: [PATCH 4/5] ci: run CI on julia 1.11 --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1197594..0d6b30f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -23,7 +23,7 @@ jobs: fail-fast: false matrix: version: - - '1.10' + - '1.11' os: - ubuntu-latest arch: From 10cfbd9cfe6310e93f489daf776a702460d3343a Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Thu, 21 Nov 2024 17:24:24 +0100 Subject: [PATCH 5/5] test: remove @show --- test/projection/projected_to_tests.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/projection/projected_to_tests.jl b/test/projection/projected_to_tests.jl index a1f7767..87579d9 100644 --- a/test/projection/projected_to_tests.jl +++ b/test/projection/projected_to_tests.jl @@ -557,6 +557,5 @@ end @test approximated isa MvNormalMeanCovariance @test kldivergence(approximated, true_dist) < 0.01 # Ensure good approximation - @show typeof(projection.parameters.direction) @test projection.parameters.direction isa Manopt.ManifoldDefaultsFactory end