Skip to content

Commit a788148

Browse files
committed
fix tests
1 parent 2b4d07c commit a788148

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

test/dragondrop.jl

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ using Random
1414
r1 = solve(GenericTensorNetwork(IndependentSet(graph, weights)), SingleConfigMax())[]
1515
J2 = vcat([Float64[J[i,j] for j=i+1:n] for i=1:n]...)
1616
# note the different sign convention of J
17-
r2 = solve(GenericTensorNetwork(SpinGlass(complete_graph(n), -J2, H)), SingleConfigMax())[]
17+
sg = SpinGlass(complete_graph(n), -J2, H)
18+
r2 = solve(GenericTensorNetwork(sg), SingleConfigMax())[]
1819
@test r1.n - qubo.mis_overhead r2.n
1920
@test r1.n % 1 r2.n % 1
2021
c1 = map_config_back(qubo, r1.c.data)
21-
@test spinglass_energy(complete_graph(n), c1; J=-J2, h=H) spinglass_energy(complete_graph(n), r2.c.data; J=-J2, h=H)
22+
@test GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(c1)) GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(r2.c.data))
2223
#display(MappingGrid(UnitDiskMapping.CopyLine[], 0, qubo))
2324
end
2425

@@ -56,7 +57,7 @@ end
5657
add_edge!(g2, (i-1)*n+j, (i2-1)*n+j2)
5758
push!(weights, J)
5859
end
59-
r2 = solve(GenericTensorNetwork(SpinGlass(g2, -weights)), SingleConfigMax())[]
60+
r2 = solve(GenericTensorNetwork(SpinGlass(g2, -weights, zeros(Int, n*n))), SingleConfigMax())[]
6061
@show r1, r2
6162
end
6263

@@ -88,9 +89,10 @@ end
8889
for (i,j,h) in onsite
8990
hs[i+(j-1)*m] = h
9091
end
91-
r2 = solve(GenericTensorNetwork(SpinGlass(g2, -Js, hs)), SingleConfigMax())[]
92+
sg = SpinGlass(g2, -Js, hs)
93+
r2 = solve(GenericTensorNetwork(sg), SingleConfigMax())[]
9294
@test r1.n - qubo.mis_overhead r2.n
9395
c1 = map_config_back(qubo, collect(Int,r1.c.data))
9496
c2 = collect(r2.c.data)
95-
@test spinglass_energy(g2, c1; J=-Js, h=hs) spinglass_energy(g2, c2; J=-Js, h=hs)
96-
end
97+
@test GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(c1)) GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(c2))
98+
end

test/reduceto.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ end
2626
]
2727
@info "Testing reduction from $(typeof(source)) to $(target_type)"
2828
# directly solve
29-
best_source = ProblemReductions.findbest(source, ProblemReductions.BruteForce())
29+
solver = GTNSolver(optimizer=TreeSA(ntrials=1))
30+
best_source = ProblemReductions.findbest(source, source isa ConstraintSatisfactionProblem ? solver : ProblemReductions.BruteForce())
3031

3132
# reduce and solve
3233
result = ProblemReductions.reduceto(target_type, source)
3334
target = ProblemReductions.target_problem(result)
3435
@test target isa target_type
35-
#best_target = findbest(target, BruteForce())
36-
best_target = GenericTensorNetworks.solve(GenericTensorNetwork(GenericTensorNetworks.IndependentSet(SimpleGraph(target.graph), collect(target.weights))), ConfigsMax())[].c.data
36+
best_target = ProblemReductions.findbest(IndependentSet(SimpleGraph(target.graph), collect(target.weights)), solver)
3737

3838
# extract the solution
3939
best_source_extracted_single = unique( ProblemReductions.extract_solution.(Ref(result), best_target) )

0 commit comments

Comments
 (0)