Skip to content

Commit

Permalink
Add quadratization benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Jul 29, 2023
1 parent 03f695f commit 5aab612
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
8 changes: 6 additions & 2 deletions benchmark/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion benchmark/report.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function compare_results(results; keypath = "")
end
end

return report
return sort!(report)
end

function write_report(report, data_path)
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions benchmark/suites/quadratization.jl
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/quadratization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5aab612

Please sign in to comment.