diff --git a/src/common_models/add_param_container.jl b/src/common_models/add_param_container.jl index 088b4d89..35e716d9 100644 --- a/src/common_models/add_param_container.jl +++ b/src/common_models/add_param_container.jl @@ -57,7 +57,7 @@ function add_cost_function_parameter_container!( ::Type{U}, variable_types::Tuple{Vararg{Type}}, axs...; - sos_variable::SOSStatusVariable = SOSStatusVariable.NO_VARIABLE, + sos_variable::SOSStatusVariable.Value = SOSStatusVariable.NO_VARIABLE, uses_compact_power::Bool = false, data_type::DataType = Float64, sparse = false, diff --git a/src/common_models/add_param_container_shims.jl b/src/common_models/add_param_container_shims.jl index 573b1fc8..1feb8c47 100644 --- a/src/common_models/add_param_container_shims.jl +++ b/src/common_models/add_param_container_shims.jl @@ -38,7 +38,7 @@ add_param_container!( ::Type{T}, ::Type{U}, variable_types::Tuple{Vararg{Type}}, - sos_variable::SOSStatusVariable = SOSStatusVariable.NO_VARIABLE, + sos_variable::SOSStatusVariable.Value = SOSStatusVariable.NO_VARIABLE, uses_compact_power::Bool = false, data_type::DataType = Float64, axs...; diff --git a/src/core/definitions.jl b/src/core/definitions.jl index ee97ae64..811721ea 100644 --- a/src/core/definitions.jl +++ b/src/core/definitions.jl @@ -172,7 +172,9 @@ Format used to export the optimization model to disk on each solve. - `MOF`: Export to MathOptFormat (`.json`). """ OptimizationModelExportFormat -const ENUMS = (ModelBuildStatus, SimulationBuildStatus, RunStatus, SOSStatusVariable) +const ENUMS = + (ModelBuildStatus.Value, SimulationBuildStatus.Value, RunStatus.Value, + SOSStatusVariable.Value) const ENUM_MAPPINGS = Dict{DataType, Dict{String, Any}}() @@ -184,8 +186,8 @@ for enum in ENUMS end # Special cases for backwards compatibility -ENUM_MAPPINGS[RunStatus]["ready"] = RunStatus.INITIALIZED -ENUM_MAPPINGS[RunStatus]["successful"] = RunStatus.SUCCESSFULLY_FINALIZED +ENUM_MAPPINGS[RunStatus.Value]["ready"] = RunStatus.INITIALIZED +ENUM_MAPPINGS[RunStatus.Value]["successful"] = RunStatus.SUCCESSFULLY_FINALIZED """ Get the enum value for the string. Case insensitive. @@ -203,10 +205,11 @@ function get_enum_value(enum, value::String) return ENUM_MAPPINGS[enum][val] end -# Base.convert(::Type{SimulationBuildStatus}, val::String) = +# Base.convert(::Type{SimulationBuildStatus.Value}, val::String) = # get_enum_value(SimulationBuildStatus, val) -# Base.convert(::Type{ModelBuildStatus}, val::String) = get_enum_value(ModelBuildStatus, val) -# Base.convert(::Type{RunStatus}, val::String) = get_enum_value(RunStatus, val) -Base.convert(::Type{SOSStatusVariable}, x::String) = get_enum_value(SOSStatusVariable, x) +# Base.convert(::Type{ModelBuildStatus.Value}, val::String) = get_enum_value(ModelBuildStatus, val) +# Base.convert(::Type{RunStatus.Value}, val::String) = get_enum_value(RunStatus, val) +Base.convert(::Type{SOSStatusVariable.Value}, x::String) = + get_enum_value(SOSStatusVariable.Value, x) const SYSTEM_TYPE = IS.ComponentContainer diff --git a/src/core/model_internal.jl b/src/core/model_internal.jl index aae762a9..6748fee6 100644 --- a/src/core/model_internal.jl +++ b/src/core/model_internal.jl @@ -4,7 +4,7 @@ Common structure to keep track of optimization models' internal information. mutable struct ModelInternal{T <: AbstractOptimizationContainer} container::T initial_conditions_model_container::Union{Nothing, T} - status::ModelBuildStatus + status::ModelBuildStatus.Value base_conversion::Bool executions::Int execution_count::Int @@ -75,7 +75,7 @@ function set_initial_conditions_model_container!( return end -function set_status!(internal::ModelInternal, status::ModelBuildStatus) +function set_status!(internal::ModelInternal, status::ModelBuildStatus.Value) internal.status = status return end diff --git a/src/core/optimization_problem_outputs.jl b/src/core/optimization_problem_outputs.jl index e0e28994..c03aede1 100644 --- a/src/core/optimization_problem_outputs.jl +++ b/src/core/optimization_problem_outputs.jl @@ -386,7 +386,7 @@ function _read_outputs( time_ids, base_power::Float64, base_timestamps::Vector{Dates.DateTime}, - table_format::TableFormat, + table_format::TableFormat.Value, ) existing_keys = keys(output_values) container_keys = container_keys === nothing ? existing_keys : container_keys @@ -504,7 +504,7 @@ Accepts a vector of keys for the return of the values. and device type for the desired outputs - `start_time::Dates.DateTime`: Start time of the requested outputs - `len::Int`: length of outputs -- `table_format::TableFormat`: Format of the table to be returned. Default is +- `table_format::TableFormat.Value`: Format of the table to be returned. Default is `TableFormat.LONG` where the columns are `DateTime`, `name`, and `value` when the data has two dimensions and `DateTime`, `name`, `name2`, and `value` when the data has three dimensions. @@ -529,7 +529,7 @@ function read_variable( key::VariableKey; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) return read_outputs_with_keys( res, @@ -571,7 +571,7 @@ function read_variables( variables::Vector{<:OptimizationContainerKey}; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) output_values = read_outputs_with_keys( @@ -619,7 +619,7 @@ function read_dual( key::ConstraintKey; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) return read_outputs_with_keys( res, @@ -661,7 +661,7 @@ function read_duals( duals::Vector{<:OptimizationContainerKey}; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) output_values = read_outputs_with_keys( res, @@ -708,7 +708,7 @@ function read_parameter( key::ParameterKey; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) return read_outputs_with_keys( res, @@ -750,7 +750,7 @@ function read_parameters( parameters::Vector{<:OptimizationContainerKey}; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) output_values = read_outputs_with_keys( @@ -799,7 +799,7 @@ function read_aux_variable( key::AuxVarKey; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) return read_outputs_with_keys( res, @@ -841,7 +841,7 @@ function read_aux_variables( aux_variables::Vector{<:OptimizationContainerKey}; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) output_values = read_outputs_with_keys( @@ -891,7 +891,7 @@ function read_expression( key::ExpressionKey; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) return read_outputs_with_keys( res, @@ -937,7 +937,7 @@ function read_expressions( expressions::Vector{<:OptimizationContainerKey}; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) output_values = read_outputs_with_keys( @@ -962,7 +962,7 @@ function read_outputs_with_keys( output_keys::Vector{<:OptimizationContainerKey}; start_time::Union{Nothing, Dates.DateTime} = nothing, len::Union{Int, Nothing} = nothing, - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) isempty(output_keys) && return Dict{OptimizationContainerKey, DataFrame}() (timestamp_ids, timestamps) = _process_timestamps(res, start_time, len) diff --git a/src/core/outputs_by_time.jl b/src/core/outputs_by_time.jl index e7256890..9b1a3722 100644 --- a/src/core/outputs_by_time.jl +++ b/src/core/outputs_by_time.jl @@ -125,7 +125,7 @@ end function make_dataframe( outputs::OutputsByTime{DenseAxisArray{Float64, 2}}, timestamp::Dates.DateTime; - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) array = outputs.data[timestamp] timestamps = _get_timestamps(outputs, timestamp, get_num_rows(outputs, array)) @@ -135,7 +135,7 @@ end function make_dataframe( outputs::OutputsByTime{DenseAxisArray{Float64, 3}}, timestamp::Dates.DateTime; - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) array = outputs.data[timestamp] num_timestamps = get_num_rows(outputs, array) @@ -146,7 +146,7 @@ end function make_dataframe( outputs::OutputsByTime{Matrix{Float64}}, timestamp::Dates.DateTime; - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) array = outputs.data[timestamp] df_wide = DataFrames.DataFrame(array, outputs.column_names[1]) @@ -168,7 +168,7 @@ end function make_dataframes( outputs::OutputsByTime; - table_format::TableFormat = TableFormat.LONG, + table_format::TableFormat.Value = TableFormat.LONG, ) return SortedDict( k => make_dataframe(outputs, k; table_format = table_format) for diff --git a/src/core/parameter_container.jl b/src/core/parameter_container.jl index 9b23ce3a..87a320ec 100644 --- a/src/core/parameter_container.jl +++ b/src/core/parameter_container.jl @@ -72,7 +72,7 @@ get_attribute_key(attr::VariableValueAttributes) = attr.attribute_key struct CostFunctionAttributes{T} <: ParameterAttributes variable_types::Tuple{Vararg{Type}} - sos_status::SOSStatusVariable + sos_status::SOSStatusVariable.Value uses_compact_power::Bool end diff --git a/src/core/settings.jl b/src/core/settings.jl index 89d1e15d..aee0f6a0 100644 --- a/src/core/settings.jl +++ b/src/core/settings.jl @@ -17,7 +17,7 @@ struct Settings export_pwl_vars::Bool allow_fails::Bool rebuild_model::Bool - export_optimization_model::OptimizationModelExportFormat + export_optimization_model::OptimizationModelExportFormat.Value store_variable_names::Bool system_to_file::Bool check_numerical_bounds::Bool @@ -35,18 +35,18 @@ function _wrap_optimizer(opt) ) end -_validate_export_optimization_model(value::OptimizationModelExportFormat) = value +_validate_export_optimization_model(value::OptimizationModelExportFormat.Value) = value function _validate_export_optimization_model(value::AbstractString) name = uppercase(strip(value)) isempty(name) && return OptimizationModelExportFormat.NONE - for fmt in instances(OptimizationModelExportFormat) + for fmt in instances(OptimizationModelExportFormat.Value) string(fmt) == name && return fmt end throw( IS.ConflictingInputsError( "export_optimization_model must be one of " * - join(string.(instances(OptimizationModelExportFormat)), ", ") * + join(string.(instances(OptimizationModelExportFormat.Value)), ", ") * "; got \"$(value)\".", ), ) diff --git a/src/objective_function/objective_function_pwl_lambda.jl b/src/objective_function/objective_function_pwl_lambda.jl index d8528141..dcc15d3a 100644 --- a/src/objective_function/objective_function_pwl_lambda.jl +++ b/src/objective_function/objective_function_pwl_lambda.jl @@ -123,7 +123,7 @@ end function _determine_bin_lhs( container::OptimizationContainer, - sos_status::SOSStatusVariable, + sos_status::SOSStatusVariable.Value, ::Type{T}, name::String, period::Int; @@ -160,7 +160,7 @@ function _add_pwl_constraint_standard!( container::OptimizationContainer, component::T, break_points::Vector{Float64}, - sos_status::SOSStatusVariable, + sos_status::SOSStatusVariable.Value, period::Int, power_var::JuMP.VariableRef, must_run::Bool = false, @@ -217,7 +217,7 @@ function _add_pwl_constraint_compact!( ::T, name::String, break_points::Vector{Float64}, - sos_status::SOSStatusVariable, + sos_status::SOSStatusVariable.Value, period::Int, power_var::JuMP.VariableRef, P_min::Float64, diff --git a/src/operation/optimization_model_interface.jl b/src/operation/optimization_model_interface.jl index 97f3a171..9af3d655 100644 --- a/src/operation/optimization_model_interface.jl +++ b/src/operation/optimization_model_interface.jl @@ -197,7 +197,7 @@ function set_simulation_info!(model::AbstractOptimizationModel, val) return end -function set_status!(model::AbstractOptimizationModel, status::ModelBuildStatus) +function set_status!(model::AbstractOptimizationModel, status::ModelBuildStatus.Value) set_status!(get_internal(model), status) return end @@ -383,7 +383,7 @@ wait_for_serialization!(model::AbstractOptimizationModel) = function serialize_optimization_model( model::AbstractOptimizationModel, save_path::String, - fmt::OptimizationModelExportFormat, + fmt::OptimizationModelExportFormat.Value, ) container = get_optimization_container(model) dest = _copy_jump_model_for_export(get_jump_model(container), fmt) diff --git a/src/utils/jump_utils.jl b/src/utils/jump_utils.jl index fca14cb7..91161c24 100644 --- a/src/utils/jump_utils.jl +++ b/src/utils/jump_utils.jl @@ -256,7 +256,7 @@ Convert a DenseAxisArray containing components to a outputs DataFrame consumable The resulting DataFrame will have the column "DateTime" if timestamps is not nothing. Otherwise, it will have the column "time_index", representing the index of the time dimension. -- `::Val{TableFormat}`: Format of the table to create. +- `::Val{TableFormat.Value}`: Format of the table to create. If it is TableFormat.LONG, the DataFrame will have the column "name", and, if the data has three dimensions, "name2." If it is TableFormat.WIDE, the DataFrame will have columns for each component. Wide @@ -606,7 +606,7 @@ end function _copy_jump_model_for_export( jump_model::JuMP.Model, - fmt::OptimizationModelExportFormat, + fmt::OptimizationModelExportFormat.Value, ) file_format = if fmt == OptimizationModelExportFormat.LP