Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Aug 29, 2024
1 parent a028b84 commit 13e7d40
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 44 deletions.
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ makedocs(
sitename = "CUTEst.jl",
pages = [
"Home" => "index.md",
"SIF decoder" => "sifdecoder.md",
"CUTEstModel" => "model.md",
"Tutorial" => "tutorial.md",
"CUTEstModel" => "model.md",
"SIF decoder" => "sifdecoder.md",
"Core" => "core.md",
"Reference" => "reference.md",
],
Expand Down
5 changes: 2 additions & 3 deletions docs/src/model.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## CUTEstModel

The main goal of `CUTEst.jl` is to create `CUTEstModel` that rely on the [API](https://jso.dev/NLPModels.jl/stable/api/) of NLPModels.jl.
The main goal of `CUTEst.jl` is to create a `CUTEstModel`, which rely on the
[API](https://jso.dev/NLPModels.jl/stable/api/) provided by `NLPModels.jl`.

```@docs
CUTEstModel
Expand Down
2 changes: 1 addition & 1 deletion docs/src/sifdecoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build_libsif
!!! note
When creating a `CUTEstModel`, the functions `sifdecoder` and `build_libsif` are called automatically.

These additional files are generated in the `deps/files` folder at the root of the `CUTEst.jl` installation directory.
These additional files are generated in the folder `deps/files` at the root of the installation directory of `CUTEst.jl` .
The path to this folder is available via `CUTEst.libsif_path`.
We provide two functions to delete these files:

Expand Down
4 changes: 2 additions & 2 deletions src/CUTEst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export CUTEstModel, sifdecoder, build_libsif, set_mastsif, clear_libsif, manage_

const cutest_false = Ref{Bool}(false)
const cutest_true = Ref{Bool}(true)
const libsif_path = joinpath(dirname(@__FILE__), "..", "deps", "files")
const libsif_path = joinpath(@__DIR__, "..", "deps", "files") |> normpath
isdir(libsif_path) || mkpath(libsif_path)

function __init__()
Expand All @@ -36,7 +36,7 @@ function __init__()
@info "Call set_mastsif() if you want to use the full SIF collection."
end

global libpath = joinpath(CUTEst_jll.artifact_dir, "lib")
global libcutest_path = joinpath(CUTEst_jll.artifact_dir, "lib")
push!(Libdl.DL_LOAD_PATH, libsif_path)
end

Expand Down
56 changes: 26 additions & 30 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,40 @@ mutable struct CUTEstModel{T} <: AbstractNLPModel{T, Vector{T}}
end

"""
nlp = CUTEstModel{T}(name, args...; kwargs...)
nlp = CUTEstModel(name, args...; kwargs...)
CUTEstModel{T}(name, args...; kwargs...)
CUTEstModel(name, args...; precision::Symbol=:double, decode::Bool=true,
verbose::Bool=false, efirst::Bool=true, lfirst::Bool=true, lvfirst::Bool=true)
Creates a CUTEst model following the NLPModels API.
This model needs to be finalized before a new one is created (e.g., calling `finalize(nlp)`).
Creates a `CUTEstModel` following the API of `NLPModels.jl`.
This model must be finalized before creating a new one with the same `name` and precision `T`.
Finalize the current model by calling `finalize(nlp)` to avoid conflicts.
## Optional arguments
## Arguments
Any extra arguments will be passed to `sifdecoder`.
You can, for instance, change parameters of the model:
- `name::AbstractString`: The name of the SIF problem to load.
- `args...`: Additional arguments passed directly to `sifdecoder`. These can be used to change parameters of the model.
```jldoctest
using CUTEst
## Keyword arguments
nlp = CUTEstModel("CHAIN", "-param", "NH=50")
println(nlp.meta.nnzh)
finalize(nlp)
nlp = CUTEstModel("CHAIN", "-param", "NH=100")
println(nlp.meta.nnzh)
finalize(nlp)
- `precision::Symbol`: Specifies the precision of the `CUTEstModel`. Options are `:single`, `:double` (default), or `:quadruple`. This keyword argument is not supported when using a constructor with a data type `T`.
- `decode::Bool`: Whether to call `sifdecoder`. Defaults to `true`.
- `verbose::Bool`: If `true`, enables verbose output during the decoding process. Passed to `sifdecoder`.
- `efirst::Bool`: If `true`, places equality constraints first.
- `lfirst::Bool`: If `true`, places linear (or affine) constraints first.
- `lvfirst::Bool`: If `true`, places nonlinear variables first.
# output
```julia
using CUTEst
# Create a CUTEstModel with the name "CHAIN" and a parameter adjustment
nlp = CUTEstModel("CHAIN", "-param", "NH=50")
display(nlp)
finalize(nlp) # Finalize the current model
153
303
# Create another CUTEstModel with different parameters
nlp = CUTEstModel("CHAIN", "-param", "NH=100")
display(nlp)
finalize(nlp) # Finalize the new model
```
## Keyword arguments
- `precision::Symbol = :double` : Precision of the CUTEstModel.
- `decode::Bool = true`: Whether to call sifdecoder.
- `verbose::Bool = false`: Passed to sifdecoder.
- `efirst`::Bool = true`: Equalities first?
- `lfirst`::Bool = true`: Linear (or affine) constraints first?
- `lvfirst::Bool = true`: Nonlinear variables should appear first?
The keyword `precision` is not supported when a constructor with a data type `T` is used.
The type `T` can be `Float32`, `Float64`, or `Float128`.
"""
function CUTEstModel end

Expand Down
12 changes: 6 additions & 6 deletions src/sifdecoder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ function build_libsif(
end
if Sys.isapple()
if VERSION < v"1.10"
libcutest = joinpath(libpath, "lib$library.$dlext")
libcutest = joinpath(libcutest_path, "lib$library.$dlext")
run(
`gfortran -dynamiclib -o $(libsif_name).$dlext $(object_files) -Wl,-rpath,$libpath $libcutest`,
`gfortran -dynamiclib -o $(libsif_name).$dlext $(object_files) -Wl,-rpath,$(libcutest_path) $libcutest`,
)
else
libcutest = joinpath(libpath, "lib$library.a")
libcutest = joinpath(libcutest_path, "lib$library.a")
run(
`gfortran -dynamiclib -o $(libsif_name).$dlext $(object_files) -Wl,-all_load $libcutest`,
)
Expand All @@ -191,7 +191,7 @@ function build_libsif(
@static if Sys.iswindows()
mingw = Int == Int64 ? "mingw64" : "mingw32"
gfortran = joinpath(artifact"mingw-w64", mingw, "bin", "gfortran.exe")
libcutest = joinpath(libpath, "lib$library.a")
libcutest = joinpath(libcutest_path, "lib$library.a")
run(
`$gfortran -shared -o $(libsif_name).$dlext $(object_files) -Wl,--whole-archive $libcutest -Wl,--no-whole-archive`,
)
Expand All @@ -200,10 +200,10 @@ function build_libsif(
if VERSION < v"1.10"
libgfortran = strip(read(`gfortran --print-file libgfortran.so`, String))
run(
`ld -shared -o $(libsif_name).$dlext $(object_files) -rpath=$libpath -L$libpath -l$library $libgfortran`,
`ld -shared -o $(libsif_name).$dlext $(object_files) -rpath=$(libcutest_path) -L$(libcutest_path) -l$library $libgfortran`,
)
else
libcutest = joinpath(libpath, "lib$library.a")
libcutest = joinpath(libcutest_path, "lib$library.a")
run(
`gfortran -shared -o $(libsif_name).$dlext $(object_files) -Wl,--whole-archive $libcutest -Wl,--no-whole-archive`,
)
Expand Down

0 comments on commit 13e7d40

Please sign in to comment.