Skip to content

Commit b1febf5

Browse files
authored
Fix a bug related to ConfigsMax (#62)
* Fix a bug related to ConfigsMax * fix test and bump version
1 parent 71694e1 commit b1febf5

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GenericTensorNetworks"
22
uuid = "3521c873-ad32-4bb4-b63d-f4f178f42b49"
33
authors = ["GiggleLiu <cacate0129@gmail.com> and contributors"]
4-
version = "1.3.2"
4+
version = "1.3.3"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/bounding.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ The backward rule for tropical einsum.
1414
* `size_dict` is a key-value map from tensor label to dimension size.
1515
"""
1616
function backward_tropical(mode, ixs, @nospecialize(xs::Tuple), iy, @nospecialize(y), @nospecialize(ymask), size_dict)
17-
y .= inv.(y) .* ymask
17+
# remove float to improve the stability of the algorithm
18+
removeinf(x::CountingTropical{<:AbstractFloat}) = isinf(x.n) ? typeof(x)(prevfloat(x.n), x.c) : x
19+
removeinf(x::Tropical{<:AbstractFloat}) = isinf(x.n) ? typeof(x)(prevfloat(x.n)) : x
20+
removeinf(x) = x
21+
y .= removeinf.(inv.(y) .* ymask)
1822
masks = []
1923
for i=1:length(ixs)
2024
nixs = OMEinsum._insertat(ixs, i, iy)

src/networks/IndependentSet.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ function generate_tensors(x::T, gp::IndependentSet) where T
6060
nv(gp.graph) == 0 && return []
6161
ixs = getixsv(gp.code)
6262
# we only add labels at vertex tensors
63-
return select_dims([
63+
tensors = select_dims([
6464
add_labels!(Array{T}[misv(_pow.(Ref(x), get_weights(gp, i))) for i=1:nv(gp.graph)], ixs[1:nv(gp.graph)], labels(gp))...,
6565
Array{T}[misb(T, length(ix)) for ix in ixs[nv(gp.graph)+1:end]]... # if n!=2, it corresponds to set packing problem.
6666
], ixs, fixedvertices(gp))
67+
return tensors
6768
end
6869

6970
function misb(::Type{T}, n::Integer=2) where T

test/configurations.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,22 @@ end
5858
@test all(x->count_ones(x)==(i-1), s.data)
5959
end
6060
end
61+
end
62+
63+
@testset "configs bug fix" begin
64+
subgraph = let
65+
g = SimpleGraph(5)
66+
vertices = "cdefg"
67+
for (w, v) in ["cd", "ce", "cf", "de", "ef", "fg"]
68+
add_edge!(g, findfirst(==(w), vertices), findfirst(==(v), vertices))
69+
end
70+
g
71+
end
72+
problem = IndependentSet(subgraph, openvertices=[1,4,5])
73+
res1 = solve(problem, SizeMax(), T=Float64)
74+
@test res1 == Tropical.(reshape([1, 1, 2, -Inf, 2, 2, -Inf, -Inf], 2, 2, 2))
75+
res2 = solve(problem, CountingMax(); T=Float64)
76+
res3 = solve(problem, ConfigsMax(; bounded=true); T=Float64)
77+
@test getfield.(res2, :n) == getfield.(res1, :n)
78+
@test getfield.(res3, :n) == getfield.(res1, :n)
6179
end

0 commit comments

Comments
 (0)