Skip to content

Commit

Permalink
Backend API Refinements (infiniteopt#351)
Browse files Browse the repository at this point in the history
* change object number terminology

* many improvements

* remove set_names_on_creation
  • Loading branch information
pulsipher authored Jul 10, 2024
1 parent db449cc commit e92a60b
Show file tree
Hide file tree
Showing 57 changed files with 1,760 additions and 1,519 deletions.
29 changes: 3 additions & 26 deletions docs/src/develop/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,22 +755,14 @@ extended using the following steps:
5. If appropriate and NOT a [`JuMPBackend`](@ref), extend the following:
- [`transformation_model`](@ref transformation_model(::AbstractTransformationBackend))
- [`transformation_data`](@ref transformation_data(::AbstractTransformationBackend))
- [`JuMP.set_attribute`](@ref JuMP.set_attribute(::AbstractTransformationBackend, ::Any, ::Any))
- [`JuMP.get_attribute`](@ref JuMP.get_attribute(::AbstractTransformationBackend, ::Any))
- [`JuMP.set_attribute`](@ref JuMP.set_attribute(::AbstractTransformationBackend, ::Any, ::Any)) (including the suggested attributes)
- [`JuMP.get_attribute`](@ref JuMP.get_attribute(::AbstractTransformationBackend, ::Any)) (including the suggested attributes)
- [`JuMP.optimize!`](@ref JuMP.optimize!(::AbstractTransformationBackend))
- [`JuMP.set_optimizer`](@ref JuMP.set_optimizer(::AbstractTransformationBackend, ::Any))
- [`JuMP.set_silent`](@ref JuMP.set_silent(::AbstractTransformationBackend))
- [`JuMP.unset_silent`](@ref JuMP.unset_silent(::AbstractTransformationBackend))
- [`JuMP.set_time_limit_sec`](@ref JuMP.set_time_limit_sec(::AbstractTransformationBackend, ::Any))
- [`JuMP.time_limit_sec`](@ref JuMP.time_limit_sec(::AbstractTransformationBackend))
- [`JuMP.unset_time_limit_sec`](@ref JuMP.unset_time_limit_sec(::AbstractTransformationBackend))
- [`JuMP.solver_name`](@ref JuMP.solver_name(::AbstractTransformationBackend))
- [`JuMP.bridge_constraints`](@ref JuMP.bridge_constraints(::AbstractTransformationBackend))
- [`JuMP.add_bridge`](@ref JuMP.add_bridge(::AbstractTransformationBackend, ::Any))
- [`JuMP.print_active_bridges`](@ref JuMP.print_active_bridges(::IO,::AbstractTransformationBackend))
- [`JuMP.print_active_bridges`](@ref JuMP.print_active_bridges(::IO,::AbstractTransformationBackend))
- [`JuMP.set_string_names_on_creation`](@ref JuMP.set_string_names_on_creation(::AbstractTransformationBackend))
- [`JuMP.set_string_names_on_creation`](@ref JuMP.set_string_names_on_creation(::AbstractTransformationBackend, ::Any))
- [`JuMP.compute_conflict!`](@ref JuMP.compute_conflict!(::AbstractTransformationBackend))
- [`JuMP.copy_conflict`](@ref JuMP.copy_conflict(::AbstractTransformationBackend))
- [`JuMP.mode`](@ref JuMP.mode(::AbstractTransformationBackend))
Expand All @@ -785,21 +777,7 @@ extended using the following steps:
- [`InfiniteOpt.expression_supports`](@ref)
- [`InfiniteOpt.constraint_supports`](@ref)
8. As appropriate and if NOT a `JuMPBackend`, extend the following:
- [`JuMP.termination_status`](@ref JuMP.termination_status(::AbstractTransformationBackend))
- [`JuMP.raw_status`](@ref JuMP.raw_status(::AbstractTransformationBackend))
- [`JuMP.solve_time`](@ref JuMP.solve_time(::AbstractTransformationBackend))
- [`JuMP.simplex_iterations`](@ref JuMP.simplex_iterations(::AbstractTransformationBackend))
- [`JuMP.barrier_iterations`](@ref JuMP.barrier_iterations(::AbstractTransformationBackend))
- [`JuMP.node_count`](@ref JuMP.node_count(::AbstractTransformationBackend))
- [`JuMP.objective_bound`](@ref JuMP.objective_bound(::AbstractTransformationBackend))
- [`JuMP.relative_gap`](@ref JuMP.relative_gap(::AbstractTransformationBackend))
- [`JuMP.result_count`](@ref JuMP.result_count(::AbstractTransformationBackend))
- [`JuMP.primal_status`](@ref JuMP.primal_status(::AbstractTransformationBackend))
- [`JuMP.dual_status`](@ref JuMP.dual_status(::AbstractTransformationBackend))
- [`JuMP.has_values`](@ref JuMP.has_values(::AbstractTransformationBackend))
- [`JuMP.has_duals`](@ref JuMP.has_duals(::AbstractTransformationBackend))
- [`JuMP.objective_value`](@ref JuMP.objective_value(::AbstractTransformationBackend))
- [`JuMP.dual_objective_value`](@ref JuMP.dual_objective_value(::AbstractTransformationBackend))
- The remaining result related attributes listed in [`JuMP.get_attribute`](@ref JuMP.get_attribute(::AbstractTransformationBackend, ::Any))
- [`JuMP.lp_sensitivity_report`](@ref JuMP.lp_sensitivity_report(::AbstractTransformationBackend))
9. If Step 6 was skipped and/or the backend is NOT a `JuMPBackend` then extend the following:
- [`InfiniteOpt.map_value`](@ref) (enables `JuMP.value`)
Expand Down Expand Up @@ -1067,7 +1045,6 @@ are enabled via Step 6 where we extend:
- [`transformation_variable`](@ref transformation_variable(::GeneralVariableRef, ::AbstractTransformationBackend))
- [`transformation_expression`](@ref transformation_expression(::Any, ::AbstractTransformationBackend))
- [`transformation_constraint`](@ref transformation_constraint(::InfOptConstraintRef, ::AbstractTransformationBackend))
[`transformation_expression`](@ref), and [`transformation_constraint`](@ref)
to return the variable(s)/expression(s)/constraint(s) in the backend.
These will use the `DeterministicData` and should error if no mapping can be
found.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guide/derivative.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```@meta
DocTestFilters = [r"≥|>=", r" == | = ", r" ∈ | in ", r" for all | ∀ ", r"d|∂",
r"integral|∫", r".*scalar_parameters.jl:790"]
r"integral|∫", r".*scalar_parameters.jl:785"]
```

# [Derivative Operators](@id deriv_docs)
Expand Down Expand Up @@ -503,7 +503,7 @@ julia> derivative_constraints(d1)
julia> add_supports(t, 0.2)
┌ Warning: Support/method changes will invalidate existing derivative evaluation constraints that have been added to the InfiniteModel. Thus, these are being deleted.
└ @ InfiniteOpt ~/work/infiniteopt/InfiniteOpt.jl/src/scalar_parameters.jl:790
└ @ InfiniteOpt ~/work/infiniteopt/InfiniteOpt.jl/src/scalar_parameters.jl:785
julia> has_derivative_constraints(d1)
false
Expand Down
14 changes: 2 additions & 12 deletions docs/src/manual/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ supports(::InfOptConstraintRef)
JuMP.set_optimizer(::InfiniteModel, ::Any)
JuMP.set_silent(::InfiniteModel)
JuMP.unset_silent(::InfiniteModel)
JuMP.set_time_limit_sec(::InfiniteModel, ::Any)
JuMP.set_time_limit_sec(::InfiniteModel, ::Real)
JuMP.unset_time_limit_sec(::InfiniteModel)
JuMP.time_limit_sec(::InfiniteModel)
JuMP.solver_name(model::InfiniteModel)
JuMP.mode(::InfiniteModel)
JuMP.compute_conflict!(::InfiniteModel)
JuMP.copy_conflict(::InfiniteModel)
JuMP.set_string_names_on_creation(::InfiniteModel)
JuMP.set_string_names_on_creation(::InfiniteModel, ::Any)
JuMP.bridge_constraints(::InfiniteModel)
JuMP.add_bridge(::InfiniteModel, ::Any)
JuMP.print_active_bridges(::IO, ::InfiniteModel, ::Vararg{Any})
Expand All @@ -57,25 +55,17 @@ Base.empty!(::AbstractTransformationBackend)
build_transformation_backend!(::InfiniteModel, ::AbstractTransformationBackend)
JuMP.optimize!(::AbstractTransformationBackend)
JuMP.set_optimizer(::AbstractTransformationBackend, ::Any)
JuMP.set_silent(::AbstractTransformationBackend)
JuMP.unset_silent(::AbstractTransformationBackend)
JuMP.set_time_limit_sec(::AbstractTransformationBackend, ::Any)
JuMP.unset_time_limit_sec(::AbstractTransformationBackend)
JuMP.time_limit_sec(::AbstractTransformationBackend)
JuMP.solver_name(model::AbstractTransformationBackend)
JuMP.mode(::AbstractTransformationBackend)
JuMP.compute_conflict!(::AbstractTransformationBackend)
JuMP.copy_conflict(::AbstractTransformationBackend)
JuMP.set_string_names_on_creation(::AbstractTransformationBackend)
JuMP.set_string_names_on_creation(::AbstractTransformationBackend, ::Any)
JuMP.bridge_constraints(::AbstractTransformationBackend)
JuMP.add_bridge(::AbstractTransformationBackend, ::Any)
JuMP.print_active_bridges(::IO, ::AbstractTransformationBackend, ::Vararg{Any})
JuMP.print_bridge_graph(::IO, ::AbstractTransformationBackend)
JuMP.backend(::AbstractTransformationBackend)
JuMP.unsafe_backend(::AbstractTransformationBackend)
transformation_variable(::GeneralVariableRef, ::AbstractTransformationBackend)
transformation_expression(::JuMP.AbstractJuMPScalar, ::AbstractTransformationBackend)
transformation_expression(::Any, ::AbstractTransformationBackend)
transformation_constraint(::InfOptConstraintRef, ::AbstractTransformationBackend)
variable_supports(::Any, ::AbstractTransformationBackend)
expression_supports(::Any, ::AbstractTransformationBackend)
Expand Down
3 changes: 3 additions & 0 deletions docs/src/manual/constraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ has_domain_restrictions
domain_restrictions
JuMP.normalized_rhs(::InfOptConstraintRef)
JuMP.normalized_coefficient(::InfOptConstraintRef, ::GeneralVariableRef)
parameter_group_int_indices(::InfOptConstraintRef)
core_object(::InfOptConstraintRef)
is_variable_domain_constraint
```

## Modification
Expand Down
2 changes: 2 additions & 0 deletions docs/src/manual/derivative.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ all_derivatives
parameter_refs(::DerivativeRef)
parameter_list(::DerivativeRef)
raw_parameter_refs(::DerivativeRef)
parameter_group_int_indices(::DerivativeRef)
core_object(::DerivativeRef)
```

## Modification
Expand Down
14 changes: 9 additions & 5 deletions docs/src/manual/expression.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ used_by_semi_infinite_variable(::ParameterFunctionRef)
used_by_derivative(::ParameterFunctionRef)
used_by_measure(::ParameterFunctionRef)
used_by_constraint(::ParameterFunctionRef)
parameter_group_int_indices(::ParameterFunctionRef)
```

### Modification
Expand Down Expand Up @@ -57,6 +58,8 @@ parameter_refs(::Union{JuMP.GenericAffExpr, JuMP.GenericNonlinearExpr, JuMP.Gene
restrict(::JuMP.AbstractJuMPScalar)
map_expression
map_expression_to_ast
all_expression_variables
parameter_group_int_indices(::Any)
```

## GeneralVariableRef User Methods
Expand Down Expand Up @@ -158,6 +161,11 @@ JuMP.set_integer(::GeneralVariableRef)
JuMP.IntegerRef(::GeneralVariableRef)
JuMP.unset_integer(::GeneralVariableRef)
constant_over_collocation(::GeneralVariableRef, ::GeneralVariableRef)
core_object
core_object(::GeneralVariableRef)
parameter_group_int_indices(::GeneralVariableRef)
InfiniteOpt.parameter_group_int_index
InfiniteOpt.parameter_group_int_index(::GeneralVariableRef)
```

## Developer Internal Methods
Expand All @@ -166,9 +174,7 @@ InfiniteOpt._add_data_object
InfiniteOpt._data_dictionary
InfiniteOpt._data_object
InfiniteOpt._delete_data_object
InfiniteOpt._core_variable_object
InfiniteOpt._core_variable_object(::GeneralVariableRef)
InfiniteOpt._set_core_variable_object
InfiniteOpt._set_core_object
InfiniteOpt._infinite_variable_dependencies
InfiniteOpt._infinite_variable_dependencies(::GeneralVariableRef)
InfiniteOpt._semi_infinite_variable_dependencies
Expand All @@ -187,6 +193,4 @@ InfiniteOpt._derivative_constraint_dependencies
InfiniteOpt._derivative_constraint_dependencies(::GeneralVariableRef)
InfiniteOpt._parameter_number
InfiniteOpt._parameter_number(::GeneralVariableRef)
InfiniteOpt._object_number
InfiniteOpt._object_number(::GeneralVariableRef)
```
1 change: 1 addition & 0 deletions docs/src/manual/finite_parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ methods available for finite parameters (i.e., any method typed for
parameter_value(::FiniteParameterRef)
JuMP.set_value(::FiniteParameterRef, ::Real)
used_by_objective(::FiniteParameterRef)
core_object(::FiniteParameterRef)
```
2 changes: 2 additions & 0 deletions docs/src/manual/measure.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ used_by_derivative(::MeasureRef)
used_by_constraint(::MeasureRef)
used_by_measure(::MeasureRef)
used_by_objective(::MeasureRef)
core_object(::MeasureRef)
parameter_group_int_indices(::MeasureRef)
```

## Modification
Expand Down
2 changes: 2 additions & 0 deletions docs/src/manual/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ JuMP.object_dictionary(::InfiniteModel)
has_internal_supports
Base.empty!(::InfiniteModel)
JuMP.set_optimize_hook(::InfiniteModel, ::Union{Function, Nothing})
parameter_refs(::InfiniteModel)
parameter_group_indices
```

## Abstract Dependencies
Expand Down
4 changes: 4 additions & 0 deletions docs/src/manual/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ used_by_parameter_function(::IndependentParameterRef)
used_by_derivative(::IndependentParameterRef)
used_by_measure(::ScalarParameterRef)
used_by_constraint(::ScalarParameterRef)
parameter_group_int_index(::IndependentParameterRef)
core_object(::IndependentParameterRef)
```

### Dependent Parameters
Expand All @@ -83,6 +85,8 @@ used_by_parameter_function(::DependentParameterRef)
used_by_derivative(::DependentParameterRef)
used_by_measure(::DependentParameterRef)
used_by_constraint(::DependentParameterRef)
parameter_group_int_index(::DependentParameterRef)
core_object(::DependentParameterRef)
```

## Modification
Expand Down
16 changes: 1 addition & 15 deletions docs/src/manual/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ JuMP.termination_status(::InfiniteModel)
JuMP.raw_status(::InfiniteModel)
JuMP.primal_status(::InfiniteModel)
JuMP.dual_status(::InfiniteModel)
JuMP.is_solved_and_feasible(::InfiniteModel)
```

## General
Expand Down Expand Up @@ -57,25 +58,10 @@ InfOptSensitivityReport

## Transformation Backend Extension API
```@docs
JuMP.termination_status(::AbstractTransformationBackend)
JuMP.raw_status(::AbstractTransformationBackend)
JuMP.primal_status(::AbstractTransformationBackend)
JuMP.dual_status(::AbstractTransformationBackend)
JuMP.solve_time(::AbstractTransformationBackend)
JuMP.relative_gap(::AbstractTransformationBackend)
JuMP.simplex_iterations(::AbstractTransformationBackend)
JuMP.barrier_iterations(::AbstractTransformationBackend)
JuMP.node_count(::AbstractTransformationBackend)
JuMP.result_count(::AbstractTransformationBackend)
JuMP.objective_bound(::AbstractTransformationBackend)
JuMP.objective_value(::AbstractTransformationBackend)
JuMP.dual_objective_value(::AbstractTransformationBackend)
JuMP.has_values(::AbstractTransformationBackend)
map_value(::Any, ::AbstractTransformationBackend)
map_infinite_parameter_value
map_reduced_cost(::GeneralVariableRef, ::AbstractTransformationBackend)
map_optimizer_index(::GeneralVariableRef, ::AbstractTransformationBackend)
JuMP.has_duals(::AbstractTransformationBackend)
map_dual(::InfOptConstraintRef, ::AbstractTransformationBackend)
map_shadow_price(::InfOptConstraintRef, ::AbstractTransformationBackend)
map_optimizer_index(::InfOptConstraintRef, ::AbstractTransformationBackend)
Expand Down
10 changes: 10 additions & 0 deletions docs/src/manual/variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ is_used(::Union{InfiniteVariableRef, DerivativeRef})
used_by_derivative(::Union{DerivativeRef, InfiniteVariableRef})
used_by_point_variable(::Union{InfiniteVariableRef, DerivativeRef})
used_by_semi_infinite_variable(::Union{InfiniteVariableRef, DerivativeRef})
parameter_group_int_indices(::InfiniteVariableRef)
core_object(::InfiniteVariableRef)
```

### Semi-Infinite
Expand All @@ -116,13 +118,21 @@ raw_parameter_refs(::SemiInfiniteVariableRef)
eval_supports(::SemiInfiniteVariableRef)
is_used(::SemiInfiniteVariableRef)
used_by_derivative(::SemiInfiniteVariableRef)
parameter_group_int_indices(::SemiInfiniteVariableRef)
core_object(::SemiInfiniteVariableRef)
```

### Point
```@docs
infinite_variable_ref(::PointVariableRef)
parameter_values(::PointVariableRef)
raw_parameter_values(::PointVariableRef)
core_object(::PointVariableRef)
```

### Finite
```@docs
core_object(::FiniteVariableRef)
```

## Modification
Expand Down
4 changes: 2 additions & 2 deletions src/TranscriptionOpt/measures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function InfiniteOpt.add_point_variable(
inf_model = JuMP.owner_model(ivref)
inf_model_index = get(inf_model.point_lookup, (ivref, support), nothing)
if !isnothing(inf_model_index)
return InfiniteOpt._make_variable_ref(inf_model, inf_model_index)
return InfiniteOpt.GeneralVariableRef(inf_model, inf_model_index)
else
# make negative index to not conflict with the InfiniteModel
raw_index = data.last_point_index -= 1
Expand Down Expand Up @@ -66,7 +66,7 @@ function InfiniteOpt.add_semi_infinite_variable(
inf_model = JuMP.owner_model(ivref)
inf_model_index = get(inf_model.semi_lookup, (ivref, eval_supps), nothing)
if !isnothing(inf_model_index)
return InfiniteOpt._make_variable_ref(inf_model, inf_model_index)
return InfiniteOpt.GeneralVariableRef(inf_model, inf_model_index)
else
# make negative index to not conflict with the InfiniteModel
semi_infinite_vars = data.semi_infinite_vars
Expand Down
Loading

0 comments on commit e92a60b

Please sign in to comment.