Skip to content

Make solver signatures more consistent#113

Merged
kellertuer merged 8 commits intoJuliaManifolds:masterfrom
const-ae:make_solver_signatures_more_consistent
Mar 23, 2022
Merged

Make solver signatures more consistent#113
kellertuer merged 8 commits intoJuliaManifolds:masterfrom
const-ae:make_solver_signatures_more_consistent

Conversation

@const-ae
Copy link
Copy Markdown
Contributor

@const-ae const-ae commented Mar 3, 2022

Use generic type instead of Function for cost function in some solvers

Make the method signatures of quasi_Newton, cyclic_proximal_point, and ChambollePock consistent with other solver functions such as for example gradient_descent. A generic type instead of Function allows the methods to be called with a function like object. This pattern is for example demonstrated in the geodesic regression tutorial.

const-ae added 3 commits March 3, 2022 10:14
Make the method signatures of quasi_Newton, cyclic_proximal_point,a
and ChambollePock consistent with other solver functions such as for
example gradient_descent.
A generic type instead of `Function` allows the methods to be called
with a function like object. This pattern is for example demonstrated
in the geodesic regression tutorial.
Copy link
Copy Markdown
Member

@mateuszbaran mateuszbaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea 👍 .

@const-ae
Copy link
Copy Markdown
Contributor Author

const-ae commented Mar 3, 2022

I had some problems with the stochastic_gradient_descent. I wasn't quite sure if I needed to adapt the plan as well: https://github.com/JuliaManifolds/Manopt.jl/blob/master/src/plans/stochastic_gradient_plan.jl#L31.

There is also another inconsistency which might be a bit harder to correct:

This makes it difficult to write generic code, but I am not sure if you are willing to possibly break somebodies code to fix this.

@kellertuer
Copy link
Copy Markdown
Member

Thanks for noticing this. Parts of this package (ChambollePock especially) were written before I was aware of this nice parameter trick.

  • Please unify the step size to stepsize I must have missed that when introducing Quasi Newton.
  • I would also like to unify the Options constructors to always take the manifold as first argument, this makes it easier to introduce zero vector defaults and such.
  • For the differences in the types – does the Difference between AbstractVector{TF} and just TF still work in stochastic gradient descent?

Besides these the idea is very good, just formatter is currently failing and please make sure all tests. run fine :)

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2022

Codecov Report

Merging #113 (cbcd5b4) into master (cdaeee4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #113   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files          47       47           
  Lines        3023     3027    +4     
=======================================
+ Hits         3012     3016    +4     
  Misses         11       11           
Impacted Files Coverage Δ
src/solvers/ChambollePock.jl 100.00% <ø> (ø)
src/solvers/cyclic_proximal_point.jl 100.00% <ø> (ø)
src/solvers/stochastic_gradient_descent.jl 100.00% <ø> (ø)
src/solvers/quasi_Newton.jl 100.00% <100.00%> (ø)
src/Manopt.jl 100.00% <0.00%> (ø)
src/helpers/random.jl 100.00% <0.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@const-ae
Copy link
Copy Markdown
Contributor Author

const-ae commented Mar 4, 2022

Is there a specific version of JuliaFormatter that I need to use? I am using v0.13.7.

Because the CI test is complaining something that was adapted by my version of JuliaFormatter:
b6489f9#diff-e2c70b7aee475e1b2edbfb1ea4dd9adb8ff5a1dfcbdf72d0dc845d3aec04aa13L530

Raw Output:
src/plans/quasi_newton_plan.jl:530:-    U<:Union{
src/plans/quasi_newton_plan.jl:531:-        QuasiNewtonMatrixDirectionUpdate,QuasiNewtonLimitedMemoryDirectionUpdate{T}
src/plans/quasi_newton_plan.jl:532:-    },
src/plans/quasi_newton_plan.jl:530:+    U<:Union{QuasiNewtonMatrixDirectionUpdate,QuasiNewtonLimitedMemoryDirectionUpdate{T}}

@mateuszbaran
Copy link
Copy Markdown
Member

That's a very old version of JuliaFormatter, I'm currently using 0.22.6. Sometimes (though rarely) the formatter changes how it formats files with the same options and IIRC the CI formatter action always uses the newest version.

@kellertuer
Copy link
Copy Markdown
Member

Note also that even more importantly here, that you have to run the Julia formatter from the Manopt.jl folder since there is a config file in this folder to chose the style.

@const-ae
Copy link
Copy Markdown
Contributor Author

const-ae commented Mar 4, 2022

I must still be doing something wrong, because for me it keeps changing a bunch of files but for example sticks to the 3-line Union{ ... } thing.

I am probably again missing something obvious:
image

I tried to update JuliaFormatter by running add JuliaFormatter but that doesn't really do anything.

@mateuszbaran
Copy link
Copy Markdown
Member

You need to run for example (@v1.7) pkg> up JuliaFormatter, add doesn't update a package.

@const-ae
Copy link
Copy Markdown
Contributor Author

const-ae commented Mar 4, 2022

Thanks, I didn't know that.

I ran up JuliaFormatter, but it's still on version v0.13.10

(@v1.7) pkg> up JuliaFormatter
    Updating registry at `~/.julia/registries/General.toml`
   Installed Tokenize ──────────── v0.5.13
   Installed ArrayInterface ────── v5.0.1
   Installed GeometryBasics ────── v0.4.2
   Installed RecursiveArrayTools ─ v2.25.0
   Installed Static ────────────── v0.6.0
   Installed CategoricalArrays ─── v0.10.3
   Installed JuliaFormatter ────── v0.13.10
    Updating `~/.julia/environments/v1.7/Project.toml`
  [98e50ef6] ↑ JuliaFormatter v0.13.7 ⇒ v0.13.10
    Updating `~/.julia/environments/v1.7/Manifest.toml`
  [4fba245c] ↑ ArrayInterface v4.0.4 ⇒ v5.0.1
  [324d7699] ↑ CategoricalArrays v0.10.2 ⇒ v0.10.3
  [5c1252a2] ↑ GeometryBasics v0.4.1 ⇒ v0.4.2
  [98e50ef6] ↑ JuliaFormatter v0.13.7 ⇒ v0.13.10
  [731186ca] ↑ RecursiveArrayTools v2.24.2 ⇒ v2.25.0
  [aedffcd0] ↑ Static v0.5.6 ⇒ v0.6.0
  [0796e94c] ↓ Tokenize v0.5.21 ⇒ v0.5.13
Precompiling project...
  ✓ Tokenize
  ✓ CSTParser
  ✓ JuliaFormatter
  14 dependencies successfully precompiled in 54 seconds (197 already precompiled)
  3 dependencies precompiled but different versions are currently loaded. Restart julia to access the new versions
[ Info: We haven't cleaned this depot up for a bit, running Pkg.gc()...
      Active manifest files: 5 found
      Active artifact files: 147 found
      Active scratchspaces: 3 found
     Deleted no artifacts, repos, packages or scratchspaces


(@v1.7) pkg> status
      Status `~/.julia/environments/v1.7/Project.toml`
  [c52e3926] Atom v0.12.36
  [6e4b80f9] BenchmarkTools v1.3.1
  [5ae59095] Colors v0.12.8
  [31c24e10] Distributions v0.25.49
  [98e50ef6] JuliaFormatter v0.13.10
  [e5e0dc1b] Juno v0.8.4
  [92481ed7] LinearRegression v0.2.1
  [1cead3c2] Manifolds v0.7.5 `/Users/ahlmanne/prog/julia/Manifolds.jl#get_basis_for_rotations`
  [0fc0a36d] Manopt v0.3.18 `/Users/ahlmanne/prog/julia/Manopt.jl#additional_features_combined`
  [91a5bcdd] Plots v1.25.11
  [6f49c342] RCall v0.13.13
  [295af30f] Revise v3.3.2
  [fd094767] Suppressor v0.2.1

@kellertuer
Copy link
Copy Markdown
Member

THen there might be one of your packages constraining it to not go beyond 13.x, maybe do an up for all packages?

@mateuszbaran
Copy link
Copy Markdown
Member

If up doesn't help, you can also try (@v1.7) pkg> add JuliaFormatter@0.22 which explicitly requests version 0.22. It either works or provides an explanation why this version can't be added.

@const-ae
Copy link
Copy Markdown
Contributor Author

const-ae commented Mar 4, 2022

General up did not do the trick:

(@v1.7) pkg> up
    Updating registry at `~/.julia/registries/General.toml`
    Updating git-repo `/Users/ahlmanne/prog/julia/Manifolds.jl`
    Updating git-repo `/Users/ahlmanne/prog/julia/Manopt.jl`
   Installed Plots ─ v1.26.0
    Updating `~/.julia/environments/v1.7/Project.toml`
  [91a5bcdd] ↑ Plots v1.25.11 ⇒ v1.26.0
    Updating `~/.julia/environments/v1.7/Manifest.toml`
  [91a5bcdd] ↑ Plots v1.25.11 ⇒ v1.26.0
Precompiling project...
  2 dependencies successfully precompiled in 48 seconds (209 already precompiled)

(@v1.7) pkg> status
      Status `~/.julia/environments/v1.7/Project.toml`
  [c52e3926] Atom v0.12.36
  [6e4b80f9] BenchmarkTools v1.3.1
  [5ae59095] Colors v0.12.8
  [31c24e10] Distributions v0.25.49
  [98e50ef6] JuliaFormatter v0.13.10
  [e5e0dc1b] Juno v0.8.4
  [92481ed7] LinearRegression v0.2.1
  [1cead3c2] Manifolds v0.7.5 `/Users/ahlmanne/prog/julia/Manifolds.jl#get_basis_for_rotations`
  [0fc0a36d] Manopt v0.3.18 `/Users/ahlmanne/prog/julia/Manopt.jl#additional_features_combined`
  [91a5bcdd] Plots v1.26.0
  [6f49c342] RCall v0.13.13
  [295af30f] Revise v3.3.2
  [fd094767] Suppressor v0.2.1

But running add JuliaFormatter@0.22 gave an error that seems relevant, although I have a hard time parsing it:

(@v1.7) pkg> add JuliaFormatter@0.22
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Requires [ae029012]:
 Requires [ae029012] log:
 ├─possible versions are: 0.5.0-1.3.0 or uninstalled
 ├─restricted to versions [0.5, 1] by Manopt [0fc0a36d], leaving only versions 0.5.0-1.3.0
 │ └─Manopt [0fc0a36d] log:
 │   ├─possible versions are: 0.3.18 or uninstalled
 │   └─Manopt [0fc0a36d] is fixed to version 0.3.18
 ├─restricted by compatibility requirements with RCall [6f49c342] to versions: 0.5.2-1.3.0
 │ └─RCall [6f49c342] log:
 │   ├─possible versions are: 0.12.0-0.13.13 or uninstalled
 │   └─restricted to versions * by an explicit requirement, leaving only versions 0.12.0-0.13.13
 ├─restricted by compatibility requirements with HybridArrays [1baab800] to versions: 1.0.0-1.3.0
 │ └─HybridArrays [1baab800] log:
 │   ├─possible versions are: 0.1.0-0.4.9 or uninstalled
 │   └─restricted to versions 0.4 by Manifolds [1cead3c2], leaving only versions 0.4.0-0.4.9
 │     └─Manifolds [1cead3c2] log:
 │       ├─possible versions are: 0.7.5 or uninstalled
 │       └─Manifolds [1cead3c2] is fixed to version 0.7.5
 └─restricted by compatibility requirements with Atom [c52e3926] to versions: 0.5.0-0.5.2 — no versions left
   └─Atom [c52e3926] log:
     ├─possible versions are: 0.8.0-0.12.36 or uninstalled
     ├─restricted to versions * by an explicit requirement, leaving only versions 0.8.0-0.12.36
     └─restricted by compatibility requirements with JuliaFormatter [98e50ef6] to versions: 0.8.0-0.8.8 or uninstalled, leaving only versions: 0.8.0-0.8.8
       └─JuliaFormatter [98e50ef6] log:
         ├─possible versions are: 0.1.0-0.22.7 or uninstalled
         └─restricted to versions 0.22 by an explicit requirement, leaving only versions 0.22.0-0.22.7

@mateuszbaran
Copy link
Copy Markdown
Member

mateuszbaran commented Mar 4, 2022

Hm, newer versions are not marked as compatible with Atom for some reason: JunoLab/Atom.jl#381 . I'm afraid in such case the only quick solution is making a special Pkg environment just for JuliaFormatter, though ideally someone would just bump compat bounds in Atom.

@mateuszbaran
Copy link
Copy Markdown
Member

Here is a short quick script that should make formatting simple for you:

julia> using Pkg; Pkg.activate(; temp=true); Pkg.add("JuliaFormatter"); using JuliaFormatter; format(".")

Just run it in the folder with Manopt sources 🙂 .

@kellertuer
Copy link
Copy Markdown
Member

Ah the temp solution is also a good one. We made a short zoom session to learn about reading the package version conflicts and I convinced @const-ae to try VS code :)

@kellertuer
Copy link
Copy Markdown
Member

Just to check – I had two questions atop that could be addressed here as well.

It is no problem not to do them here – but just let me know. If you understand what I meant and want to address them here, I will leave this open until they are – if not we can merge this.

@const-ae
Copy link
Copy Markdown
Contributor Author

Sorry for the late response, I was at some workshop last week.

Just to check – I had two questions atop that could be addressed here as well.

I assume you are referring to:

  • I would also like to unify the Options constructors to always take the manifold as first argument, this makes it easier to introduce zero vector defaults and such.
  • For the differences in the types – does the Difference between AbstractVector{TF} and just TF still work in stochastic gradient descent?

I think these two question are probably better left for another PR, because I won't get to address them any time soon.

@kellertuer
Copy link
Copy Markdown
Member

Well, nearly – for the second question I would like to hear a yes, since otherwise you would break some code. I feel like it would/should work, but did not yet have the time to check.

The first point in your quote is then something for another PR, no problem.

Copy link
Copy Markdown
Member

@kellertuer kellertuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had finally the chance to check the Stochastic variants, where I feared you might have oversimplified the unification – but! All is fine 👍

We could just bump the version number here. If you want, feel free to already add yourself to the .zenodo file similar to the Manifolds.jl case; this is just a small fix but together with the check (will hopefully look closer at that soon) I think this is already justified :)

Thanks again!

@const-ae
Copy link
Copy Markdown
Contributor Author

Great. I have added myself and bumped the version number :)

@kellertuer kellertuer merged commit ef899f0 into JuliaManifolds:master Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants