Skip to content
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
2 changes: 1 addition & 1 deletion src/common_models/add_param_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/common_models/add_param_container_shims.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...;
Expand Down
17 changes: 10 additions & 7 deletions src/core/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}()

Expand All @@ -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.
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/core/model_internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions src/core/optimization_problem_outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/core/outputs_by_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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])
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/parameter_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/core/settings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)\".",
),
)
Expand Down
6 changes: 3 additions & 3 deletions src/objective_function/objective_function_pwl_lambda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ end

function _determine_bin_lhs(
container::OptimizationContainer,
sos_status::SOSStatusVariable,
sos_status::SOSStatusVariable.Value,
::Type{T},
name::String,
period::Int;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/operation/optimization_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/jump_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading