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

Check for unnecessary uses of underlying_scheme #2584

Open
benlorenz opened this issue Jul 24, 2023 · 8 comments · Fixed by #2585
Open

Check for unnecessary uses of underlying_scheme #2584

benlorenz opened this issue Jul 24, 2023 · 8 comments · Fixed by #2585
Labels
bug Something isn't working topic: schemes

Comments

@benlorenz
Copy link
Member

benlorenz commented Jul 24, 2023

Describe the bug
The show method for EllipticSurface can be extremely slow:

@doc raw"""
#Examples
```jldoctest
julia> Qt, t = polynomial_ring(QQ, :t);
julia> Qtf = fraction_field(Qt);
julia> E = EllipticCurve(Qtf, [0,0,0,0,t^5*(t-1)^2]);
julia> X3 = elliptic_surface(E, 2)
Elliptic surface
over rational field
with generic fiber
-x^3 + y^2 - t^7 + 2*t^6 - t^5
and relatively minimal model
scheme over QQ covered with 45 patches
```
"""
function Base.show(io::IO, ::MIME"text/plain", S::EllipticSurface)
io = pretty(io)
println(io, "Elliptic surface")
println(io, Indent(), "over ", Lowercase(), base_ring(S))
println(io, Dedent(), "with generic fiber")
print(io, Indent(), Lowercase(), equation(generic_fiber(S)), Dedent())
if isdefined(S, :Y)
println(io)
println(io, "and relatively minimal model")
print(io, Indent(), Lowercase(), relatively_minimal_model(S)[1], Dedent())
end
print(io, Dedent())
end

To Reproduce
Run the code from the doctest in elliptic_surface.jl:241-253:

julia> Qt, t = polynomial_ring(QQ, :t);

julia> Qtf = fraction_field(Qt);

julia> E = EllipticCurve(Qtf, [0,0,0,0,t^5*(t-1)^2]);

julia> X3 = elliptic_surface(E, 2)
Elliptic surface
  over rational field
with generic fiber
  -x^3 + y^2 - t^7 + 2*t^6 - t^5
and relatively minimal model
  scheme over QQ covered with 45 patches

The last step takes about 200 seconds including compilation time. After recreating the object it takes "only" about 60 seconds (i.e. excluding compilation time)

More precisely it happens due to show calling base_ring:

julia> Qt, t = polynomial_ring(QQ, :t);

julia> Qtf = fraction_field(Qt);

julia> E = EllipticCurve(Qtf, [0,0,0,0,t^5*(t-1)^2]);

julia> X3 = elliptic_surface(E, 2);

julia> @time base_ring(X3)
213.849025 seconds (486.34 M allocations: 23.844 GiB, 6.70% gc time, 62.53% compilation time)
Rational field

julia> X3 = elliptic_surface(E, 2);

julia> @time base_ring(X3)
 77.345964 seconds (331.51 M allocations: 13.487 GiB, 14.47% gc time, 0.03% compilation time)
Rational field

Expected behavior
If this method can take that long it should not be used in the show method and maybe not in the doctests as well. Maybe there is an easier / faster way to determine the base_ring ?

Also I don't think it is a good idea to attach an example to the docstring of Base.show, I can't find it in our documentation.

This was added in #2580, cc: @StevellM

@benlorenz benlorenz added the bug Something isn't working label Jul 24, 2023
@afkafkafk13
Copy link
Collaborator

afkafkafk13 commented Jul 24, 2023

@StevellM Thank you for adressing the problem immediately.
Your PR adresses the immediate problem of the slow doctests, but we need to keep this issue open, because base_ring for a scheme over QQ should not be so extremely slow. This is not on your plate, but should be considered in a wider scope, when we look at time and space consumption of the scheme framework.(@simonbrandhorst @HechtiDerLachs )

@simonbrandhorst
Copy link
Collaborator

@benlorenz I asked Stevell to put in the docstring of the show methods so that it is tested by our CI. Which apparently helped to find this bug. Do you see a better way to test that all the printing works as intended?

@HechtiDerLachs
Copy link
Collaborator

HechtiDerLachs commented Jul 25, 2023 via email

@fieker fieker reopened this Jul 26, 2023
@fieker
Copy link
Contributor

fieker commented Jul 26, 2023

Anne wanted to reopen this...

@fieker
Copy link
Contributor

fieker commented Jul 26, 2023

Anne @afkafkafk13 is analysing and managing this further...

@simonbrandhorst
Copy link
Collaborator

@afkafkafk13 In this special case the reason is that underlying_scheme constructs a (covered) scheme.
Depending on what the underlying_scheme is, this can be more or less expensive.
The obivous way to treat it, is to implement base_ring for the subtype of scheme that one considers.
But I am not aware of any more generic or easier solution.

@afkafkafk13
Copy link
Collaborator

For this occurrence of the problem, I fully agree with you.
I wanted this issue reopened as a marker for the following closely related tasks

  • check further uses of underlying_scheme to identify instances where this unnecessarily creates the scheme and can be avoided
  • document this pitfall, because of the high probability of getting into similar settings in most applications built on top of the schemes framework

@simonbrandhorst simonbrandhorst changed the title EllipticSurface show/base_ring method (+doctest) extremely slow Check for unnecessary uses of underlying_scheme Sep 12, 2023
@fingolfin
Copy link
Member

Regarding how to test the printing, there are multiple options:

  1. add doctests exercising the printing to the docstrings of other methods (if it makes sense, i.e., fits with the method being documented)
  2. add doctests to the manual chapter for elliptic surfaces (if it makes sense)
  3. add a regular test under test/ which exercises the printing -- it can also use a doctest, see test/Groups/group_characters.jl for an example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic: schemes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants