Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CUTEst.jl for CUTEst v2.3.0 #423

Merged
merged 4 commits into from
Oct 10, 2024
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ SIFDecode_jll = "54dcf436-342f-53ea-8005-3708a1ae6c8c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
CUTEst_jll = "=2.2.5"
CUTEst_jll = "=2.3.0"
Combinatorics = "1.0"
DataStructures = "0.18"
JSON = "0.21"
NLPModels = "0.21.3"
Quadmath = "0.5.10"
SIFDecode_jll = "2.6.0"
SIFDecode_jll = "2.6.1"
julia = "^1.6.0"

[extras]
Expand Down
1 change: 1 addition & 0 deletions docs/src/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ CUTEst.uvartype
CUTEst.fopen
CUTEst.csgrshp
CUTEst.ccfsg
CUTEst.classification
```
10 changes: 10 additions & 0 deletions gen/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ using Clang
using Clang.Generators
using JuliaFormatter

# Support for quadruple precision
struct JuliaCfloat128 <: Clang.Generators.AbstractJuliaSIT end
Clang.Generators.tojulia(x::CLFloat128) = JuliaCfloat128()
Clang.Generators.translate(jlty::JuliaCfloat128, options=Dict()) = :Float128

function main()
cd(@__DIR__)
include_dir = joinpath(CUTEst_jll.artifact_dir, "include")
Expand All @@ -15,6 +20,7 @@ function main()
"integer",
"real",
"doublereal",
"quadreal",
"logical",
"rp_",
"rpc_",
Expand All @@ -40,11 +46,15 @@ function main()
code = replace(code, "Ptr{doublereal}" => "Ptr{Float64}")
code = replace(code, "Ptr{real}" => "Ptr{Float32}")
code = replace(code, "Ptr{doubleCfloat}" => "Ptr{Float64}")
code = replace(code, "Ptr{quadreal}" => "Ptr{Float128}")
code = replace(code, "Ptr{logical}" => "Ptr{Bool}")
code = replace(code, "Ptr{rp_}" => "Ptr{Float64}")
code = replace(code, "Ptr{rpc_}" => "Ptr{Float64}")
code = replace(code, "Ptr{ip_}" => "Ptr{Cint}")
code = replace(code, "Ptr{ipc_}" => "Ptr{Cint}")
for routine in ("classification", "probname", "pname", "varnames", "connames", "unames", "cnames")
code = replace(code, "cutest_cint_$routine" => "cutest_$routine")
end

blocks = split(code, "end\n")
nblocks = length(blocks)
Expand Down
15 changes: 15 additions & 0 deletions src/core_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3212,3 +3212,18 @@ for (cutest_ccf, T) in
end
end
end

"""
classification(T, libsif, status, funit, class)
"""
function classification end

for (cutest_classification, T) in ((:cutest_classification_s_, :Float32),
(:cutest_classification_, :Float64),
(:cutest_classification_q_, :Float128))
@eval begin
function classification(::Type{$T}, libsif::Ptr{Cvoid}, status, funit, class)
$cutest_classification(libsif, status, funit, class)
end
end
end
36 changes: 28 additions & 8 deletions src/libcutest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@
@ccall $ptr_cutest_pname_(status::Ptr{Cint}, funit::Ptr{Cint}, pname::Ptr{Cchar})::Cvoid
end

function cutest_classification_(libsif, status, funit, classification)
ptr_cutest_classification_ = Libdl.dlsym(libsif, :cutest_classification_)
@ccall $ptr_cutest_classification_(status::Ptr{Cint}, funit::Ptr{Cint},

Check warning on line 129 in src/libcutest.jl

View check run for this annotation

Codecov / codecov/patch

src/libcutest.jl#L127-L129

Added lines #L127 - L129 were not covered by tests
classification::Ptr{Cchar})::Cvoid
end

function cutest_probname_(libsif, status, pname)
ptr_cutest_probname_ = Libdl.dlsym(libsif, :cutest_probname_)
@ccall $ptr_cutest_probname_(status::Ptr{Cint}, pname::Ptr{Cchar})::Cvoid
Expand Down Expand Up @@ -670,6 +676,12 @@
@ccall $ptr_cutest_pname_s_(status::Ptr{Cint}, funit::Ptr{Cint}, pname::Ptr{Cchar})::Cvoid
end

function cutest_classification_s_(libsif, status, funit, classification)
ptr_cutest_classification_s_ = Libdl.dlsym(libsif, :cutest_classification_s_)
@ccall $ptr_cutest_classification_s_(status::Ptr{Cint}, funit::Ptr{Cint},

Check warning on line 681 in src/libcutest.jl

View check run for this annotation

Codecov / codecov/patch

src/libcutest.jl#L679-L681

Added lines #L679 - L681 were not covered by tests
classification::Ptr{Cchar})::Cvoid
end

function cutest_probname_s_(libsif, status, pname)
ptr_cutest_probname_s_ = Libdl.dlsym(libsif, :cutest_probname_s_)
@ccall $ptr_cutest_probname_s_(status::Ptr{Cint}, pname::Ptr{Cchar})::Cvoid
Expand Down Expand Up @@ -1222,6 +1234,12 @@
@ccall $ptr_cutest_pname_q_(status::Ptr{Cint}, funit::Ptr{Cint}, pname::Ptr{Cchar})::Cvoid
end

function cutest_classification_q_(libsif, status, funit, classification)
ptr_cutest_classification_q_ = Libdl.dlsym(libsif, :cutest_classification_q_)
@ccall $ptr_cutest_classification_q_(status::Ptr{Cint}, funit::Ptr{Cint},

Check warning on line 1239 in src/libcutest.jl

View check run for this annotation

Codecov / codecov/patch

src/libcutest.jl#L1237-L1239

Added lines #L1237 - L1239 were not covered by tests
classification::Ptr{Cchar})::Cvoid
end

function cutest_probname_q_(libsif, status, pname)
ptr_cutest_probname_q_ = Libdl.dlsym(libsif, :cutest_probname_q_)
@ccall $ptr_cutest_probname_q_(status::Ptr{Cint}, pname::Ptr{Cchar})::Cvoid
Expand All @@ -1246,8 +1264,8 @@

function cutest_cint_uofg_q_(libsif, status, n, x, f, g, grad)
ptr_cutest_cint_uofg_q_ = Libdl.dlsym(libsif, :cutest_cint_uofg_q_)
@ccall $ptr_cutest_cint_uofg_q_(status::Ptr{Cint}, n::Ptr{Cint}, x::Ptr{Float128}, f::Ptr{Float128},
g::Ptr{Float128}, grad::Ptr{Bool})::Cvoid
@ccall $ptr_cutest_cint_uofg_q_(status::Ptr{Cint}, n::Ptr{Cint}, x::Ptr{Float128},
f::Ptr{Float128}, g::Ptr{Float128}, grad::Ptr{Bool})::Cvoid
end

function cutest_udh_q_(libsif, status, n, x, lh1, h)
Expand All @@ -1265,7 +1283,8 @@
function cutest_ush_q_(libsif, status, n, x, nnzh, lh, h, irnh, icnh)
ptr_cutest_ush_q_ = Libdl.dlsym(libsif, :cutest_ush_q_)
@ccall $ptr_cutest_ush_q_(status::Ptr{Cint}, n::Ptr{Cint}, x::Ptr{Float128}, nnzh::Ptr{Cint},
lh::Ptr{Cint}, h::Ptr{Float128}, irnh::Ptr{Cint}, icnh::Ptr{Cint})::Cvoid
lh::Ptr{Cint}, h::Ptr{Float128}, irnh::Ptr{Cint},
icnh::Ptr{Cint})::Cvoid
end

function cutest_cint_ueh_q_(libsif, status, n, x, ne, le, iprnhi, iprhi, lirnhi, irnhi, lhi, hi,
Expand Down Expand Up @@ -1294,9 +1313,10 @@
hi, byrows)
ptr_cutest_cint_ugreh_q_ = Libdl.dlsym(libsif, :cutest_cint_ugreh_q_)
@ccall $ptr_cutest_cint_ugreh_q_(status::Ptr{Cint}, n::Ptr{Cint}, x::Ptr{Float128},
g::Ptr{Float128}, ne::Ptr{Cint}, le::Ptr{Cint}, iprnhi::Ptr{Cint},
iprhi::Ptr{Cint}, lirnhi::Ptr{Cint}, irnhi::Ptr{Cint},
lhi::Ptr{Cint}, hi::Ptr{Float128}, byrows::Ptr{Bool})::Cvoid
g::Ptr{Float128}, ne::Ptr{Cint}, le::Ptr{Cint},
iprnhi::Ptr{Cint}, iprhi::Ptr{Cint}, lirnhi::Ptr{Cint},
irnhi::Ptr{Cint}, lhi::Ptr{Cint}, hi::Ptr{Float128},
byrows::Ptr{Bool})::Cvoid
end

function cutest_cint_uhprod_q_(libsif, status, n, goth, x, p, r)
Expand Down Expand Up @@ -1332,8 +1352,8 @@

function cutest_cint_cofg_q_(libsif, status, n, x, f, g, grad)
ptr_cutest_cint_cofg_q_ = Libdl.dlsym(libsif, :cutest_cint_cofg_q_)
@ccall $ptr_cutest_cint_cofg_q_(status::Ptr{Cint}, n::Ptr{Cint}, x::Ptr{Float128}, f::Ptr{Float128},
g::Ptr{Float128}, grad::Ptr{Bool})::Cvoid
@ccall $ptr_cutest_cint_cofg_q_(status::Ptr{Cint}, n::Ptr{Cint}, x::Ptr{Float128},
f::Ptr{Float128}, g::Ptr{Float128}, grad::Ptr{Bool})::Cvoid
end

function cutest_cint_cofsg_q_(libsif, status, n, x, f, nnzg, lg, sg, ivsg, grad)
Expand Down
2 changes: 2 additions & 0 deletions test/coverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
function coverage_increase(nlp::CUTEstModel{T}) where {T}
status = Cint[0]
n, m = nlp.meta.nvar, nlp.meta.ncon
# class = Vector{Cchar}(undef, 30)
# CUTEst.classification(T, nlp.libsif, nlp.status, nlp.funit, class)
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

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

What was wrong here @amontoison ? As the function is no longer tested it seems

Copy link
Member Author

@amontoison amontoison Oct 11, 2024

Choose a reason for hiding this comment

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

Nick added this routine with the release 2.3.0 but I have some issue to make it work in Julia.
I think that Fortran changes the Julia pointer and it leads to a seg fault but we can't do that.
Julia own the memory.

With this new release of CUTEst, we also added a C version for all routines with string (name) and it means that strring are null-terminated (Ptr{Cchar} -> Cstring).

If I find time, I would like to update all api related to routine with string.

Copy link
Member

Choose a reason for hiding this comment

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

Oki, thanks! Could you make an issue for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's wait that all the C tests in CUTEst passed first:
ralna/CUTEst#67

pname = Vector{Cchar}(undef, 10)
CUTEst.probname(T, nlp.libsif, status, pname)
vname = Matrix{Cchar}(undef, 10, n)
Expand Down
Loading