From 5aab6125c572b3deb3746d57a9e2fedaa99feaff Mon Sep 17 00:00:00 2001 From: Pedro Maciel Xavier Date: Fri, 28 Jul 2023 23:17:51 -0300 Subject: [PATCH] Add quadratization benchmark --- benchmark/benchmark.jl | 8 ++++++-- benchmark/report.jl | 2 +- benchmark/{ => suites}/constructors.jl | 0 benchmark/{ => suites}/operators.jl | 0 benchmark/suites/quadratization.jl | 18 ++++++++++++++++++ src/quadratization.jl | 6 +++--- 6 files changed, 28 insertions(+), 6 deletions(-) rename benchmark/{ => suites}/constructors.jl (100%) rename benchmark/{ => suites}/operators.jl (100%) create mode 100644 benchmark/suites/quadratization.jl diff --git a/benchmark/benchmark.jl b/benchmark/benchmark.jl index 118f738..6007efd 100644 --- a/benchmark/benchmark.jl +++ b/benchmark/benchmark.jl @@ -17,14 +17,18 @@ Random.seed!(0) const SUITE = BenchmarkGroup() -include("constructors.jl") +include("suites/constructors.jl") benchmark_constructors!(SUITE, PBO.PBF{Int,Float64}) -include("operators.jl") +include("suites/operators.jl") benchmark_operators!(SUITE, PBO.PBF{Int,Float64}) +include("suites/quadratization.jl") + +benchmark_quadratization!(SUITE, PBO.PBF{Int,Float64}) + function benchmark_main(suite) data_path = joinpath(@__DIR__, "data") diff --git a/benchmark/report.jl b/benchmark/report.jl index fb32391..3c59647 100644 --- a/benchmark/report.jl +++ b/benchmark/report.jl @@ -67,7 +67,7 @@ function compare_results(results; keypath = "") end end - return report + return sort!(report) end function write_report(report, data_path) diff --git a/benchmark/constructors.jl b/benchmark/suites/constructors.jl similarity index 100% rename from benchmark/constructors.jl rename to benchmark/suites/constructors.jl diff --git a/benchmark/operators.jl b/benchmark/suites/operators.jl similarity index 100% rename from benchmark/operators.jl rename to benchmark/suites/operators.jl diff --git a/benchmark/suites/quadratization.jl b/benchmark/suites/quadratization.jl new file mode 100644 index 0000000..7e1321a --- /dev/null +++ b/benchmark/suites/quadratization.jl @@ -0,0 +1,18 @@ +function benchmark_quadratization!(suite, ::Type{F}) where {V,T,F<:PBO.AbstractFunction{V,T}} + suite["quadratization"] = BenchmarkGroup() + suite["quadratization"]["automatic"] = BenchmarkGroup() + suite["quadratization"]["automatic"]["small"] = @benchmarkable( + PBO.quadratize(f, PBO.Quadratization{PBO.INFER}()); + setup = begin + f = PBO.k_regular_k_xorsat(Random.GLOBAL_RNG, $F, 10, 3; quad = nothing) + end + ) + suite["quadratization"]["automatic"]["large"] = @benchmarkable( + PBO.quadratize(f, PBO.Quadratization{PBO.INFER}()); + setup = begin + f = PBO.k_regular_k_xorsat(Random.GLOBAL_RNG, $F, 100, 3; quad = nothing) + end + ) + + return nothing +end \ No newline at end of file diff --git a/src/quadratization.jl b/src/quadratization.jl index d8874cf..e5fbac5 100644 --- a/src/quadratization.jl +++ b/src/quadratization.jl @@ -275,14 +275,14 @@ function auxgen(::AbstractFunction{V,T}; start::V = V(0), step::V = V(-1)) where return aux end -function quadratize!(f::PBF, quad::Union{Quadratization,Nothing}) +function quadratize!(f::PBF, quad::Union{Quadratization,Nothing} = Quadratization{INFER}) return quadratize!(auxgen(f), f, quad) end -function quadratize(aux, f::PBF, quad::Union{Quadratization,Nothing}) +function quadratize(aux, f::PBF, quad::Union{Quadratization,Nothing} = Quadratization{INFER}) return quadratize!(aux, copy(f), quad) end -function quadratize(f::PBF, quad::Union{Quadratization,Nothing}) +function quadratize(f::PBF, quad::Union{Quadratization,Nothing} = Quadratization{INFER}) return quadratize!(copy(f), quad) end