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
70 changes: 0 additions & 70 deletions docs/src/submodules/Utilities/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,76 +318,6 @@ $$ \begin{aligned}
In IJulia, calling `print` or ending a cell with
[`Utilities.latex_formulation`](@ref) will render the model in LaTex.

## Allocate-Load

The Allocate-Load API allows solvers that do not support loading the problem
incrementally to implement [`copy_to`](@ref) in a way that still allows
transformations to be applied in the copy between the cache and the
model if the transformations are implemented as MOI layers implementing the
Allocate-Load API.

Loading a model using the Allocate-Load interface consists of two passes
through the model data:
1) the _allocate_ pass where the model typically records the necessary
information about the constraints and attributes such as their number and
size. This information may be used by the solver to allocate datastructures
of appropriate size.
2) the _load_ pass where the model typically loads the constraint and attribute
data to the model.

The description above only gives a suggestion of what to achieve in each pass.
In fact the exact same constraint and attribute data is provided to each pass,
so an implementation of the Allocate-Load API is free to do whatever is more
convenient in each pass.

The main difference between each pass, apart from the fact that one is executed
before the other during a copy, is that the allocate pass needs to create and
return new variable and constraint indices, while during the load pass the
appropriate constraint indices are provided.

If you choose to implement the Allocate-Load API, implement the following
functions, which will be called in order:

**Allocate**

* [`Utilities.allocate_variables`](@ref)
* [`Utilities.allocate_constrained_variable`](@ref)
* [`Utilities.allocate_constrained_variables`](@ref)
* [`Utilities.allocate`](@ref)
* [`Utilities.allocate_constraint`](@ref)

**Load**

* [`Utilities.load_variables`](@ref)
* [`Utilities.load_constrained_variable`](@ref)
* [`Utilities.load_constrained_variables`](@ref)
* [`Utilities.load`](@ref)
* [`Utilities.load_constraint`](@ref)

Note that the `_constrained_variable` functions are optional, and are only
needed if the solver requires variables be constrained on creation.

You must also implement:
```julia
function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike; kwargs...)
return MOI.Utilities.automatic_copy_to(dest, src; kwargs...)
end

function MOI.Utilities.supports_allocate_load(
model::Optimizer,
copy_names::Bool,
)
# If you support names...
return true
# Otherwise...
return !copy_names
end
```
See [`Utilities.supports_allocate_load`](@ref) for more details.

!!! warning
The Allocate-Load API should **not** be used outside [`copy_to`](@ref).

## Utilities.MatrixOfConstraints

The constraints of [`Utilities.Model`](@ref) are stored as a vector of tuples
Expand Down
17 changes: 0 additions & 17 deletions docs/src/submodules/Utilities/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,6 @@ Utilities.IndexMap
Utilities.identity_index_map
```

### [Allocate-Load API](@id allocate_load_api_ref)

```@docs
Utilities.allocate_load
Utilities.supports_allocate_load
Utilities.allocate_variables
Utilities.allocate_constrained_variable
Utilities.allocate_constrained_variables
Utilities.allocate
Utilities.allocate_constraint
Utilities.load_variables
Utilities.load_constrained_variable
Utilities.load_constrained_variables
Utilities.load
Utilities.load_constraint
```

## MatrixOfConstraints

```@docs
Expand Down
4 changes: 0 additions & 4 deletions docs/src/tutorials/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,6 @@ To implement the [`copy_to`](@ref) interface, implement the following function:

* [`copy_to`](@ref)

!!! tip
An alternative is to use the Utilities submodule to implement the
[Allocate-Load] API.

### The incremental interface

!!! warning
Expand Down
17 changes: 6 additions & 11 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
filter_constraints::Union{Nothing,Function} = nothing,
)

Use [`MathOptInterface.supports_incremental_interface`](@ref) and
[`Utilities.supports_allocate_load`](@ref) to automatically choose between
[`Utilities.default_copy_to`](@ref) or [`Utilities.allocate_load`](@ref) to
apply the copy operation.
A default fallback for [`MOI.copy_to`](@ref).

To use this method, define
[`MathOptInterface.supports_incremental_interface`](@ref).

If the `filter_constraints` arguments is given, only the constraints for which
this function returns `true` will be copied. This function is given a
Expand All @@ -24,17 +24,14 @@ function automatic_copy_to(
copy_names::Bool = true,
filter_constraints::Union{Nothing,Function} = nothing,
)
if MOI.supports_incremental_interface(dest, copy_names)
return default_copy_to(dest, src, copy_names, filter_constraints)
elseif supports_allocate_load(dest, copy_names)
return allocate_load(dest, src, copy_names, filter_constraints)
else
if !MOI.supports_incremental_interface(dest, copy_names)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could argue whether we want to simplify this now and just having the fallback

copy_to(...) = default_copy_to(...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Let's merge this first and then re-assess all the copy stuff.

error(
"Model $(typeof(dest)) does not support copy",
copy_names ? " with names" : "",
".",
)
end
return default_copy_to(dest, src, copy_names, filter_constraints)
end

@deprecate supports_default_copy_to MOI.supports_incremental_interface
Expand Down Expand Up @@ -662,5 +659,3 @@ function default_copy_to(

return idxmap
end

include("copy/allocate_load.jl")
Loading