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

WIP, Fix some dynamic dispatch issues & new linear algebra backend #96

Merged
merged 9 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
10 changes: 8 additions & 2 deletions benchmark/CI-scripts/run_benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import Nemo

suite = []

function compute_gb(system)
function compute_gb(system, trials=7)
times = []
trials = 7
for _ in 1:trials
GC.gc()
time = @elapsed groebner(system)
Expand Down Expand Up @@ -151,6 +150,13 @@ push!(
result=compute_gb(Groebner.cyclicn(7, ordering=:degrevlex, ground=QQ))
)
)
push!(
suite,
(
problem_name="groebner, AA, QQ, noon 8",
result=compute_gb(Groebner.noonn(8, ordering=:degrevlex, ground=QQ), 3)
)
)

function multimodular_gb_problem(nbits; np=AbstractAlgebra)
R, (x1, x2, x3, x4) =
Expand Down
114 changes: 114 additions & 0 deletions experimental/dispatch.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using AbstractAlgebra, AllocCheck, BenchmarkTools

R, (x, y, z) = PolynomialRing(GF(2^31 - 1), ["x", "y", "z"], ordering=:degrevlex)

s = [x * y^2 + z, x^2 * z + y]
S = Groebner.katsuran(9, ground=GF(2^31 - 1), ordering=:degrevlex)

####################################
############ DEFAULT #############
####################################

Groebner.logging_enabled() = true
r = check_allocs(Groebner.groebner, (typeof(s),))
@info length(r) # 132
@benchmark Groebner.groebner($s)
#=
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 134.600 μs … 8.695 ms ┊ GC (min … max): 0.00% … 94.07%
Time (median): 148.800 μs ┊ GC (median): 0.00%
Time (mean ± σ): 162.509 μs ± 269.036 μs ┊ GC (mean ± σ): 5.49% ± 3.27%

▂▇█▇▆▅▇▇▆▅▄▃▃▂▁ ▁ ▁ ▂
█████████████████████▇███▇▆▇▇▇▇▆▇▇▆▇▇▅▆▆▆▆▅▆▅▆▅▆▅▅▅▆▅▅▅▅▆▄▅▅▄ █
135 μs Histogram: log(frequency) by time 276 μs <

Memory estimate: 55.59 KiB, allocs estimate: 581.
=#

@benchmark Groebner.groebner($S)
#=
BenchmarkTools.Trial: 23 samples with 1 evaluation.
Range (min … max): 197.985 ms … 304.716 ms ┊ GC (min … max): 2.03% … 3.13%
Time (median): 213.912 ms ┊ GC (median): 1.88%
Time (mean ± σ): 221.748 ms ± 24.122 ms ┊ GC (mean ± σ): 2.16% ± 0.66%

▃▃█ ▃ █
▇▁▁███▇▇▇█▁█▁▁▇▁▁▁▇▁▇▇▁▁▁▁▁▁▁▁▁▁▇▁▁▁▇▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇ ▁
198 ms Histogram: frequency by time 305 ms <

Memory estimate: 54.83 MiB, allocs estimate: 35010.
=#

####################################
############ NO LOGS #############
####################################

Groebner.logging_enabled() = false
r = check_allocs(Groebner.groebner, (typeof(s),))
@info length(r) # 66
@benchmark Groebner.groebner($s)
#=
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 35.500 μs … 7.040 ms ┊ GC (min … max): 0.00% … 95.62%
Time (median): 39.500 μs ┊ GC (median): 0.00%
Time (mean ± σ): 49.397 μs ± 201.520 μs ┊ GC (mean ± σ): 11.76% ± 2.87%

▃█▃
▂████▆▄▃▂▂▂▃▃▃▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
35.5 μs Histogram: frequency by time 96.8 μs <

Memory estimate: 42.92 KiB, allocs estimate: 308.
=#

@benchmark Groebner.groebner($S)
#=
BenchmarkTools.Trial: 22 samples with 1 evaluation.
Range (min … max): 194.198 ms … 391.634 ms ┊ GC (min … max): 3.33% … 2.89%
Time (median): 226.074 ms ┊ GC (median): 1.91%
Time (mean ± σ): 234.905 ms ± 44.547 ms ┊ GC (mean ± σ): 2.12% ± 0.67%

▃ ▃ ▃ ▃ █ ▃
█▇▇█▇█▁▇▇▁▁█▇█▁▁▁▇▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▇▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇ ▁
194 ms Histogram: frequency by time 392 ms <

Memory estimate: 54.80 MiB, allocs estimate: 34297.
=#

####################################
####### FIXING DISPATCH ##########
####################################

Groebner.logging_enabled() = false
r = check_allocs(Groebner.groebner, (typeof(s),))
@info length(r) # 37
@benchmark Groebner.groebner($s)
#=
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 30.400 μs … 10.521 ms ┊ GC (min … max): 0.00% … 98.74%
Time (median): 36.400 μs ┊ GC (median): 0.00%
Time (mean ± σ): 50.917 μs ± 272.105 μs ┊ GC (mean ± σ): 15.76% ±
2.95%

▆██▇▆▆▅▅▅▅▄▄▃▃▃▃▃▃▂▂▁▁▁▁ ▁▁▁▁▁▁ ▂
█████████████████████████████████▇▇▇▇▆█▇▇▇▆▇▆▅▅▆▆▆▆▄▅▅▆▅▅▅▄▅ █
30.4 μs Histogram: log(frequency) by time 119 μs <

Memory estimate: 41.78 KiB, allocs estimate: 290.
=#

@benchmark Groebner.groebner($S)
#=
BenchmarkTools.Trial: 27 samples with 1 evaluation.
Range (min … max): 178.942 ms … 231.366 ms ┊ GC (min … max): 2.46% … 1.76%
Time (median): 186.839 ms ┊ GC (median): 2.31%
Time (mean ± σ): 189.678 ms ± 11.078 ms ┊ GC (mean ± σ): 2.58% ± 0.78%

▃ ██ █ ▃
▇█▇▇██▁▇▇█▁▇█▇▇▁▁▁▁▇▁▁▇▁▇▁▁▁▇▁▁▁▁▇▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇ ▁
179 ms Histogram: frequency by time 231 ms <

Memory estimate: 54.80 MiB, allocs estimate: 34279.
=#

@profview_allocs Groebner.groebner(s) sample_rate = 1.0
29 changes: 23 additions & 6 deletions experimental/example-maybe-bug.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
using AbstractAlgebra # , Groebner
using AbstractAlgebra, BenchmarkTools # , Groebner

R, (t1, t2, t3, a, b, c) = PolynomialRing(QQ, ["t1", "t2", "t3", "a", "b", "c"])
R, (x1, x2, x3) = PolynomialRing(QQ, ["x1", "x2", "x3"], ordering=:degrevlex)

k = Groebner.katsuran(7)
s = [x1 * x2^2 + 2^20, x1 * x3 + 2^30 + 1, x2 * x3 + x1 - 2^40]
gb = Groebner.groebner(s, loglevel=-2, modular=:learn_and_apply)
gb2 = Groebner.groebner(s, loglevel=-2, modular=:classic_modular)
gb == gb2

gb = Groebner.groebner(k, ordering=Groebner.DegRevLex())
k = Groebner.noonn(7, ground=QQ, ordering=:degrevlex)

@time gb = Groebner.groebner(k, loglevel=0, modular=:learn_and_apply);
@time gb2 = Groebner.groebner(k, loglevel=0, modular=:classic_modular);
gb == gb2

# for k = 7
# 188.876 ms (213205 allocations: 42.44 MiB)

#! format: off
sys =[1000000*a^2*t1^2+1000000*a^2*t2^2+1000000*a^2*t3^2+1000000*b^2*t1^2+1000000*b^2*t2^2+1000000*b^2*t3^2+1000000*c^2*t1^2+1000000*c^2*t2^2+1000000*c^2*t3^2-1065102000*a^2*t1-1566200000*a^2*t2+359610000*a^2*t3-4000000*a*b*t2-1574352000*a*b*t3+4000000*a*c*t1+273640000*a*c*t3-1065102000*b^2*t1+8152000*b^2*t2+355610000*b^2*t3-1574352000*b*c*t1-273640000*b*c*t2-791462000*c^2*t1-1566200000*c^2*t2+355610000*c^2*t3+740236705137*a^2-279943961360*a*b+47071636200*a*c+1574352000*a*t1-273640000*a*t2+126292488913*b^2+837307375312*b*c+4000000*b*t1-273640000*b*t3+612513941897*c^2+4000000*c*t2-1574352000*c*t3+1000000*t1^2+1000000*t2^2+1000000*t3^2-624135247952*a-50784764200*b-283060057360*c-791462000*t1+8152000*t2+359610000*t3+165673, 1000000*a^2*t1^2+1000000*a^2*t2^2+1000000*a^2*t3^2+1000000*b^2*t1^2+1000000*b^2*t2^2+1000000*b^2*t3^2+1000000*c^2*t1^2+1000000*c^2*t2^2+1000000*c^2*t3^2-1889130000*a^2*t1-139016000*a^2*t2+357608000*a^2*t3+550492000*a*b*t3+1500376000*a*c*t3-1889130000*b^2*t1-689508000*b^2*t2+357608000*b^2*t3+550492000*b*c*t1-1500376000*b*c*t2-388754000*c^2*t1-139016000*c^2*t2+357608000*c^2*t3+740396599024*a^2+98430171568*a*b+268273230304*a*c-550492000*a*t1-1500376000*a*t2+854420557476*b^2-2714848476*b*c-1500376000*b*t3-114024022072*c^2+550492000*c*t3+1000000*t1^2+1000000*t2^2+1000000*t3^2+624263610988*a-268273230304*b+98430171568*c-388754000*t1-689508000*t2+357608000*t3-63620, 4000000*a^2*t1^2+4000000*a^2*t2^2+4000000*a^2*t3^2+4000000*b^2*t1^2+4000000*b^2*t2^2+4000000*b^2*t3^2+4000000*c^2*t1^2+4000000*c^2*t2^2+4000000*c^2*t3^2-3295636000*a^2*t1+6825304000*a^2*t2+1438448000*a^2*t3-16000000*a*b*t2+4096192000*a*b*t3+16000000*a*c*t1+4906624000*a*c*t3-3295636000*b^2*t1+2729112000*b^2*t2+1422448000*b^2*t3+4096192000*b*c*t1-4906624000*b*c*t2+1610988000*c^2*t1+6825304000*c^2*t2+1422448000*c^2*t3+2962666483625*a^2+722869290752*a*b+875649162944*a*c-4096192000*a*t1-4906624000*a*t2+513760438633*b^2-3361285532000*b*c+16000000*b*t1-4906624000*b*t3+2443184693353*c^2+16000000*c*t2+4096192000*c*t3+4000000*t1^2+4000000*t2^2+4000000*t3^2-2498705324448*a-879018458944*b+741978122752*c+1610988000*t1+2729112000*t2+1438448000*t3+440361,4000000*a^2*t1^2+4000000*a^2*t2^2+4000000*a^2*t3^2+4000000*b^2*t1^2+4000000*b^2*t2^2+4000000*b^2*t3^2+4000000*c^2*t1^2+4000000*c^2*t2^2+4000000*c^2*t3^2+3295636000*a^2*t1+6824896000*a^2*t2+1430432000*a^2*t3+4094592000*a*b*t3-4906624000*a*c*t3+3295636000*b^2*t1+2730304000*b^2*t2+1430432000*b^2*t3+4094592000*b*c*t1+4906624000*b*c*t2-1610988000*c^2*t1+6824896000*c^2*t2+1430432000*c^2*t3+2961910911797*a^2+732129427968*a*b-877323997696*a*c-4094592000*a*t1+4906624000*a*t2+516620569397*b^2+3361357491776*b*c+4906624000*b*t3+2445290017525*c^2+4094592000*c*t3+4000000*t1^2+4000000*t2^2+4000000*t3^2+2499114213824*a+877323997696*b+732129427968*c-1610988000*t1+2730304000*t2+1430432000*t3-324875, 1000000*a^2*t1^2+1000000*a^2*t2^2+1000000*a^2*t3^2+1000000*b^2*t1^2+1000000*b^2*t2^2+1000000*b^2*t3^2+1000000*c^2*t1^2+1000000*c^2*t2^2+1000000*c^2*t3^2+1889602000*a^2*t1-138926000*a^2*t2+359604000*a^2*t3-4000000*a*b*t2+550036000*a*b*t3+4000000*a*c*t1-1500228000*a*c*t3+1889602000*b^2*t1-688962000*b^2*t2+355604000*b^2*t3+550036000*b*c*t1+1500228000*b*c*t2+389374000*c^2*t1-138926000*c^2*t2+355604000*c^2*t3+740903906549*a^2+99175424872*a*b-265964790856*a*c-550036000*a*t1+1500228000*a*t2+854030749541*b^2+2874521168*b*c+4000000*b*t1+1500228000*b*t3-114557203083*c^2+4000000*c*t2+550036000*c*t3+1000000*t1^2+1000000*t2^2+1000000*t3^2-623884900400*a+270522742856*b+97519648872*c+389374000*t1-688962000*t2+359604000*t3+55909, 250000*a^2*t1^2+250000*a^2*t2^2+250000*a^2*t3^2+250000*b^2*t1^2+250000*b^2*t2^2+250000*b^2*t3^2+250000*c^2*t1^2+250000*c^2*t2^2+250000*c^2*t3^2+266341000*a^2*t1-391502000*a^2*t2+89402000*a^2*t3-393620000*a*b*t3-68228000*a*c*t3+266341000*b^2*t1+2118000*b^2*t2+89402000*b^2*t3-393620000*b*c*t1+68228000*b*c*t2+198113000*c^2*t1-391502000*c^2*t2+89402000*c^2*t3+184958257568*a^2-70380830480*a*b-12199439312*a*c+393620000*a*t1+68228000*a*t2+31688927488*b^2-209385275032*b*c+68228000*b*t3+153269490056*c^2-393620000*c*t3+250000*t1^2+250000*t2^2+250000*t3^2+156251491928*a+12199439312*b-70380830480*c+198113000*t1+2118000*t2+89402000*t3+159976]
R,(t1,t2,t3,a,b,c) = PolynomialRing(QQ, ["t1","t2","t3","a", "b", "c"])
sys = [1000000*a^2*t1^2+1000000*a^2*t2^2+1000000*a^2*t3^2+1000000*b^2*t1^2+1000000*b^2*t2^2+1000000*b^2*t3^2+1000000*c^2*t1^2+1000000*c^2*t2^2+1000000*c^2*t3^2-1065102000*a^2*t1-1566200000*a^2*t2+359610000*a^2*t3-4000000*a*b*t2-1574352000*a*b*t3+4000000*a*c*t1+273640000*a*c*t3-1065102000*b^2*t1+8152000*b^2*t2+355610000*b^2*t3-1574352000*b*c*t1-273640000*b*c*t2-791462000*c^2*t1-1566200000*c^2*t2+355610000*c^2*t3+740236705137*a^2-279943961360*a*b+47071636200*a*c+1574352000*a*t1-273640000*a*t2+126292488913*b^2+837307375312*b*c+4000000*b*t1-273640000*b*t3+612513941897*c^2+4000000*c*t2-1574352000*c*t3+1000000*t1^2+1000000*t2^2+1000000*t3^2-624135247952*a-50784764200*b-283060057360*c-791462000*t1+8152000*t2+359610000*t3+165673, 1000000*a^2*t1^2+1000000*a^2*t2^2+1000000*a^2*t3^2+1000000*b^2*t1^2+1000000*b^2*t2^2+1000000*b^2*t3^2+1000000*c^2*t1^2+1000000*c^2*t2^2+1000000*c^2*t3^2-1889130000*a^2*t1-139016000*a^2*t2+357608000*a^2*t3+550492000*a*b*t3+1500376000*a*c*t3-1889130000*b^2*t1-689508000*b^2*t2+357608000*b^2*t3+550492000*b*c*t1-1500376000*b*c*t2-388754000*c^2*t1-139016000*c^2*t2+357608000*c^2*t3+740396599024*a^2+98430171568*a*b+268273230304*a*c-550492000*a*t1-1500376000*a*t2+854420557476*b^2-2714848476*b*c-1500376000*b*t3-114024022072*c^2+550492000*c*t3+1000000*t1^2+1000000*t2^2+1000000*t3^2+624263610988*a-268273230304*b+98430171568*c-388754000*t1-689508000*t2+357608000*t3-63620, 4000000*a^2*t1^2+4000000*a^2*t2^2+4000000*a^2*t3^2+4000000*b^2*t1^2+4000000*b^2*t2^2+4000000*b^2*t3^2+4000000*c^2*t1^2+4000000*c^2*t2^2+4000000*c^2*t3^2-3295636000*a^2*t1+6825304000*a^2*t2+1438448000*a^2*t3-16000000*a*b*t2+4096192000*a*b*t3+16000000*a*c*t1+4906624000*a*c*t3-3295636000*b^2*t1+2729112000*b^2*t2+1422448000*b^2*t3+4096192000*b*c*t1-4906624000*b*c*t2+1610988000*c^2*t1+6825304000*c^2*t2+1422448000*c^2*t3+2962666483625*a^2+722869290752*a*b+875649162944*a*c-4096192000*a*t1-4906624000*a*t2+513760438633*b^2-3361285532000*b*c+16000000*b*t1-4906624000*b*t3+2443184693353*c^2+16000000*c*t2+4096192000*c*t3+4000000*t1^2+4000000*t2^2+4000000*t3^2-2498705324448*a-879018458944*b+741978122752*c+1610988000*t1+2729112000*t2+1438448000*t3+440361,4000000*a^2*t1^2+4000000*a^2*t2^2+4000000*a^2*t3^2+4000000*b^2*t1^2+4000000*b^2*t2^2+4000000*b^2*t3^2+4000000*c^2*t1^2+4000000*c^2*t2^2+4000000*c^2*t3^2+3295636000*a^2*t1+6824896000*a^2*t2+1430432000*a^2*t3+4094592000*a*b*t3-4906624000*a*c*t3+3295636000*b^2*t1+2730304000*b^2*t2+1430432000*b^2*t3+4094592000*b*c*t1+4906624000*b*c*t2-1610988000*c^2*t1+6824896000*c^2*t2+1430432000*c^2*t3+2961910911797*a^2+732129427968*a*b-877323997696*a*c-4094592000*a*t1+4906624000*a*t2+516620569397*b^2+3361357491776*b*c+4906624000*b*t3+2445290017525*c^2+4094592000*c*t3+4000000*t1^2+4000000*t2^2+4000000*t3^2+2499114213824*a+877323997696*b+732129427968*c-1610988000*t1+2730304000*t2+1430432000*t3-324875, 1000000*a^2*t1^2+1000000*a^2*t2^2+1000000*a^2*t3^2+1000000*b^2*t1^2+1000000*b^2*t2^2+1000000*b^2*t3^2+1000000*c^2*t1^2+1000000*c^2*t2^2+1000000*c^2*t3^2+1889602000*a^2*t1-138926000*a^2*t2+359604000*a^2*t3-4000000*a*b*t2+550036000*a*b*t3+4000000*a*c*t1-1500228000*a*c*t3+1889602000*b^2*t1-688962000*b^2*t2+355604000*b^2*t3+550036000*b*c*t1+1500228000*b*c*t2+389374000*c^2*t1-138926000*c^2*t2+355604000*c^2*t3+740903906549*a^2+99175424872*a*b-265964790856*a*c-550036000*a*t1+1500228000*a*t2+854030749541*b^2+2874521168*b*c+4000000*b*t1+1500228000*b*t3-114557203083*c^2+4000000*c*t2+550036000*c*t3+1000000*t1^2+1000000*t2^2+1000000*t3^2-623884900400*a+270522742856*b+97519648872*c+389374000*t1-688962000*t2+359604000*t3+55909, 250000*a^2*t1^2+250000*a^2*t2^2+250000*a^2*t3^2+250000*b^2*t1^2+250000*b^2*t2^2+250000*b^2*t3^2+250000*c^2*t1^2+250000*c^2*t2^2+250000*c^2*t3^2+266341000*a^2*t1-391502000*a^2*t2+89402000*a^2*t3-393620000*a*b*t3-68228000*a*c*t3+266341000*b^2*t1+2118000*b^2*t2+89402000*b^2*t3-393620000*b*c*t1+68228000*b*c*t2+198113000*c^2*t1-391502000*c^2*t2+89402000*c^2*t3+184958257568*a^2-70380830480*a*b-12199439312*a*c+393620000*a*t1+68228000*a*t2+31688927488*b^2-209385275032*b*c+68228000*b*t3+153269490056*c^2-393620000*c*t3+250000*t1^2+250000*t2^2+250000*t3^2+156251491928*a+12199439312*b-70380830480*c+198113000*t1+2118000*t2+89402000*t3+159976]
#! format: on

gb = Groebner.groebner(sys, ordering=Groebner.DegRevLex(), statistics=:timings);
Groebner.performance_counters_enabled() = true
@time gb = Groebner.groebner(
sys,
ordering=Groebner.DegRevLex(),
statistics=:timings,
modular=:learn_and_apply
);

Groebner.isgroebner(gb, ordering=Groebner.DegRevLex())
Groebner.normalform(gb, sys, ordering=Groebner.DegRevLex())
Expand Down
Loading
Loading