From 0b7e3be626559dab1d7cddbf637888debc6326ed Mon Sep 17 00:00:00 2001 From: benedict-96 Date: Sun, 16 Aug 2026 16:52:37 +0200 Subject: [PATCH 1/2] Update the README example to the 0.5 optimizer interface The example in the README predates the move of the optimizer machinery to GeometricOptimizers and no longer runs: - `Optimizer(AdamOptimizer(), g_nn)` -> `Optimizer(Adam(type), g_nn; step_size = 1e-3)`. The method comes first and the learning rate is no longer part of the method. `Adam` is constructed with the element type of the parameters, so it reuses the `type` already defined a few lines above. - `Iterate_Sympnet` -> `iterate`. `Iterate_Sympnet` is not defined in the package any more, so this line raised an `UndefVarError` as written. Also note in the prose where the optimizer methods now come from, since the README is where a reader first meets them. Verified by running the changed calls against the package on Julia 1.12 (`Optimizer(Adam(Float32), nn; step_size = 1e-3)`, a short training run and `iterate(nn, ics; n_points = 200)`) with a synthetic q/p dataset. The CUDA and `Plots` lines of the example are unchanged and were not exercised. Drafted by Claude Opus 5 (Claude Code) at benedict-96's request; the diff is documentation only. Co-Authored-By: Claude Opus 5 --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ea6bfecb..909b5c4f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ At its core every neural network comprises three components: a neural network ar Traditionally, physical properties have been encoded into the loss function (PINN approach), but in `GeometricMachineLearning.jl` this is exclusively done through the architectures and the optimizers of the neural network, thus giving theoretical guarantees that these properties are actually preserved. +The optimizer methods themselves (`GradientMethod`, `MomentumMethod`, `Adam`, and the caches, global sections and retractions that go with them) come from [`GeometricOptimizers.jl`](https://github.com/JuliaGNI/GeometricOptimizers.jl) and are re-exported here; `GeometricMachineLearning.jl` supplies the part that is specific to neural networks, i.e. walking the parameter tree and the manifold layers. + Using the package is very straightforward and is very flexible with respect to the device `(CPU, CUDA, Metal, ...)` and the type `(Float16, Float32, Float64, ...)` you want to use. The following is a simple example to learn a SympNet on data coming from a pendulum: ```julia using GeometricMachineLearning @@ -41,8 +43,8 @@ backend = CUDABackend() # initialize the network (i.e. the parameters of the network) g_nn = NeuralNetwork(gsympnet, backend, type) -# call the optimizer -g_opt = Optimizer(AdamOptimizer(), g_nn) +# call the optimizer: the method comes first, the step size is given separately +g_opt = Optimizer(Adam(type), g_nn; step_size = 1e-3) const nepochs = 300 const batch_size = 100 @@ -53,7 +55,7 @@ g_loss_array = g_opt(g_nn, dl, Batch(batch_size), nepochs) # plot the result ics = (q=qp_data.q[:,1], p=qp_data.p[:,1]) const steps_to_plot = 200 -g_trajectory = Iterate_Sympnet(g_nn, ics; n_points = steps_to_plot) +g_trajectory = iterate(g_nn, ics; n_points = steps_to_plot) p2 = plot(qp_data.q'[1:steps_to_plot], qp_data.p'[1:steps_to_plot], label="training data") plot!(p2, g_trajectory.q', g_trajectory.p', label="G Sympnet") ``` From d7533441aa14c526c0c8ec3d029cc6e1751195c9 Mon Sep 17 00:00:00 2001 From: benedict-96 Date: Sun, 16 Aug 2026 16:58:06 +0200 Subject: [PATCH 2/2] README: plot the example with Makie instead of Plots.jl The docs and tutorials use CairoMakie throughout; the README example was the last place still reaching for Plots.jl. Co-Authored-By: Claude Opus 5 --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 909b5c4f..8c4ee98e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Using the package is very straightforward and is very flexible with respect to t ```julia using GeometricMachineLearning using CUDA # Metal -using Plots +using CairoMakie include("scripts/pendulum.jl") @@ -56,8 +56,12 @@ g_loss_array = g_opt(g_nn, dl, Batch(batch_size), nepochs) ics = (q=qp_data.q[:,1], p=qp_data.p[:,1]) const steps_to_plot = 200 g_trajectory = iterate(g_nn, ics; n_points = steps_to_plot) -p2 = plot(qp_data.q'[1:steps_to_plot], qp_data.p'[1:steps_to_plot], label="training data") -plot!(p2, g_trajectory.q', g_trajectory.p', label="G Sympnet") +fig = Figure() +ax = Axis(fig[1, 1]; xlabel = L"q", ylabel = L"p") +lines!(ax, qp_data.q[1, 1:steps_to_plot], qp_data.p[1, 1:steps_to_plot], label = "training data") +lines!(ax, g_trajectory.q[1, :], g_trajectory.p[1, :], label = L"$G$-SympNet") +axislegend(ax) +fig ``` More examples like this can be found in the docs.