Move OSQP to a weak dependency (package extension) - #165
Open
hakkelt wants to merge 3 commits into
Open
Conversation
Loading OSQP and its dependencies accounted for ~2s of ProximalOperators' load time, yet OSQP is only used by IndPolyhedralOSQP (the default backend of IndPolyhedral). This implements "Option 2" from JuliaFirstOrder#163: OSQP becomes a weak dependency and the solver-backed implementation lives in the new extension ProximalOperatorsOSQPExt. - Project.toml: OSQP moved from [deps] to [weakdeps]; register ProximalOperatorsOSQPExt = "OSQP". - src/functions/indPolyhedralOSQP.jl: keeps the IndPolyhedralOSQP type (now parametric on the model type), the function-value and prox_naive methods, and a stub constructor that raises an informative error when OSQP is not loaded. An explicit inner constructor suppresses the auto-generated 4-arg outer constructor that would otherwise shadow the extension's (l, A, xmin, xmax) method. - ext/ProximalOperatorsOSQPExt.jl: OSQP-backed constructors and prox!. - Users must `using OSQP` before constructing IndPolyhedral(...; solver=:osqp); documented in the IndPolyhedral docstring. - test: add OSQP to the test env and `using OSQP` in test_indPolyhedral.jl. - Bump version to 0.18.0 (minor breaking API change). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X9Xuox9ELuSiEbxwJq84vJ
Contributor
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
…_naive to ext Follow-up to the previous commit: - Delete src/functions/indPolyhedralOSQP.jl. The IndPolyhedralOSQP struct, its inner constructor, the is_proximable trait and the not-loaded stub constructor are now inlined into src/functions/indPolyhedral.jl, so the whole non-OSQP surface of IndPolyhedral lives in one file. - Move the function evaluation `(f::IndPolyhedralOSQP)(x)` and `prox_naive` into ext/ProximalOperatorsOSQPExt.jl. The extension now holds everything that operates on an IndPolyhedralOSQP instance; the main package only defines the type and the error stub. No behavioural change: an instance can only exist once OSQP is loaded, so moving its methods to the extension is transparent. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X9Xuox9ELuSiEbxwJq84vJ
hakkelt
marked this pull request as ready for review
September 8, 2026 09:54
Leave the version at 0.17.0; the maintainers can decide the release number. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X9Xuox9ELuSiEbxwJq84vJ
This was referenced Sep 8, 2026
lostella
self-requested a review
September 8, 2026 20:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements "Option 2" from #163.
Goal
OSQP and its dependencies add ~2s to
using ProximalOperators, but OSQP isonly used by
IndPolyhedralOSQP— the default backend ofIndPolyhedral.This makes OSQP optional so only users who need that operator pay the cost.
Changes
[deps]to[weakdeps], registered as the extensionProximalOperatorsOSQPExt.src/functions/indPolyhedralOSQP.jlis removed. The main package keeps onlythe
IndPolyhedralOSQPtype and a stub constructor that raises aninformative error when OSQP is not loaded; both are now inlined into
src/functions/indPolyhedral.jl.prox!,the function evaluation and
prox_naive— i.e. every method operating on anIndPolyhedralOSQPinstance.IndPolyhedraldocstring documents the new requirement.Effect
Constructing
IndPolyhedral(...)/IndPolyhedral(...; solver=:osqp)nowrequires
using OSQPfirst; without it, a clear error is thrown instead ofa
MethodError. This is a minor breaking API change. All other operators areunaffected and load without OSQP.
The version is left at 0.17.0 for the maintainers to set.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X9Xuox9ELuSiEbxwJq84vJ