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

Replace Val-types in cholesky[!] #41640

Merged
merged 8 commits into from
Dec 14, 2021
Merged

Replace Val-types in cholesky[!] #41640

merged 8 commits into from
Dec 14, 2021

Conversation

dkarrasch
Copy link
Member

@dkarrasch dkarrasch commented Jul 19, 2021

Extends #40623 to cholesky. Addresses #40623 (comment).

@dkarrasch dkarrasch added the linear algebra Linear algebra label Jul 19, 2021
stdlib/LinearAlgebra/src/cholesky.jl Outdated Show resolved Hide resolved
@@ -132,7 +132,7 @@ end

#pivoted upper Cholesky
if eltya != BigFloat
cpapd = cholesky(apdh, Val(true))
cpapd = cholesky(apdh, RowMaximum())
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should maintain some tests that use cholesky(apdh, Val(true)) to ensure that the deprecations work and to avoid accidental breakage of later?

Suggested change
cpapd = cholesky(apdh, RowMaximum())
cpapd = cholesky(apdh, RowMaximum())

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes the tests fail, see my first commit and its fix in the second.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, we don't have that for lu and qr. Seeing the few "fix breakage" PRs in downstream packages made me feel bad about deprecating these functions, though there were no objections against that. Maybe we shouldn't officially deprecate them but only redirect them and list those functions in the deprecated.jl list?

Copy link
Member Author

Choose a reason for hiding this comment

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

Surprisingly, in my local build I don't even get a deprecation warning.

Copy link
Member

Choose a reason for hiding this comment

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

That makes the tests fail

I see. So I guess CI runs with --depwarn=error?

Surprisingly, in my local build I don't even get a deprecation warning.

Do you run with --depwarn=yes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just start the locally built Julia and then using LinearAlgebra; A = rand(3,3); A = A'A; cholesky(A, Val(true)). So, I wasn't referring to the tests, just to "normal usage".

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but the default now is --depwarn=no so users won't see these unless you set --depwarn=yes on startup.

@thchr
Copy link
Contributor

thchr commented Jul 20, 2021

Just for the record: the changes in #40623 did break code elsewhere, e.g., JuliaArrays/StaticArrays.jl#931.
I suppose it's really kind of borderline because the breakage arose due to the introduction of ambiguity errors - but it definitely had an impact.

I think the ambiguity errors there arose from changing certain ::Union{Val{false}, Val{true}} signatures to (deprecated) methods with distinct Val{false} and Val{true} dispatch - but I'm not 100% sure (e.g., qr didn't have any Union dispatch before #40623, but still broke in StaticArrays after #40623).

AFAICT, there's no conversion of Union-style dispatches here - so it it might not be a problem - but I just wanted to note this effect in any case.

@dkarrasch
Copy link
Member Author

Sorry to hear that. I'll run tests this time.

@nanosoldier runtests(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

@dkarrasch
Copy link
Member Author

AFAICT, there are 3 packages affected: GLM, NiceNumbers and SciMLBase. I wonder what happens if we don't export the "old signature". For instance, this works:

module MyTest

struct MyType end
export f
f(x, ::MyType) = 3x
@deprecate f(x, ::Val{false}=Val(false)) f(x, MyType()) false
end
using .MyTest
f(2, Val(false))
f(2, MyTest.MyType())

I wonder if that prevents ambiguity errors.

@dkarrasch
Copy link
Member Author

@nanosoldier runtests(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

@dkarrasch
Copy link
Member Author

@nanosoldier runtests(["GLM", "NiceNumbers", "SciMLBase"], vs = ":master")

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

@dkarrasch
Copy link
Member Author

This PR makes GLM.jl (for a reason that I don't understand) and NiceNumbers.jl (which would be easy to fix) fail, but not SciMLBase.jl (which had ambiguity issues initially) anymore.

positive semi-definite matrix `A`. This is the return type of [`cholesky(_, Val(true))`](@ref),
positive semi-definite matrix `A`. This is the return type of [`cholesky(_, ::RowMaximum)`](@ref),
Copy link
Member Author

Choose a reason for hiding this comment

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

The current cross reference doesn't work properly and links to the cholesky-docstring from SparseArrays.jl. Is this type-based reference better or how do I specify which docstring to link to? @fredrikekre

@palday
Copy link
Contributor

palday commented Aug 4, 2021

@dkarrasch MixedModels did get test breakage from the qr change -- in part because of the change in warnings we got, which broke the tests checking the warnings. A quick look at the report from GLM suggests that this is also part of the problem.

cf. JuliaStats/MixedModels.jl#547

@dkarrasch
Copy link
Member Author

Hm, could be that it's better not to deprecate, but to redirect then? I wasn't sure about that, but nobody told me to not deprecate. OTOH, some people seem to like these type-based changes. So, how do we proceed with maximum benefit and least annoyance?

@palday
Copy link
Contributor

palday commented Aug 6, 2021

Ultimately, deprecation is just re-direction with a warning and it would be good to be consistent with qr. So I would say deprecate, but do PRs against GLM.jl and other packages with a wrapper like

@static if VERSION < v"1.8.0-DEV.xxxx" 
    pivoted_cholesky(A; kwargs...) = cholesky(A, Val(true); kwargs...)
else
    pivoted_cholesky(A; kwargs...) = cholesky(A, RowNorm(); kwargs...)
end

and replace all the calls in that package as appropriate. Then those tests don't break, users aren't annoyed by deprecation warnings coming from package code, and inlining should prevent any performance hit.

(If qr didn't already deprecate, then I would say just redirect and let inlining handle everything because a lot of users just wanted "pivoting" without thinking about the pivoting strategy.)

@dkarrasch
Copy link
Member Author

@nanosoldier runtests(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

@palday
Copy link
Contributor

palday commented Dec 9, 2021

@dkarrasch I think the GLM failure is the one mentioned above.

@dkarrasch
Copy link
Member Author

@dkarrasch I think the GLM failure is the one mentioned above.

I know, which is why GLM.jl already has a patch PR. 😉

@dkarrasch
Copy link
Member Author

How do we proceed here? There are three PRs in the pipeline to update failing packages (out of those that currently pass their test suite). Shall we merge now, update (if necessary) the specific VERSION number in the accompanying PRs and see how it goes? There's one last question about how to fix the currently broken reference to the pivoted cholesky docstring. @fredrikekre Could you please take a look when you find the time?

@palday
Copy link
Contributor

palday commented Dec 13, 2021

@dkarrasch Cool, thanks. I'll review the GLM.jl PR as soon as this one here lands (so tag me as a reviewer when that happens). 😄

@dkarrasch
Copy link
Member Author

@nanosoldier runtests(["CMAEvolutionStrategy", "CryptoDashApp", "DCISolver", "DataFrames", "GraphQLClient", "Hecke", "ITensors", "JetPackWaveFD", "OptimKit", "PolaronPathIntegrals", "QuantumTomography", "TreeParzen"], vs = ":master")

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

@dkarrasch dkarrasch merged commit 490d78c into master Dec 14, 2021
@dkarrasch dkarrasch deleted the dk/cholesky branch December 14, 2021 14:55
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants