From ae32ee83d5b08c8f18ba65ca09d04997692675ea Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Mon, 8 Jan 2024 12:32:51 +1300 Subject: [PATCH 1/2] Update compat bounds in Project.toml --- Project.toml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index a9fc3ab..705d370 100644 --- a/Project.toml +++ b/Project.toml @@ -22,25 +22,33 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] -Clustering = "0.14" +Clustering = "0.14, 0.15" Compat = "2.2, 3" -Distributions = "0.25.0" +Distributed = "<0.0.1, 1.6" +Distributions = "0.25" +GLPK = "1" +Ipopt = "1" JuMP = "= 1.2.1" +LinearAlgebra = "<0.0.1, 1.6" +Logging = "<0.0.1, 1.6" MacroTools = "0.5.3" -MathOptInterface = "= 1.3.0" -MutableArithmetics = "= 1.0.4" -OrderedCollections = "1.2.0" +MathOptInterface = "1.3" +MutableArithmetics = "1.0.4" +OrderedCollections = "1.2" Parameters = "0.12" +Printf = "<0.0.1, 1.6" ProgressMeter = "1.4.1" -Reexport = "1.0.0" -julia = "1" +Random = "<0.0.1, 1.6" +Reexport = "1" +SparseArrays = "<0.0.1, 1.6" +Test = "<0.0.1, 1.6" +julia = "1.6" [extras] -Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Logging", "GLPK", "Ipopt", "Distributions"] +test = ["GLPK", "Ipopt", "Logging", "Test"] From fc5846662e1ab453580af638da214e65b7836772 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 8 Jan 2024 13:22:17 +1300 Subject: [PATCH 2/2] Updates to get tests passing --- .github/workflows/ci.yml | 5 ++--- .gitignore | 1 + Project.toml | 6 +++--- src/StochasticPrograms.jl | 6 ++---- src/crash.jl | 4 +--- src/methods/api.jl | 2 +- src/solvers/sampled/SAA/SAA.jl | 3 +-- .../lshaped/aggregators/hybrid_aggregation.jl | 2 +- src/solvers/structured/lshaped/lshaped.jl | 3 +-- .../progressivehedging/progressivehedging.jl | 3 +-- .../structured/quasigradient/quasigradient.jl | 3 +-- src/types/decision_objective.jl | 12 ++++++------ src/types/decisions/bridges/constraints/quadratic.jl | 2 +- .../decisions/expressions/mutable_arithmetics.jl | 2 +- src/types/decisions/functions/affine.jl | 8 ++++---- src/types/decisions/functions/operators.jl | 4 ++-- src/types/decomposition/scenarioproblems.jl | 12 ++++++------ test/decisions/decision_expressions.jl | 6 ++---- test/decisions/decision_functions.jl | 5 ++--- test/decisions/decision_operators.jl | 6 ++---- 20 files changed, 41 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52944a8..7298978 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,7 @@ jobs: matrix: version: - '1.6' - - '1.8' - - 'nightly' + - '1' os: - ubuntu-latest - macOS-latest @@ -26,7 +25,7 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} diff --git a/.gitignore b/.gitignore index 6b2ea0a..20f12aa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.jl.mem docs/build/ docs/site/ +Manifest.toml diff --git a/Project.toml b/Project.toml index 705d370..1b12b7a 100644 --- a/Project.toml +++ b/Project.toml @@ -27,17 +27,17 @@ Compat = "2.2, 3" Distributed = "<0.0.1, 1.6" Distributions = "0.25" GLPK = "1" -Ipopt = "1" +Ipopt = "~1.0, ~1.1, ~1.2" JuMP = "= 1.2.1" LinearAlgebra = "<0.0.1, 1.6" Logging = "<0.0.1, 1.6" MacroTools = "0.5.3" -MathOptInterface = "1.3" +MathOptInterface = "~1.3" MutableArithmetics = "1.0.4" OrderedCollections = "1.2" Parameters = "0.12" Printf = "<0.0.1, 1.6" -ProgressMeter = "1.4.1" +ProgressMeter = "~1.4.1" Random = "<0.0.1, 1.6" Reexport = "1" SparseArrays = "<0.0.1, 1.6" diff --git a/src/StochasticPrograms.jl b/src/StochasticPrograms.jl index 9095ce1..ca6ac48 100644 --- a/src/StochasticPrograms.jl +++ b/src/StochasticPrograms.jl @@ -33,7 +33,7 @@ using Printf using JuMP using Compat using OrderedCollections -using MathOptInterface +import MathOptInterface as MOI import Distributions: mean, std, quantile, ProbabilityWeights, TDist, Normal using MacroTools using MacroTools: @q, postwalk, prewalk @@ -47,15 +47,13 @@ const DenseAxisArray = JuMP.Containers.DenseAxisArray const SparseAxisArray = JuMP.Containers.SparseAxisArray const VectorizedProductIterator = JuMP.Containers.VectorizedProductIterator -const MOI = MathOptInterface const MOIU = MOI.Utilities const MOIB = MOI.Bridges const VI = MOI.VariableIndex const CI = MOI.ConstraintIndex const AcceptableTermination = [MOI.OPTIMAL, MOI.LOCALLY_SOLVED, MOI.ALMOST_OPTIMAL, MOI.ALMOST_LOCALLY_SOLVED] -import MutableArithmetics -const MA = MutableArithmetics +import MutableArithmetics as MA export StochasticModel, diff --git a/src/crash.jl b/src/crash.jl index 3d87ff5..48b227d 100644 --- a/src/crash.jl +++ b/src/crash.jl @@ -51,9 +51,7 @@ module Crash using StochasticPrograms using StochasticPrograms: AbstractCrash, StochasticProgramOptimizer -using MathOptInterface - -const MOI = MathOptInterface +import MathOptInterface as MOI """ None diff --git a/src/methods/api.jl b/src/methods/api.jl index 27e1f22..221e331 100644 --- a/src/methods/api.jl +++ b/src/methods/api.jl @@ -657,7 +657,7 @@ end Return the scenario at `scenario_index` of the two-stage `stochasticprogram` """ -function scenario(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer) where N +function scenario(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer) return scenario(structure(stochasticprogram), 2, scenario_index) end """ diff --git a/src/solvers/sampled/SAA/SAA.jl b/src/solvers/sampled/SAA/SAA.jl index 934ed43..abde36a 100644 --- a/src/solvers/sampled/SAA/SAA.jl +++ b/src/solvers/sampled/SAA/SAA.jl @@ -23,14 +23,13 @@ @reexport module SAA using JuMP -using MathOptInterface +import MathOptInterface as MOI using StochasticPrograms using ProgressMeter using Parameters import StochasticPrograms: AbstractCrash, load_model!, optimizer_name, optimal_instance -const MOI = MathOptInterface const MOIU = MOI.Utilities include("solver.jl") diff --git a/src/solvers/structured/lshaped/aggregators/hybrid_aggregation.jl b/src/solvers/structured/lshaped/aggregators/hybrid_aggregation.jl index 1e40261..dd445e8 100644 --- a/src/solvers/structured/lshaped/aggregators/hybrid_aggregation.jl +++ b/src/solvers/structured/lshaped/aggregators/hybrid_aggregation.jl @@ -96,7 +96,7 @@ function flush!(lshaped::AbstractLShaped, aggregation::HybridAggregation) return added end -function flush!(cutqueue::CutQueue, aggregation::HybridAggregation, metadata::MetaDataChannel, t::Integer, x::AbstractArray) where T <: AbstractFloat +function flush!(cutqueue::CutQueue, aggregation::HybridAggregation, metadata::MetaDataChannel, t::Integer, x::AbstractArray) flush!(cutqueue, active(aggregation), metadata, t, x) if shift(fetch(metadata, t, :gap), aggregation.τ) activate_final!(aggregation) diff --git a/src/solvers/structured/lshaped/lshaped.jl b/src/solvers/structured/lshaped/lshaped.jl index 949c8e0..54bd66c 100644 --- a/src/solvers/structured/lshaped/lshaped.jl +++ b/src/solvers/structured/lshaped/lshaped.jl @@ -31,7 +31,7 @@ using Printf # External libraries using Parameters using JuMP -using MathOptInterface +import MathOptInterface as MOI using StochasticPrograms using StochasticPrograms: AcceptableTermination using StochasticPrograms: UnspecifiedInstantiation, StageDecompositionStructure, AbstractScenarioProblems, ScenarioProblems, DistributedScenarioProblems, DecisionChannel @@ -47,7 +47,6 @@ using Clustering import Base: show, put!, wait, isready, take!, fetch, zero, +, length, size import StochasticPrograms: supports_structure, num_iterations, default_structure, check_loadable, load_structure!, restore_structure!, optimize!, optimizer_name, master_optimizer, subproblem_optimizer, num_subproblems, remove_penalty_variables!, remove_penalty_constraints!, relax_decision_integrality -const MOI = MathOptInterface const MOIU = MOI.Utilities const CI = MOI.ConstraintIndex const CutConstraint = CI{AffineDecisionFunction{Float64}, MOI.GreaterThan{Float64}} diff --git a/src/solvers/structured/progressivehedging/progressivehedging.jl b/src/solvers/structured/progressivehedging/progressivehedging.jl index 6a90e4d..1738c86 100644 --- a/src/solvers/structured/progressivehedging/progressivehedging.jl +++ b/src/solvers/structured/progressivehedging/progressivehedging.jl @@ -31,7 +31,7 @@ using Printf # External libraries using Parameters using JuMP -using MathOptInterface +import MathOptInterface as MOI using StochasticPrograms using StochasticPrograms: AcceptableTermination using StochasticPrograms: UnspecifiedInstantiation, ScenarioDecompositionStructure, AbstractScenarioProblems, ScenarioProblems, DistributedScenarioProblems @@ -45,7 +45,6 @@ using ProgressMeter import Base: show, put!, wait, isready, take!, fetch import StochasticPrograms: supports_structure, num_iterations, default_structure, load_structure!, restore_structure!, optimize!, optimizer_name, master_optimizer, subproblem_optimizer, num_subproblems -const MOI = MathOptInterface const MOIU = MOI.Utilities export diff --git a/src/solvers/structured/quasigradient/quasigradient.jl b/src/solvers/structured/quasigradient/quasigradient.jl index c69c443..028fc7d 100644 --- a/src/solvers/structured/quasigradient/quasigradient.jl +++ b/src/solvers/structured/quasigradient/quasigradient.jl @@ -31,7 +31,7 @@ using Printf # External libraries using Parameters using JuMP -using MathOptInterface +import MathOptInterface as MOI using StochasticPrograms using StochasticPrograms: AcceptableTermination using StochasticPrograms: UnspecifiedInstantiation, StageDecompositionStructure, AbstractScenarioProblems, ScenarioProblems, DistributedScenarioProblems, DecisionChannel @@ -48,7 +48,6 @@ import Base: show, put!, wait, isready, take!, fetch, zero, +, length, size import StochasticPrograms: supports_structure, num_iterations, default_structure, check_loadable, load_structure!, restore_structure!, optimize!, optimizer_name, master_optimizer, subproblem_optimizer, num_subproblems, remove_penalty_variables!, remove_penalty_constraints! using ProgressMeter: Progress -const MOI = MathOptInterface const MOIU = MOI.Utilities const CI = MOI.ConstraintIndex diff --git a/src/types/decision_objective.jl b/src/types/decision_objective.jl index 2ccbbc9..194d99e 100644 --- a/src/types/decision_objective.jl +++ b/src/types/decision_objective.jl @@ -188,7 +188,7 @@ function JuMP.dual_objective_value(stochasticprogram::TwoStageStochasticProgram, return dual_objective_value(stochasticprogram, 2, scenario_index; result = result) end """ - objective_sense(stochasticprogram::StochasticProgram)::MathOptInterface.OptimizationSense + objective_sense(stochasticprogram::StochasticProgram)::MOI.OptimizationSense Return the objective sense of the `stochasticprogram`. """ @@ -196,7 +196,7 @@ function JuMP.objective_sense(stochasticprogram::StochasticProgram) return MOI.get(stochasticprogram, MOI.ObjectiveSense())::MOI.OptimizationSense end """ - objective_sense(stochasticprogram::StochasticProgram, stage::Integer)::MathOptInterface.OptimizationSense + objective_sense(stochasticprogram::StochasticProgram, stage::Integer)::MOI.OptimizationSense Return the objective sense of the `stochasticprogram` stage `stage`. """ @@ -205,7 +205,7 @@ function JuMP.objective_sense(stochasticprogram::StochasticProgram{N}, stage::In return objective_sense(proxy(stochasticprogram, stage)) end """ - objective_sense(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)::MathOptInterface.OptimizationSense + objective_sense(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)::MOI.OptimizationSense Return the objective sense in the node at stage `stage` and scenario `scenario_index`. """ @@ -215,7 +215,7 @@ function JuMP.objective_sense(stochasticprogram::StochasticProgram, stage::Integ return MOI.get(stochasticprogram, attr)::MOI.OptimizationSense end """ - set_objective_sense(stochasticprogram::StochasticProgram, sense::MathOptInterface.OptimizationSense) + set_objective_sense(stochasticprogram::StochasticProgram, sense::MOI.OptimizationSense) Sets the objective sense of the `stochasticprogram` to `sense`. """ @@ -231,7 +231,7 @@ function JuMP.set_objective_sense(stochasticprogram::StochasticProgram, sense::M return nothing end """ - set_objective_sense(stochasticprogram::StochasticProgram, stage::Integer, sense::MathOptInterface.OptimizationSense) + set_objective_sense(stochasticprogram::StochasticProgram, stage::Integer, sense::MOI.OptimizationSense) Sets the objective sense of the `stochasticprogram` at stage `stage` to `sense`. """ @@ -248,7 +248,7 @@ function JuMP.set_objective_sense(stochasticprogram::StochasticProgram{N}, stage return nothing end """ - set_objective_sense(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer, sense::MathOptInterface.OptimizationSense) + set_objective_sense(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer, sense::MOI.OptimizationSense) Sets the objective sense of the stochasticprogram node at stage `stage` and scenario `scenario_index` to the given `sense`. diff --git a/src/types/decisions/bridges/constraints/quadratic.jl b/src/types/decisions/bridges/constraints/quadratic.jl index 46fe519..bd1e185 100644 --- a/src/types/decisions/bridges/constraints/quadratic.jl +++ b/src/types/decisions/bridges/constraints/quadratic.jl @@ -92,7 +92,7 @@ end function MOI.set(model::MOI.ModelLike, ::MOI.ConstraintFunction, bridge::QuadraticDecisionConstraintBridge{T,S}, - f::QuadraticDecisionFunction{T}) where {T,S,F} + f::QuadraticDecisionFunction{T}) where {T,S} # Update bridge functions and function constant bridge.decision_function = f # Change the function of the bridged constraints diff --git a/src/types/decisions/expressions/mutable_arithmetics.jl b/src/types/decisions/expressions/mutable_arithmetics.jl index 1d07b8b..c67fbf2 100644 --- a/src/types/decisions/expressions/mutable_arithmetics.jl +++ b/src/types/decisions/expressions/mutable_arithmetics.jl @@ -125,7 +125,7 @@ function MA.promote_operation(::typeof(*), ::Type{<:_Decision}, ::Type{<:_Decisi return DQE end # _Variable/_Decision--(_Variable/_Decision)AffExpr -function MA.promote_operation(::typeof(*), ::Type{<:_Variable}, ::Type{GenericAffExpr{C, _Decision}}) where {C, D <: _Decision} +function MA.promote_operation(::typeof(*), ::Type{<:_Variable}, ::Type{GenericAffExpr{C, _Decision}}) where {C} return DecisionQuadExpr{C} end function MA.promote_operation(::typeof(*), ::Type{GenericAffExpr{C, D}}, ::Type{<:_Variable}) where {C, D <: _Decision} diff --git a/src/types/decisions/functions/affine.jl b/src/types/decisions/functions/affine.jl index c1370dd..0107335 100644 --- a/src/types/decisions/functions/affine.jl +++ b/src/types/decisions/functions/affine.jl @@ -347,14 +347,14 @@ function Base.getindex(it::MOIU.ScalarFunctionIterator{VectorAffineDecisionFunct push!(decision_terms, MOI.VectorAffineTerm(i, it.f.decision_part.terms[j].scalar_term)) end end - return VectorAffineDecisionFunction(MOIU.VAF(variable_terms, it.f.variable_part.constants[output_indices]), - MOIU.VAF(decision_terms, it.f.decision_part.constants[output_indices])) + return VectorAffineDecisionFunction(MOI.VectorAffineFunction(variable_terms, it.f.variable_part.constants[output_indices]), + MOI.VectorAffineFunction(decision_terms, it.f.decision_part.constants[output_indices])) end function MOIU.zero_with_output_dimension(::Type{VectorAffineDecisionFunction{T}}, n::Integer) where T - return MOI.VectorAffineDecisionFunction{T}(MOIU.zero_with_output_dimension(MOI.VAF{T}, n), - MOIU.zero_with_output_dimension(MOI.VAF{T}, n)) + return MOI.VectorAffineDecisionFunction{T}(MOIU.zero_with_output_dimension(MOI.VectorAffineFunction{T}, n), + MOIU.zero_with_output_dimension(MOI.VectorAffineFunction{T}, n)) end function MOIU.substitute_variables(variable_map::Function, f::AffineDecisionFunction{T}) where T diff --git a/src/types/decisions/functions/operators.jl b/src/types/decisions/functions/operators.jl index fc42fb9..a894b0a 100644 --- a/src/types/decisions/functions/operators.jl +++ b/src/types/decisions/functions/operators.jl @@ -858,8 +858,8 @@ function MOIU.operate(::typeof(vcat), ::Type{T}, out_dim = max(variable_out_dim, decision_out_dim) append!(variable_constants, zeros(T, out_dim - length(variable_constants))) append!(decision_constants, zeros(T, out_dim - length(decision_constants))) - return VectorAffineDecisionFunction{T}(MOIU.VAF(variable_terms, variable_constants), - MOIU.VAF(decision_terms, decision_constants)) + return VectorAffineDecisionFunction{T}(MOI.VectorAffineFunction(variable_terms, variable_constants), + MOI.VectorAffineFunction(decision_terms, decision_constants)) end # First or second argument must be decision like to avoid type piracy diff --git a/src/types/decomposition/scenarioproblems.jl b/src/types/decomposition/scenarioproblems.jl index 503af31..d04ebb9 100644 --- a/src/types/decomposition/scenarioproblems.jl +++ b/src/types/decomposition/scenarioproblems.jl @@ -391,7 +391,7 @@ function scenario_decision_dispatch(decision_function::Function, scenarioproblems::ScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer, - args...) where N + args...) dref = DecisionRef(subproblem(scenarioproblems, scenario_index), index) return decision_function(dref, args...) end @@ -399,7 +399,7 @@ function scenario_decision_dispatch(decision_function::Function, scenarioproblems::DistributedScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer, - args...) where N + args...) return get_from_scenarioproblem(scenarioproblems, scenario_index, decision_function, index, args...) do sp, i, decision_function, index, args... subprob = fetch(sp).problems[i] dref = DecisionRef(subprob, index) @@ -410,7 +410,7 @@ function scenario_decision_dispatch!(decision_function!::Function, scenarioproblems::ScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer, - args...) where N + args...) dref = DecisionRef(subproblem(scenarioproblems, scenario_index), index) decision_function!(dref, args...) return nothing @@ -419,7 +419,7 @@ function scenario_decision_dispatch!(decision_function!::Function, scenarioproblems::DistributedScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer, - args...) where N + args...) set_in_scenarioproblem!(scenarioproblems, scenario_index, decision_function!, index, args...) do sp, i, decision_function!, index, args... subprob = fetch(sp).problems[i] dref = DecisionRef(subprob, index) @@ -558,11 +558,11 @@ end # Getters # # ========================== # -function decision(scenarioproblems::ScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer) where N +function decision(scenarioproblems::ScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer) subprob = subproblem(scenarioproblems, scenario_index) return decision(DecisionRef(subprob, index)) end -function decision(scenarioproblems::DistributedScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer) where N +function decision(scenarioproblems::DistributedScenarioProblems, index::MOI.VariableIndex, scenario_index::Integer) return get_from_scenarioproblem(scenarioproblems, scenario_index, index) do sp, i, index subprob = fetch(sp).problems[i] return decision(DecisionRef(subprob, index)) diff --git a/test/decisions/decision_expressions.jl b/test/decisions/decision_expressions.jl index 860aa27..0cab369 100644 --- a/test/decisions/decision_expressions.jl +++ b/test/decisions/decision_expressions.jl @@ -24,10 +24,8 @@ using StochasticPrograms using Test -using MathOptInterface -const MOI = MathOptInterface -const MOIU = MOI.Utilities -const MA = MOI.MutableArithmetics +import MathOptInterface as MOI +import MutableArithmetics as MA function DecisionModel() m = Model() diff --git a/test/decisions/decision_functions.jl b/test/decisions/decision_functions.jl index 83147af..e175169 100644 --- a/test/decisions/decision_functions.jl +++ b/test/decisions/decision_functions.jl @@ -24,10 +24,9 @@ using StochasticPrograms using Test -using MathOptInterface -const MOI = MathOptInterface +import MathOptInterface as MOI const MOIU = MOI.Utilities -const MA = MOI.MutableArithmetics +import MutableArithmetics as MA function test_vectorization(x, fx, y, fy, z, fz, w, fw) g = VectorAffineDecisionFunction( diff --git a/test/decisions/decision_operators.jl b/test/decisions/decision_operators.jl index 3c44fed..11788e5 100644 --- a/test/decisions/decision_operators.jl +++ b/test/decisions/decision_operators.jl @@ -25,10 +25,8 @@ using StochasticPrograms using Test using LinearAlgebra -using MathOptInterface -const MOI = MathOptInterface -const MOIU = MOI.Utilities -const MA = MOI.MutableArithmetics +import MathOptInterface as MOI +import MutableArithmetics as MA function DecisionModel() m = Model()