From e75cdca1ec25b669b0b60c19a2a070e1afc4f7ed Mon Sep 17 00:00:00 2001 From: benedict-96 Date: Wed, 11 Dec 2024 11:04:18 +0100 Subject: [PATCH] Removed geometric integrators from dependencies. --- Project.toml | 6 ++-- src/GeometricMachineLearning.jl | 23 +------------ src/integrator/abstract_neural_net_method.jl | 3 -- src/integrator/problem_hnn.jl | 22 ------------ src/integrator/problem_lnn.jl | 29 ---------------- src/integrator/sympnet_integrator.jl | 35 -------------------- test/runtests.jl | 4 --- 7 files changed, 4 insertions(+), 118 deletions(-) delete mode 100644 src/integrator/abstract_neural_net_method.jl delete mode 100644 src/integrator/problem_hnn.jl delete mode 100644 src/integrator/problem_lnn.jl delete mode 100644 src/integrator/sympnet_integrator.jl diff --git a/Project.toml b/Project.toml index bf098d932..897325709 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,6 @@ Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" GeometricBase = "9a0b12b7-583b-4f04-aa1f-d8551b6addc9" GeometricEquations = "c85262ba-a08a-430a-b926-d29770767bf2" -GeometricIntegrators = "dcce2d33-59f6-5b8d-9047-0defad88ae06" GeometricSolutions = "7843afe4-64f4-4df4-9231-049495c56661" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" @@ -41,7 +40,7 @@ Distances = "0.10" ForwardDiff = "0.10" GeometricBase = "0.10" GeometricEquations = "0.18" -GeometricIntegrators = "0.14" +GeometricIntegrators = "0.14.2" GeometricSolutions = "0.3.24" HDF5 = "0.16, 0.17" KernelAbstractions = "0.9" @@ -66,6 +65,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" RungeKutta = "fb486d5c-30a0-4a8a-8415-a8b4ace5a6f7" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +GeometricIntegrators = "dcce2d33-59f6-5b8d-9047-0defad88ae06" [targets] -test = ["Documenter", "ChainRulesTestUtils", "Random", "SafeTestsets", "Test", "GeometricProblems", "FiniteDifferences"] +test = ["Documenter", "ChainRulesTestUtils", "Random", "SafeTestsets", "Test", "GeometricProblems", "FiniteDifferences", "GeometricIntegrators"] diff --git a/src/GeometricMachineLearning.jl b/src/GeometricMachineLearning.jl index 17b8605b9..75ecdab86 100644 --- a/src/GeometricMachineLearning.jl +++ b/src/GeometricMachineLearning.jl @@ -5,9 +5,8 @@ module GeometricMachineLearning using ChainRulesCore using Distances using GeometricBase - using GeometricIntegrators using GeometricSolutions: GeometricSolution, EnsembleSolution, DataSeries, StateVariable - using GeometricEquations: ODEProblem, HODEProblem, ODEEnsemble, HODEEnsemble + using GeometricEquations: EnsembleProblem, ODEProblem, HODEProblem, ODEEnsemble, HODEEnsemble using KernelAbstractions using LinearAlgebra using NNlib @@ -32,7 +31,6 @@ module GeometricMachineLearning import AbstractNeuralNetworks: AbstractPullback, NetworkLoss, _compute_loss # export params, architetcure, model export dim - import GeometricIntegrators.Integrators: method, GeometricIntegrator import NNlib: σ, sigmoid, softmax import Base: iterate, eltype #import LogExpFunctions: softmax @@ -386,25 +384,6 @@ module GeometricMachineLearning export matching include("training/matching.jl") - - # INCLUDE PROBLEMS - export HNNProblem, LNNProblem - - include("integrator/problem_hnn.jl") - include("integrator/problem_lnn.jl") - - # INCLUDE INTEGRATOR - export NeuralNetMethod - export method - - include("integrator/abstract_neural_net_method.jl") - - # INCLUDE INTEGRATION METHOD - export SympNetMethod - export integrate, integrate_step! - - include("integrator/sympnet_integrator.jl") - include("reduced_system/reduced_system.jl") export HRedSys, reduction_error, projection_error, integrate_reduced_system, integrate_full_system diff --git a/src/integrator/abstract_neural_net_method.jl b/src/integrator/abstract_neural_net_method.jl deleted file mode 100644 index 77b230f2d..000000000 --- a/src/integrator/abstract_neural_net_method.jl +++ /dev/null @@ -1,3 +0,0 @@ -abstract type NeuralNetMethod <: GeometricMethod end - -method(nns::NeuralNetSolution) = throw(ArgumentError("No intgertator method associated to "*string(typeof(nn(nns))))) diff --git a/src/integrator/problem_hnn.jl b/src/integrator/problem_hnn.jl deleted file mode 100644 index a40bba907..000000000 --- a/src/integrator/problem_hnn.jl +++ /dev/null @@ -1,22 +0,0 @@ -# This file contains the functions to create the corresponding problem to hnn which is HODEProblem - -function HNNProblem(nn::NeuralNetwork{<:HamiltonianNeuralNetwork}, tspan, tstep, ics...; kwargs...) - - Hₛₚₗᵢₜ(q, p) = sum(nn([q..., p...])) - - ∇Hₛₚₗᵢₜ(q, p) = Zygote.gradient(Hₛₚₗᵢₜ, q, p) - - function v(v, t, q, p, params) - v .= ∇Hₛₚₗᵢₜ(q,p)[2] - end - - function f(f, t, q, p, params) - f .= - ∇Hₛₚₗᵢₜ(q,p)[1] - end - - function hamiltonian(t, q, p, params) - Hₛₚₗᵢₜ(q, p) - end - - HODEProblem(v, f, hamiltonian, tspan, tstep, ics...; kwargs...) -end diff --git a/src/integrator/problem_lnn.jl b/src/integrator/problem_lnn.jl deleted file mode 100644 index bf5e0ddbf..000000000 --- a/src/integrator/problem_lnn.jl +++ /dev/null @@ -1,29 +0,0 @@ -# This file contains the functions to create the corresponding problem to lnn which is LODEProblem - -function LNNProblem(nn::NeuralNetwork{<:LagrangianNeuralNetwork}, tspan::Tuple, tstep::Real, ics...; kwargs...) - - Lₛₚₗᵢₜ(q,v) = sum(nn([q...,v...])) - - ∇Lₛₚₗᵢₜ(q,v) = Zygote.gradient(Lₛₚₗᵢₜ, q, v) - - function p(p, t, q, v, params) - p .= ∇Lₛₚₗᵢₜ(q,v)[2] - end - - function f(f, t, q, v, params) - f .= ∇Lₛₚₗᵢₜ(q,v)[1] - end - - function ω(ω, t, q, v, params) - n_dim = length(q) - I = Diagonal(ones(n_dim)) - Z = zeros(n_dim,n_dim) - ω .= [Z I;-I Z] - end - - function lagrangian(t, q, v, params) - Lₛₚₗᵢₜ(q,v) - end - - LODEProblem(p, f, ω, lagrangian, tspan, tstep, ics...; kwargs...) -end diff --git a/src/integrator/sympnet_integrator.jl b/src/integrator/sympnet_integrator.jl deleted file mode 100644 index f68b84425..000000000 --- a/src/integrator/sympnet_integrator.jl +++ /dev/null @@ -1,35 +0,0 @@ - - -struct SympNetMethod{TN <: NeuralNetwork{<:SympNet}, tType <: Real} <: NeuralNetMethod - nn::TN - Δt ::tType -end - -function method(nns::NeuralNetSolution{<: NeuralNetwork{<:SympNet}}) - SympNetMethod(nn(nns), tstep(nns)) -end - - -function GeometricIntegrators.Integrators.integrate(nns::NeuralNetSolution; kwargs...) - integrate(problem(nns), method(nns); kwargs...) -end - - -function GeometricIntegrators.Integrators.integrate_step!(int::GeometricIntegrator{<:SympNetMethod, <:AbstractProblemPODE}) - - # compute how may times to compose nn () - @assert GeometricIntegrators.Integrators.method(int).Δt % GeometricIntegrators.timestep(int) == 0 - nb_comp = method(int).Δt ÷ GeometricIntegrators.timestep(int) - - _q = GeometricIntegrators.Integrators.solstep(int).q - _p = GeometricIntegrators.Integrators.solstep(int).p - - for _ in 1:nb_comp - _qp = (GeometricIntegrators.Integrators.method(int).nn)([_q...,_p...]) - _q, _p = (_qp[1:length(_q)], _qp[(1+length(_q)):end]) - end - - GeometricIntegrators.Integrators.solstep(int).q = StateVariable(_q) - GeometricIntegrators.Integrators.solstep(int).p = StateVariable(_p) - -end diff --git a/test/runtests.jl b/test/runtests.jl index da0b90b52..cd3d58342 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -55,10 +55,6 @@ using Documenter: doctest @safetestset "Batch " begin include("data/test_batch.jl") end @safetestset "Method " begin include("train!/test_method.jl") end @safetestset "Matching " begin include("data/test_matching.jl") end -# @safetestset "TrainingSet " begin include("train!/test_trainingSet.jl") end -# @safetestset "Training " begin include("train!/test_training.jl") end -@safetestset "NeuralNetSolution " begin include("train!/test_neuralnet_solution.jl") end -# @safetestset "Problem & Integrators " begin include("integrator/test_integrator.jl") end @safetestset "Test data loader for q and p data " begin include("data_loader/batch_data_loader_qp_test.jl") end @safetestset "Test mnist_utils. " begin include("data_loader/mnist_utils.jl") end