Skip to content

Commit 5c8db22

Browse files
committed
fix partition function sign
1 parent 8432a0a commit 5c8db22

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/interfaces.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ function solve(gp::GenericTensorNetwork, property::AbstractProperty; T=Float64,
267267
Array(contractx(gp, one(T); usecuda=usecuda))
268268
end
269269
elseif property isa PartitionFunction
270-
return contractx(gp, exp(property.beta); usecuda=usecuda)
270+
# for larger size is better, we use the negative size as the energy
271+
return contractx(gp, exp(energy_mode(gp.problem) isa LargerSizeIsBetter ? property.beta : -property.beta); usecuda=usecuda)
271272
elseif property isa CountingMax{Single}
272273
return contractx(gp, _x(CountingTropical{T,T}; invert=false); usecuda=usecuda)
273274
elseif property isa CountingMin{Single}

test/interfaces.jl

+20
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,23 @@ end
259259
@test findmin(sg, solver3)[] findmin(sg, solver2)
260260
@test findmax(sg, solver3)[] findmax(sg, solver2)
261261
end
262+
263+
@testset "partition function" begin
264+
function fullerene()
265+
φ = (1+√5)/2
266+
res = NTuple{3,Float64}[]
267+
for (x, y, z) in ((0.0, 1.0, 3φ), (1.0, 2 + φ, 2φ), (φ, 2.0, 2φ + 1.0))
268+
for (α, β, γ) in ((x,y,z), (y,z,x), (z,x,y))
269+
for loc in ((α,β,γ), (α,β,-γ), (α,-β,γ), (α,-β,-γ), (-α,β,γ), (-α,β,-γ), (-α,-β,γ), (-α,-β,-γ))
270+
if loc res
271+
push!(res, loc)
272+
end
273+
end
274+
end
275+
end
276+
return res
277+
end
278+
graph = UnitDiskGraph(fullerene(), sqrt(5))
279+
spin_glass = SpinGlass(graph, UnitWeight(ne(graph)), zeros(Int, nv(graph)))
280+
@test log(solve(spin_glass, PartitionFunction(1.0))[])/nv(graph) 1.3073684577607942
281+
end

0 commit comments

Comments
 (0)