Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format all #2554

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
using JuliaFormatter
format("src", verbose=true)
format("test", verbose=true)
format(".", verbose=true)
out = String(read(Cmd(`git diff`)))
if isempty(out)
exit(0)
Expand Down
11 changes: 4 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const _PDF = findfirst(isequal("--pdf"), ARGS) !== nothing || _IS_GITHUB_ACTIONS
# ==============================================================================

const _PAGES = [
"Introduction" => [
"index.md",
"background/motivation.md",
],
"Introduction" => ["index.md", "background/motivation.md"],
"Tutorials" => [
"tutorials/example.md",
"tutorials/implementing.md",
Expand Down Expand Up @@ -94,12 +91,12 @@ const _PAGES = [

function fix_release_line(
line::String,
url::String = "https://github.com/jump-dev/MathOptInterface.jl"
url::String = "https://github.com/jump-dev/MathOptInterface.jl",
)
# (#XXXX) -> ([#XXXX](url/issue/XXXX))
while (m = match(r"\(\#([0-9]+)\)", line)) !== nothing
id = m.captures[1]
line = replace(line, m.match => "([#$id]($url/issues/$id))")
id = m.captures[1]
line = replace(line, m.match => "([#$id]($url/issues/$id))")
end
# ## vX.Y.Z -> [vX.Y.Z](url/releases/tag/vX.Y.Z)
while (m = match(r"\#\# (v[0-9]+.[0-9]+.[0-9]+)", line)) !== nothing
Expand Down
65 changes: 54 additions & 11 deletions perf/bellman_ford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,58 @@ import MathOptInterface.Utilities as MOIU

# Model similar to SDPA format, it gives a good example because it does not
# support a lot hence need a lot of bridges
MOIU.@model(SDPAModel,
(), (MOI.EqualTo,), (MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), (),
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), ())
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.GreaterThan{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.LessThan{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.EqualTo{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.Interval{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel, ::Type{MOI.VectorOfVariables}, ::Type{MOI.Reals}) = false
MOI.supports(::SDPAModel{T}, ::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}}) where {T} = false
MOIU.@model(
SDPAModel,
(),
(MOI.EqualTo,),
(MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
(),
(),
(MOI.ScalarAffineFunction,),
(MOI.VectorOfVariables,),
()
)
function MOI.supports_constraint(
::SDPAModel{T},
::Type{MOI.VariableIndex},
::Type{MOI.GreaterThan{T}},
) where {T}
return false
end
function MOI.supports_constraint(
::SDPAModel{T},
::Type{MOI.VariableIndex},
::Type{MOI.LessThan{T}},
) where {T}
return false
end
function MOI.supports_constraint(
::SDPAModel{T},
::Type{MOI.VariableIndex},
::Type{MOI.EqualTo{T}},
) where {T}
return false
end
function MOI.supports_constraint(
::SDPAModel{T},
::Type{MOI.VariableIndex},
::Type{MOI.Interval{T}},
) where {T}
return false
end
function MOI.supports_constraint(
::SDPAModel,
::Type{MOI.VectorOfVariables},
::Type{MOI.Reals},
)
return false
end
function MOI.supports(
::SDPAModel{T},
::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}},
) where {T}
return false
end
MOI.supports(::SDPAModel, ::MOI.ObjectiveFunction{MOI.VariableIndex}) = false

function interval_constraint()
Expand All @@ -31,7 +74,7 @@ function interval_constraint()
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.node($bridged, $F, $S)
end)
display(@benchmark begin
return display(@benchmark begin
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.bridge_index($bridged, $F, $S)
end)
Expand All @@ -48,7 +91,7 @@ function quadratic_objective()
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.node($bridged, $F)
end)
display(@benchmark begin
return display(@benchmark begin
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.bridge_index($bridged, $F)
end)
Expand Down
30 changes: 25 additions & 5 deletions perf/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,35 @@ using BenchmarkTools
import MathOptInterface as MOI
import MathOptInterface.Utilities as MOIU

@MOIU.model Model () (MOI.Interval,) () () () (MOI.ScalarAffineFunction,) () ()
MOIU.@model Model () (MOI.Interval,) () () () (MOI.ScalarAffineFunction,) () ()
optimizer = MOIU.MockOptimizer(Model{Float64}())
caching_optimizer = MOIU.CachingOptimizer(Model{Float64}(), optimizer)
MOIU.reset_optimizer(caching_optimizer) # detach optimizer
v = MOI.add_variables(caching_optimizer, 2)
cf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([0.0, 0.0], v), 0.0)
c = MOI.add_constraint(caching_optimizer, cf, MOI.Interval(-Inf, 1.0))
@btime MOI.set($caching_optimizer, $(MOI.ConstraintSet()), $c, $(MOI.Interval(0.0, 2.0)))
@btime MOI.set(
$caching_optimizer,
$(MOI.ConstraintSet()),
$c,
$(MOI.Interval(0.0, 2.0)),
)
MOIU.attach_optimizer(caching_optimizer)
@btime MOI.set($caching_optimizer, $(MOI.ConstraintSet()), $c, $(MOI.Interval(0.0, 2.0)))
@btime MOI.set($(caching_optimizer.model_cache), $(MOI.ConstraintSet()), $c, $(MOI.Interval(0.0, 2.0)))
@btime MOI.set($(caching_optimizer.optimizer), $(MOI.ConstraintSet()), $(caching_optimizer.model_to_optimizer_map[c]), $(MOI.Interval(0.0, 2.0)))
@btime MOI.set(
$caching_optimizer,
$(MOI.ConstraintSet()),
$c,
$(MOI.Interval(0.0, 2.0)),
)
@btime MOI.set(
$(caching_optimizer.model_cache),
$(MOI.ConstraintSet()),
$c,
$(MOI.Interval(0.0, 2.0)),
)
@btime MOI.set(
$(caching_optimizer.optimizer),
$(MOI.ConstraintSet()),
$(caching_optimizer.model_to_optimizer_map[c]),
$(MOI.Interval(0.0, 2.0)),
)
14 changes: 7 additions & 7 deletions perf/time_to_first_solve/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import MathOptInterface as MOI
function example_diet(optimizer, bridge)
category_data = [
1800.0 2200.0
91.0 Inf
0.0 65.0
0.0 1779.0
91.0 Inf
0.0 65.0
0.0 1779.0
]
cost = [2.49, 2.89, 1.50, 1.89, 2.09, 1.99, 2.49, 0.89, 1.59]
food_data = [
410 24 26 730
420 32 10 1190
560 20 32 1800
380 4 19 270
380 4 19 270
320 12 10 930
320 15 12 820
320 31 12 1230
100 8 2.5 125
330 8 10 180
100 8 2.5 125
330 8 10 180
]
bridge_model = if bridge
MOI.instantiate(optimizer; with_bridge_type=Float64)
MOI.instantiate(optimizer; with_bridge_type = Float64)
else
MOI.instantiate(optimizer)
end
Expand Down
Loading