Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Dec 13, 2024
1 parent 2b4d07c commit a788148
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions test/dragondrop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ using Random
r1 = solve(GenericTensorNetwork(IndependentSet(graph, weights)), SingleConfigMax())[]
J2 = vcat([Float64[J[i,j] for j=i+1:n] for i=1:n]...)
# note the different sign convention of J
r2 = solve(GenericTensorNetwork(SpinGlass(complete_graph(n), -J2, H)), SingleConfigMax())[]
sg = SpinGlass(complete_graph(n), -J2, H)
r2 = solve(GenericTensorNetwork(sg), SingleConfigMax())[]
@test r1.n - qubo.mis_overhead r2.n
@test r1.n % 1 r2.n % 1
c1 = map_config_back(qubo, r1.c.data)
@test spinglass_energy(complete_graph(n), c1; J=-J2, h=H) spinglass_energy(complete_graph(n), r2.c.data; J=-J2, h=H)
@test GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(c1)) GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(r2.c.data))
#display(MappingGrid(UnitDiskMapping.CopyLine[], 0, qubo))
end

Expand Down Expand Up @@ -56,7 +57,7 @@ end
add_edge!(g2, (i-1)*n+j, (i2-1)*n+j2)
push!(weights, J)
end
r2 = solve(GenericTensorNetwork(SpinGlass(g2, -weights)), SingleConfigMax())[]
r2 = solve(GenericTensorNetwork(SpinGlass(g2, -weights, zeros(Int, n*n))), SingleConfigMax())[]
@show r1, r2
end

Expand Down Expand Up @@ -88,9 +89,10 @@ end
for (i,j,h) in onsite
hs[i+(j-1)*m] = h
end
r2 = solve(GenericTensorNetwork(SpinGlass(g2, -Js, hs)), SingleConfigMax())[]
sg = SpinGlass(g2, -Js, hs)
r2 = solve(GenericTensorNetwork(sg), SingleConfigMax())[]
@test r1.n - qubo.mis_overhead r2.n
c1 = map_config_back(qubo, collect(Int,r1.c.data))
c2 = collect(r2.c.data)
@test spinglass_energy(g2, c1; J=-Js, h=hs) spinglass_energy(g2, c2; J=-Js, h=hs)
end
@test GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(c1)) GenericTensorNetworks.energy(sg, 1 .- 2 .* Int.(c2))
end
6 changes: 3 additions & 3 deletions test/reduceto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ end
]
@info "Testing reduction from $(typeof(source)) to $(target_type)"
# directly solve
best_source = ProblemReductions.findbest(source, ProblemReductions.BruteForce())
solver = GTNSolver(optimizer=TreeSA(ntrials=1))
best_source = ProblemReductions.findbest(source, source isa ConstraintSatisfactionProblem ? solver : ProblemReductions.BruteForce())

# reduce and solve
result = ProblemReductions.reduceto(target_type, source)
target = ProblemReductions.target_problem(result)
@test target isa target_type
#best_target = findbest(target, BruteForce())
best_target = GenericTensorNetworks.solve(GenericTensorNetwork(GenericTensorNetworks.IndependentSet(SimpleGraph(target.graph), collect(target.weights))), ConfigsMax())[].c.data
best_target = ProblemReductions.findbest(IndependentSet(SimpleGraph(target.graph), collect(target.weights)), solver)

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

0 comments on commit a788148

Please sign in to comment.