Skip to content

Commit 0b29f18

Browse files
committed
update project.toml
1 parent d3054f5 commit 0b29f18

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GraphTensorNetworks"
22
uuid = "0978c8c2-34f6-49c7-9826-ea2cc20dabd2"
33
authors = ["GiggleLiu <[email protected]> and contributors"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

src/graph_polynomials.jl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,39 @@ end
6464

6565
function graph_polynomial(gp::GraphProblem, ::Val{:finitefield}; usecuda=false,
6666
maxorder=max_size(gp; usecuda=usecuda), max_iter=100)
67-
TI = Int32 # Int 32 is faster
67+
return map(Polynomial, big_integer_solve(T->_polynomial_single(gp, T; usecuda=usecuda, maxorder=maxorder), Int32, max_iter))
68+
end
69+
70+
function big_integer_solve(f, ::Type{TI}, max_iter::Int=100) where TI
6871
N = typemax(TI)
69-
YS = fill(Any[], (fill(bondsize(gp), length(getiyv(gp.code)))...,))
70-
local res, respre
72+
local res, respre, YS
7173
for k = 1:max_iter
7274
N = prevprime(N-TI(1))
73-
@debug "iteration $k, computing on GP$(N) ..."
75+
@debug "iteration $k, computing on GP($(N)) ..."
7476
T = Mods.Mod{N,TI}
75-
rk = _polynomial_single(gp, T; usecuda=usecuda, maxorder=maxorder)
76-
push!.(YS, rk)
77+
rk = f(T)
7778
if max_iter==1
78-
return map(Polynomial, map(x->BigInt.(Mods.value.(x)), YS[1]))
79-
elseif k != 1
80-
res = map(improved_counting, YS)
81-
all(respre .== res) && return map(Polynomial, res)
79+
return map(x->BigInt.(Mods.value.(x)), rk) # needs test
80+
end
81+
if k != 1
82+
push!.(YS, rk)
83+
res = map(x->improved_counting(x...), YS)
84+
all(respre .== res) && return res
8285
respre = res
83-
else
84-
respre = map(x->BigInt.(value.(x)), YS[1])
86+
else # k=1
87+
YS = reshape([Any[] for i=1:length(rk)], size(rk))
88+
push!.(YS, rk)
89+
respre = map(x->BigInt.(value.(x)), rk)
8590
end
8691
end
8792
@warn "result is potentially inconsistent."
88-
return map(Polynomial, res)
93+
return res
8994
end
9095

91-
function improved_counting(sequences)
92-
map(yi->Mods.CRT(yi...), zip(sequences...))
96+
function improved_counting(ys::AbstractArray...)
97+
map(yi->improved_counting(yi...), zip(ys...))
9398
end
99+
improved_counting(ys::Mod...) = Mods.CRT(ys...)
94100

95101
contractx(gp::GraphProblem, x; usecuda=false) = contractf(_->x, gp; usecuda=usecuda)
96102
function contractf(f, gp::GraphProblem; usecuda=false)

test/graph_polynomials.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ end
2323
p2 = graph_polynomial(Independence(g), Val(:polynomial))[]
2424
p3 = graph_polynomial(Independence(g), Val(:fft))[]
2525
p4 = graph_polynomial(Independence(g), Val(:finitefield))[]
26+
p5 = graph_polynomial(Independence(g), Val(:finitefield); max_iter=1)[]
2627
@test p1 p2
2728
@test p1 p3
2829
@test p1 p4
30+
@test p1 p5
31+
32+
# test overflow
33+
g = random_regular_graph(120, 3)
34+
gp = Independence(g, optimizer=TreeSA(; ntrials=1); simplifier=MergeGreedy())
35+
p6 = graph_polynomial(gp, Val(:polynomial))[]
36+
p7 = graph_polynomial(gp, Val(:finitefield))[]
37+
@test p6 p7
2938
end
3039

3140
@testset "counting maximal IS" begin

0 commit comments

Comments
 (0)