Skip to content

Commit

Permalink
run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Demin committed Aug 21, 2024
1 parent 1ecfeac commit 27ed611
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 18 deletions.
8 changes: 4 additions & 4 deletions benchmark/CI-scripts/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ function compare()
0, "insignificant"
elseif (1 + MAX_DEVIATION) * m1 < m2
fail = true
2, "**slower**"
2, "slower❌"
elseif m1 > (1 + MAX_DEVIATION) * m2
1, "**faster**"
1, "faster✅"
else
0, "insignificant"
end
Expand All @@ -144,9 +144,9 @@ function compare()
label_nightly = mean(nightly)
indicator = if label_master < label_nightly
fail = true
2, "**worse**"
2, "worse❌"
elseif label_master > label_nightly
1, "**better**"
1, "better✅"
else
0, "same"
end
Expand Down
2 changes: 1 addition & 1 deletion src/f4/learn_apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function f4_reduction_apply!(

flag = linalg_main!(matrix, basis, params, trace, linalg=LinearAlgebra(:apply, :sparse))
if !flag
@log :warn "In apply, in linear algebra, some of the matrix rows reduced to zero."
@log :info "In apply, in linear algebra, some of the matrix rows reduced to zero."
return false, false
end

Expand Down
17 changes: 10 additions & 7 deletions src/groebner/learn_apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ function groebner_apply_batch0!(
flag, gb_batch = _groebner_apply_batch1!(wrapped_trace, ir_batch, options)
!flag && return (flag, batch)
result_ir = map(
f -> io_convert_ir_to_polynomials(ir_batch[1][1], batch[1], f..., options),
gb_batch
i -> io_convert_ir_to_polynomials(ir_batch[i][1], batch[i], gb_batch[i]..., options),
1:length(gb_batch)
)
flag, result_ir
end
Expand Down Expand Up @@ -204,18 +204,21 @@ function __groebner_apply1!(
!flag && return flag, monoms, coeffs

flag, gb_monoms2, gb_coeffs2 = groebner_apply2!(trace, params)
if !flag
trace.nfail += 1
empty!(trace.matrix_sorted_columns)
end

gb_monoms, gb_coeffs = io_convert_internal_to_ir(ring, gb_monoms2, gb_coeffs2, params)
flag, gb_monoms, gb_coeffs
end

function groebner_apply2!(trace, params)
flag, gb_monoms, gb_coeffs = _groebner_apply2!(trace, params)
!flag && return (flag, gb_monoms, gb_coeffs)
if !flag
# Recover trace
@log :info "Trace might be corrupted. Recovering..."
trace.nfail += 1
empty!(trace.matrix_sorted_columns)
trace.buf_basis = basis_deepcopy(trace.input_basis)
return flag, gb_monoms, gb_coeffs
end
flag, gb_monoms, gb_coeffs
end

Expand Down
2 changes: 1 addition & 1 deletion src/input_output/input_output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function ir_pack_coeffs(batch::NTuple{N, T}) where {N, T}
new_ring = PolyRing(ring.nvars, ring.ord, ch)
monoms = batch[1][2]
coeffs = Vector{Vector{CompositeNumber{N, UInt64}}}(undef, length(monoms))
@assert allequal(el -> el[2], batch)
@assert allequal(map(el -> el[2], batch))
for i in 1:length(batch[1][2])
coeffs[i] = Vector{CompositeNumber{N, UInt64}}(undef, length(batch[1][2][i]))
for j in 1:length(batch[1][2][i])
Expand Down
27 changes: 25 additions & 2 deletions test/learn_and_apply/apply_in_batches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Primes
# Simple sanity checks
ks = map(GF, Primes.nextprimes(2^30, 40))

@test_broken false # broken for internal_ordering=:lex

R, (x, y) =
polynomial_ring(AbstractAlgebra.ZZ, ["x", "y"], internal_ordering=:degrevlex)
sys_qq = [44x^2 + x + 2^50, y^10 - 10 * y^5 - 99]
Expand Down Expand Up @@ -77,3 +75,28 @@ import Primes
test_learn_apply(kat, ps2)
test_learn_apply(cyc, ps2)
end

@testset "learn & apply low level, in batches" begin
ring0 = Groebner.PolyRing(2, Groebner.DegLex(), 5)
ring1 = Groebner.PolyRing(2, Groebner.DegLex(), 7)
ring2 = Groebner.PolyRing(2, Groebner.DegLex(), 11)
ring3 = Groebner.PolyRing(2, Groebner.DegLex(), 13)
ring4 = Groebner.PolyRing(2, Groebner.DegLex(), 17)
trace, (gb0...) = Groebner.groebner_learn(ring0, [[[0,0], [1, 1]]], [[1, -1]])
@test gb0 == ([[[1,1], [0, 0]]], [[1, 4]])
flag1, (gb1...) = Groebner.groebner_apply!(trace, ring1, [[[0,0], [1, 1]]], [[1, -1]])
flag2, (gb2...) = Groebner.groebner_apply!(trace, ring2, [[[1,1], [0, 0]]], [[-1, 1]])
flag3, (gb3...) = Groebner.groebner_apply!(trace, ring3, [[[0,0], [0, 1], [1, 1]]], [[1, 0, -1]])
flag4, (gb4...) = Groebner.groebner_apply!(trace, ring4, [[[0,0], [1, 1]]], [[1, -1]])
@test flag1 && flag2 && flag3 && flag4
@test gb1 == ([[[1,1], [0, 0]]], [[1, 6]])
@test gb2 == ([[[1,1], [0, 0]]], [[1, 10]])
@test gb3 == ([[[1,1], [0, 0]]], [[1, 12]])
@test gb4 == ([[[1,1], [0, 0]]], [[1, 16]])

flag1, (gb1...) = Groebner.groebner_apply!(trace, ring1, [[[0,0]]], [[1]])
flag2, (gb2...) = Groebner.groebner_apply!(trace, ring2, [[[1,1], [0, 0]]], [[-1, 0]])
flag3, (gb3...) = Groebner.groebner_apply!(trace, ring3, [[[0,0], [0, 1], [1, 1]]], [[1, 0, -1]])
flag4, (gb4...) = Groebner.groebner_apply!(trace, ring4, [[[0,0], [1, 1]]], [[1, -1]])
@test !flag1 && !flag2 && flag3 && flag4
end
34 changes: 31 additions & 3 deletions test/learn_and_apply/learn_and_apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ end
flag4, gb4 = Groebner.groebner_apply!(trace, sys_mod_p2)
flag5, gb5 = Groebner.groebner_apply!(trace, sys_mod_p2)

flag6, gb6 = Groebner.groebner_apply!(trace, sys_mod_p)
@test flag6 && gb6 == gb2

trace, gb = Groebner.groebner_learn(sys_mod_p2)
flag, gb = Groebner.groebner_apply!(trace, sys_mod_p2)
@test flag
Expand Down Expand Up @@ -412,9 +415,34 @@ end
@test_throws DomainError Groebner.groebner_learn(ring, [], [])
@test ([[[0, 0]]], [[1]]) == Groebner.groebner_learn(ring, [[[0, 0]]], [[1]])[2:3]
@test ([[[1, 1]]], [[1]]) == Groebner.groebner_learn(ring, [[[1, 1]]], [[2]])[2:3]
ring = Groebner.PolyRing(2, Groebner.Lex(), 2^30 + 3)
@test ([[[0, 0]]], [[1]]) == Groebner.groebner_learn(ring, [[[0, 0]]], [[1]])[2:3]
@test ([[[1, 1]]], [[1]]) == Groebner.groebner_learn(ring, [[[1, 1]]], [[2]])[2:3]
trace, _ = Groebner.groebner_learn(ring, [[[1, 1]]], [[2]])
@test (true, [[[1, 1]]], [[1]]) == Groebner.groebner_apply!(trace, ring, [[[1, 1]]], [[2]])
# ring = Groebner.PolyRing(2, Groebner.Lex(), 2^30 + 3)
# @test ([[[0, 0]]], [[1]]) == Groebner.groebner_learn(ring, [[[0, 0]]], [[1]])[2:3]
# @test ([[[1, 1]]], [[1]]) == Groebner.groebner_learn(ring, [[[1, 1]]], [[2]])[2:3]

ring0 = Groebner.PolyRing(2, Groebner.DegLex(), 5)
ring1 = Groebner.PolyRing(2, Groebner.DegLex(), 7)
ring2 = Groebner.PolyRing(2, Groebner.DegLex(), 11)
ring3 = Groebner.PolyRing(2, Groebner.DegLex(), 13)
ring4 = Groebner.PolyRing(2, Groebner.DegLex(), 17)
trace, (gb0...) = Groebner.groebner_learn(ring0, [[[0,0], [1, 1]]], [[1, -1]])
@test gb0 == ([[[1,1], [0, 0]]], [[1, 4]])
flag1, (gb1...) = Groebner.groebner_apply!(trace, ring1, [[[0,0], [1, 1]]], [[1, -1]])
flag2, (gb2...) = Groebner.groebner_apply!(trace, ring2, [[[1,1], [0, 0]]], [[-1, 1]])
flag3, (gb3...) = Groebner.groebner_apply!(trace, ring3, [[[0,0], [0, 1], [1, 1]]], [[1, 0, -1]])
flag4, (gb4...) = Groebner.groebner_apply!(trace, ring4, [[[0,0], [1, 1]]], [[1, -1]])
@test flag1 && flag2 && flag3 && flag4
@test gb1 == ([[[1,1], [0, 0]]], [[1, 6]])
@test gb2 == ([[[1,1], [0, 0]]], [[1, 10]])
@test gb3 == ([[[1,1], [0, 0]]], [[1, 12]])
@test gb4 == ([[[1,1], [0, 0]]], [[1, 16]])

flag1, (gb1...) = Groebner.groebner_apply!(trace, ring1, [[[0,0]]], [[1]])
flag2, (gb2...) = Groebner.groebner_apply!(trace, ring2, [[[1,1], [0, 0]]], [[-1, 0]])
flag3, (gb3...) = Groebner.groebner_apply!(trace, ring3, [[[0,0], [0, 1], [1, 1]]], [[1, 0, -1]])
flag4, (gb4...) = Groebner.groebner_apply!(trace, ring4, [[[0,0], [1, 1]]], [[1, -1]])
@test !flag1 && !flag2 && flag3 && flag4

sys = Groebner.Examples.cyclicn(5, k=GF(2^40 + 15))
ring = Groebner.PolyRing(5, Groebner.DegRevLex(), 2^40 + 15)
Expand Down

0 comments on commit 27ed611

Please sign in to comment.