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

Upgrade to ManifoldDiff v0.4 #771

Merged
merged 14 commits into from
Nov 27, 2024
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Minimum Julia version is now 1.10 (the LTS which replaced 1.6)
* The dependency ManifoldDiff.jl has been upgraded from v0.3 to v0.4, to bring compatibility with DifferentiationInterface.jl.

## [0.10.7] – 2024-11-16

Expand Down
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Graphs = "1.4"
HybridArrays = "0.4"
Kronecker = "0.4, 0.5"
LinearAlgebra = "1.6"
ManifoldDiff = "0.3.13"
ManifoldDiff = "0.4.0"
ManifoldsBase = "0.15.18"
Markdown = "1.6"
MatrixEquations = "2.2"
Expand All @@ -74,6 +74,7 @@ StatsBase = "0.32, 0.33, 0.34"
julia = "1.10"

[extras]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
BoundaryValueDiffEq = "764a87c0-6b3e-53db-9096-fe964310641d"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
Expand All @@ -98,4 +99,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"

[targets]
test = ["Test", "BoundaryValueDiffEq", "Colors", "DiffEqCallbacks", "Distributions", "DoubleFloats", "FiniteDifferences", "Gtk", "HybridArrays", "ImageIO", "ImageMagick", "OrdinaryDiffEq", "NLsolve", "Plots", "PythonPlot", "Quaternions", "QuartzImageIO", "RecipesBase", "RecursiveArrayTools"]
test = ["Test", "ADTypes", "BoundaryValueDiffEq", "Colors", "DiffEqCallbacks", "Distributions", "DoubleFloats", "FiniteDifferences", "Gtk", "HybridArrays", "ImageIO", "ImageMagick", "OrdinaryDiffEq", "NLsolve", "Plots", "PythonPlot", "Quaternions", "QuartzImageIO", "RecipesBase", "RecursiveArrayTools"]
3 changes: 2 additions & 1 deletion src/Manifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ using ManifoldDiff:
_jacobian!,
set_default_differential_backend!
using ManifoldDiff:
AbstractDiffBackend,
AbstractRiemannianDiffBackend,
CoprojectorOntoVector,
ExplicitEmbeddedBackend,
Expand All @@ -365,6 +364,8 @@ using Statistics
using StatsBase
using StatsBase: AbstractWeights

const AbstractDiffBackend = Any # TODO: remove

include("utils.jl")

include("manifold_fallbacks.jl")
Expand Down
13 changes: 7 additions & 6 deletions test/differentiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ function ManifoldDiff.gradient(::AbstractManifold, f, p, ::TestRiemannianBackend
return collect(1.0:length(p))
end

using ADTypes
using FiniteDifferences
using LinearAlgebra: Diagonal, dot

@testset "Differentiation backend" begin
fd51 = ManifoldDiff.FiniteDifferencesBackend()
fd51 = AutoFiniteDifferences(central_fdm(5, 1))
@testset "default_differential_backend" begin
@test default_differential_backend() isa ManifoldDiff.FiniteDifferencesBackend
@test default_differential_backend() isa AutoFiniteDifferences

@test length(fd51.method.grid) == 5
@test length(fd51.fdm.grid) == 5
# check method order
@test typeof(fd51.method).parameters[2] == 1
fd71 = ManifoldDiff.FiniteDifferencesBackend(central_fdm(7, 1))
@test typeof(fd51.fdm).parameters[2] == 1
fd71 = AutoFiniteDifferences(central_fdm(7, 1))
@test set_default_differential_backend!(fd71) == fd71
@test default_differential_backend() == fd71
end
Expand Down Expand Up @@ -105,7 +106,7 @@ rb_onb_default = TangentDiffBackend(
DefaultOrthonormalBasis(),
)

rb_onb_fd51 = TangentDiffBackend(ManifoldDiff.FiniteDifferencesBackend())
rb_onb_fd51 = TangentDiffBackend(AutoFiniteDifferences(central_fdm(5, 1)))

rb_onb_default2 = TangentDiffBackend(
default_differential_backend();
Expand Down
2 changes: 1 addition & 1 deletion test/manifolds/symplectic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ using ManifoldDiff
analytical_grad_f(p) = (1 / 2) * (p * J * p * J + p * p')

p_grad = points[1]
fd_diff = RiemannianProjectionBackend(ManifoldDiff.FiniteDifferencesBackend())
fd_diff = RiemannianProjectionBackend(AutoFiniteDifferences(central_fdm(5, 1)))

@test isapprox(
Manifolds.gradient(Sp_6, test_f, p_grad, fd_diff),
Expand Down
2 changes: 1 addition & 1 deletion test/manifolds/symplecticstiefel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ end
return Q_grad * p * (euc_grad_f') * Q_grad * p + euc_grad_f * p' * p
end
p_grad = convert(Array{Float64}, points[1])
fd_diff = RiemannianProjectionBackend(ManifoldDiff.FiniteDifferencesBackend())
fd_diff = RiemannianProjectionBackend(AutoFiniteDifferences(central_fdm(5, 1)))

@test isapprox(
Manifolds.gradient(M, test_f, p_grad, fd_diff),
Expand Down
6 changes: 3 additions & 3 deletions test/metric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using ManifoldsBase: TraitList
import ManifoldsBase: default_retraction_method
import Manifolds: solve_exp_ode
using Manifolds: InducedBasis, connection, get_chart_index, induced_basis, mean!, median!
using ManifoldDiff: FiniteDifferencesBackend
using ADTypes
include("header.jl")

struct TestEuclidean{N} <: AbstractManifold{ℝ} end
Expand Down Expand Up @@ -372,7 +372,7 @@ Manifolds.inner(::MetricManifold{ℝ,<:AbstractManifold{ℝ},Issue539Metric}, p,
@test gaussian_curvature(M, p, B_chart_p) ≈ 0 atol = 1e-6
@test einstein_tensor(M, p, B_chart_p) ≈ zeros(n, n) atol = 1e-6

fdm = FiniteDifferencesBackend(forward_fdm(2, 1))
fdm = AutoFiniteDifferences(forward_fdm(2, 1))
@test christoffel_symbols_first(M, p, B_chart_p; backend=fdm) ≈ zeros(n, n, n) atol =
1e-6
@test christoffel_symbols_second(M, p, B_chart_p; backend=fdm) ≈ zeros(n, n, n) atol =
Expand All @@ -384,7 +384,7 @@ Manifolds.inner(::MetricManifold{ℝ,<:AbstractManifold{ℝ},Issue539Metric}, p,
@test gaussian_curvature(M, p, B_chart_p; backend=fdm) ≈ 0 atol = 1e-6
@test einstein_tensor(M, p, B_chart_p; backend=fdm) ≈ zeros(n, n) atol = 1e-6

fd_diff = FiniteDifferencesBackend()
fd_diff = AutoFiniteDifferences(central_fdm(5, 1))
@test christoffel_symbols_first(M, p, B_chart_p; backend=fd_diff) ≈
zeros(n, n, n) atol = 1e-6
@test christoffel_symbols_second(M, p, B_chart_p; backend=fd_diff) ≈
Expand Down
Loading