-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathruntests.jl
More file actions
83 lines (68 loc) · 3.27 KB
/
Copy pathruntests.jl
File metadata and controls
83 lines (68 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Pkg
Pkg.develop(; path = normpath(joinpath(@__DIR__, "..", "..")))
Pkg.instantiate()
using Test
using Random
using SparseArrays
using BenchmarkTools
using MathOptInterface
using QUBOTools
include("../suites/fixtures.jl")
include("../suites/constructors.jl")
include("../suites/conversions.jl")
include("../suites/evaluation.jl")
const TSP_EXTRACTION_ALLOCATION_BUDGET = 32 * 1024 * 1024
@testset "Benchmark Fixtures" begin
@test benchmark_seed("n=128", 128; quadratic_density = 0.08) == 0xe5c9c566
fixture_a = benchmark_fixture("n=128", 128; quadratic_density = 0.08)
fixture_b = benchmark_fixture("n=128", 128; quadratic_density = 0.08)
constructor_fixture = benchmark_constructor_fixture("n=128", 128; quadratic_density = 0.08)
dict_model = QUBOTools.Model(
constructor_fixture.linear,
constructor_fixture.quadratic;
offset = -1.0,
sense = :min,
domain = :bool,
)
parsed_model = QUBOTools.Model(constructor_fixture.bool_moi_model)
psi = [isodd(i) ? 1 : 0 for i in 1:QUBOTools.dimension(dict_model)]
@test fixture_a.linear == fixture_b.linear
@test fixture_a.quadratic == fixture_b.quadratic
@test fixture_a.psi == fixture_b.psi
@test QUBOTools.dimension(parsed_model) == 128
@test Dict(QUBOTools.linear_terms(parsed_model)) == Dict(QUBOTools.linear_terms(dict_model))
@test Dict(QUBOTools.quadratic_terms(parsed_model)) == Dict(QUBOTools.quadratic_terms(dict_model))
@test QUBOTools.offset(parsed_model) == QUBOTools.offset(dict_model)
@test QUBOTools.sense(parsed_model) === QUBOTools.Min
@test QUBOTools.domain(parsed_model) === QUBOTools.BoolDomain
@test QUBOTools.value(parsed_model, psi) ≈ QUBOTools.value(dict_model, psi)
tsp_fixture = benchmark_dense_tsp_constructor_fixture("tsp/cities=12", 12)
tsp_model = QUBOTools.Model(tsp_fixture.bool_moi_model)
tsp_allocated = @allocated QUBOTools.Model(tsp_fixture.bool_moi_model)
@test length(tsp_fixture.linear) == tsp_fixture.cities^2
@test length(tsp_fixture.quadratic) == 2 * tsp_fixture.cities^2 * (tsp_fixture.cities - 1)
@test QUBOTools.dimension(tsp_model) == tsp_fixture.cities^2
@test QUBOTools.linear_size(tsp_model) == tsp_fixture.cities^2
@test QUBOTools.quadratic_size(tsp_model) == length(tsp_fixture.quadratic)
@test tsp_allocated <= TSP_EXTRACTION_ALLOCATION_BUDGET
end
@testset "Benchmark Suites" begin
fixtures = benchmark_fixtures()
constructor_fixtures = benchmark_constructor_fixtures()
suite = BenchmarkGroup()
suite["constructors"] = BenchmarkGroup()
suite["conversions"] = BenchmarkGroup()
suite["evaluation"] = BenchmarkGroup()
benchmark_constructors!(suite["constructors"], constructor_fixtures)
benchmark_conversions!(suite["conversions"], fixtures)
benchmark_evaluation!(suite["evaluation"], fixtures)
@test haskey(suite["constructors"], "n=2048")
@test haskey(suite["constructors"]["n=2048"], "Model/MOI/bool")
@test haskey(suite["constructors"], "tsp/cities=36")
@test haskey(suite["constructors"]["tsp/cities=36"], "Model/MOI/bool")
for fixture in fixtures
conversion_group = suite["conversions"][fixture.label]
@test haskey(conversion_group, "ising/Matrix")
@test haskey(conversion_group, "qubo/Matrix")
end
end