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

Introducing ProximalCore, cleaning up code #137

Merged
merged 27 commits into from
Feb 14, 2022

Conversation

lostella
Copy link
Member

@lostella lostella commented Feb 10, 2022

This is a large-ish revision of the code base, with some breaking changes.

Goal

  1. Offload the "definition" of the first-order API to a separate package ProximalCore, to improve decoupling with the API users, like ProximalAlgorithms.
  2. Take the opportunity to do a pass over the package and simplify or improve the existing code wherever possible.

At the time of writing, more than 600 lines (~7% of the lines), and more than 32k characters (~12%) are gone from src/: this does not tell everything about how "simple" code is, but at least suggests an improvement in readability and maintainability.

Summary of the changes

  • Removed the ProximableFunction abstract type.
  • Removed custom printing for all types: this was very complex and unreadable in case an object gets printed as part of some larger structure. There is some discussion in Improve pretty printing #85 on how to do this better, I think for now it is fine to go with the "do nothing" option until we settle on a better one.
  • Added dependency on ProximalCore, containing the API definition of the first-order primitives (prox and gradient) among other basic tooling. This move allows other packages (e.g. ProximalAlgorithms) to depend on the API only (ProximalCore) rather than its implementation for specific function types (ProximalOperators). This decouples the packages a bit, and addresses Lightweight “base” package with core definitions #131.
  • Updated the documentation to display docstrings from ProximalCore for prox, prox!, gradient, and gradient!.
  • Turned the predicates is_xyz into properties of a function's type. This allows to specialize code, based on whether a function is e.g. convex or not, or quadratic or not, at compile time. This required:
    • A small change to the LeastSquares types (type now has a parameter indicating whether the function is convex)
    • A small change to the SqrNormL2 type (was allowed not being strongly convex, but it didn't really make sense)
  • Cleaned up code, removing extremely verbose type constraints in favor of readability. (Not sure I'm done here, I'll do another pass before this can be merged.)
  • Removed code for SqrDistL2 entirely: now it is based on MoreauEnvelope since it's a special case of it.
  • Corrected docstrings to conform with official guidelines.
  • Renamed file TotalVariation1D.jl into totalVariation1D.jl for consistency.
  • Bumped Julia version from 1.0 to 1.4, added test-specific environment, and hyphenated version specifiers in dependencies.
  • Bumped Documenter version.
  • Bumped package version to 0.15.0.

Tests

Tests are unchanged, so changes are non-breaking from a "functional" standpoint.

Benchmarks

I ran benchmarks locally and no significant performance degradation was detected: identical allocations, noisy ups and downs in the runtime for some cases. (I think some benchmark cases are too small to be reliable for runtime measurements.)

TODO

  • Finish cleaning up the code from verbose type annotations and constraints (see summary below).
    • Epicompose
    • IndBox
    • IndGraph
    • IndPolyhedral
    • LeastSquares
    • NormL1
    • NuclearNorm
    • Quadratic
    • SqrHingeLoss
    • SqrNormL2
    • SumLargest
  • Run benchmarks locally to spot any performance regression. (Benchmarks run on GitHub, but not on a dedicated CPU so they're not always reliable.)
  • Explicitly mention and link ProximalCore in the documentation.

@codecov
Copy link

codecov bot commented Feb 10, 2022

Codecov Report

Merging #137 (5deba8f) into master (c46f6de) will increase coverage by 8.31%.
The diff coverage is 96.87%.

❗ Current head 5deba8f differs from pull request most recent head 6722b00. Consider uploading reports for the commit 6722b00 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #137      +/-   ##
==========================================
+ Coverage   87.57%   95.88%   +8.31%     
==========================================
  Files          79       79              
  Lines        2583     2382     -201     
==========================================
+ Hits         2262     2284      +22     
+ Misses        321       98     -223     
Impacted Files Coverage Δ
src/functions/sumLargest.jl 50.00% <33.33%> (+21.42%) ⬆️
src/functions/totalVariation1D.jl 85.50% <62.50%> (ø)
src/calculus/translate.jl 84.00% <69.23%> (+1.24%) ⬆️
src/functions/logisticLoss.jl 90.00% <75.00%> (+0.52%) ⬆️
src/functions/sqrHingeLoss.jl 75.75% <76.92%> (+11.05%) ⬆️
src/functions/indFree.jl 77.77% <81.25%> (+15.87%) ⬆️
src/functions/leastSquaresDirect.jl 93.42% <86.36%> (+4.08%) ⬆️
src/functions/linear.jl 94.11% <87.50%> (+15.17%) ⬆️
src/functions/crossEntropy.jl 88.88% <91.66%> (+11.11%) ⬆️
src/calculus/sum.jl 96.00% <94.11%> (+13.85%) ⬆️
... and 64 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c46f6de...6722b00. Read the comment docs.

@lostella lostella force-pushed the move-to-proximal-core branch from 6197471 to 6597b0b Compare February 13, 2022 08:03
@lostella lostella marked this pull request as ready for review February 14, 2022 12:51
@lostella lostella merged commit b86a53d into JuliaFirstOrder:master Feb 14, 2022
@lostella lostella deleted the move-to-proximal-core branch February 14, 2022 21:48
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.

1 participant