sumiya11 / Groebner.jl

Groebner bases in (almost) pure Julia
https://sumiya11.github.io/Groebner.jl/
GNU General Public License v2.0
66 stars 13 forks source link

Allow tracking several Statistics during the computation #4

Closed sumiya11 closed 1 month ago

sumiya11 commented 2 years ago

This and #8 are top priority

aabouman commented 2 years ago

I don't have much knowledge of the f4 algorithm but do you have a recommendation for a quick way to measure progress? I just want to get a feel for when the problem becomes infeasible.

sumiya11 commented 2 years ago

Do you mean some kind of progress bar ?

aabouman commented 2 years ago

Yeah it doesn't need to be that advanced but just somewhere I can print an iterator or something of the like to understand the progress

sumiya11 commented 2 years ago

That's a cool idea! Ive never heard anyone doing that with Groebner bases before; I'll investigate what can be done 😄

sumiya11 commented 2 years ago

@aabouman The simplest solution would be to compute the basis incrementally, starting from the basis of [f1,f2], then [f1,f2,f3], and so on:

groebner([f1...fn]) = groebner(groebner(groebner([f1, f2]), f3)... fn)

Something like

julia> function iterativegroebner(system)
           gb = [system[1]]
           for i in 2:length(system)
               push!(gb, system[i])
               @info "$i/$(length(system)) step"
               @time gb = Groebner.groebner(gb)
           end
           gb
       end

Which produces

# system noon with 8 polynomials
julia> system = Groebner.change_ordering(Groebner.noonn(8), :degrevlex)

julia> iterativegroebner(system);
[ Info: 2/8 step
  0.000816 seconds (2.15 k allocations: 940.922 KiB)
[ Info: 3/8 step
  0.002860 seconds (14.05 k allocations: 2.932 MiB)
[ Info: 4/8 step
  0.016764 seconds (64.50 k allocations: 8.450 MiB)
[ Info: 5/8 step
  0.085297 seconds (262.17 k allocations: 30.699 MiB)
[ Info: 6/8 step
  0.543022 seconds (1.18 M allocations: 151.607 MiB, 5.17% gc time)
# e.g., stop somewhere here, when the time goes up
[ Info: 7/8 step
  3.378745 seconds (4.55 M allocations: 644.938 MiB, 10.05% gc time)
[ Info: 8/8 step
 13.478732 seconds (13.13 M allocations: 1.904 GiB, 5.44% gc time)

This will be slower in general, but allows you to stop earlier, when the time on the current step becomes too large

julia> @time groebner(system);
  9.691641 seconds (11.32 M allocations: 1.458 GiB, 6.46% gc time)

julia> iterativegroebner(system) == groebner(system)
  true

Other than that, F4 is not very suitable for tracking the progress, since the computation times can (and usually will) blow up unexpectedly. I will think about it though

aabouman commented 2 years ago

That's funny I had hacked together something similar where I just added additional polynomials bit by bit. Thanks so much for your help!

sumiya11 commented 1 month ago

I could not implement tracking statistics and printing useful info in the terminal in a way that would not clutter the code of F4. At the moment I decided I care about readability more. I will close this issue.