Skip to content

More user-friendly Julia interfaces #396

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

Open
amontoison opened this issue Apr 14, 2025 · 4 comments
Open

More user-friendly Julia interfaces #396

amontoison opened this issue Apr 14, 2025 · 4 comments
Labels

Comments

@amontoison
Copy link
Member

amontoison commented Apr 14, 2025

For each package of GALAHAD, we need three variables data, control, inform.
We should regroup them in a structure workspace only defined it in the Julia interface GALAHAD.jl.

struct TrbWorkspace{T,INT}
    data::Ptr{Cvoid}
    control::trb_control_type{T,INT}
    inform::trb_inform_type{T,INT}
end

It will reduce by a lot the number of parameters when we call the low-level Julia wrappers.

T = Float64
INT = Int32
workspace = TrbWorkspace{T,INT}()  # to be defined
trb_initialize(workspace, status)
trb_import(workspace, status, n, x_l, x_u, "coordinate", ne, H_row, H_col, C_NULL)
trb_solve_reverse_with_mat(workspace, status, eval_status, n, x, f[], g, ne, H_val, u, v)
trb_information(workspace, status)
trb_terminate(workspace)

We could also add a field status to TrbWorkspace.
trb_initialize could be automatically called when creating the structure with TrbWorkspace{T, INT}().
Furthermore, since we combine all arguments needed by trb_terminate, we could set it as the finalizer for the structure so that when the GC removes the object, it gets terminated automatically.
This would free the user from having to call trb_terminate manually.

It is not an interface with NLPModels.jl, but it could already be more user-friendly.
I just need to update my script to generate the Julia wrappers (https://github.com/ralna/GALAHAD/blob/master/GALAHAD.jl/gen/rewriter.jl), which should take less than one hour of work.

What do you think, @dpo, @nimgould, and @jfowkes?

@jfowkes
Copy link
Collaborator

jfowkes commented Apr 14, 2025

I think this is a great idea, I'm all for more user-friendliness and it doesn't get more user friendly than automatic initialisation and termination, especially as this is increasingly what users expect from higher-level language interfaces.

@nimgould
Copy link
Contributor

I can see the sense, but also the downsides (implementing it being a major one, as all the docs would need to be carefully rewritten). As it stands, the control and inform structures are passed as needed, while your approach is to bundle them all together. I presume a user would need to
say (the Julia equivalent of) of workspace.control.out = 1 rather than the simpler control.out = 1, and looks at workspace.inform.status not inform.status, which is a mouthful to me, particularly if it occurs may time. But, maybe Julia users are used to verbose variables?

The status variable is only used as inform.status is not always present. And, there would be no need for the trb_information call, as workspace.inform would be there.

I will leave this decision to you Juliates, but I will also pass responsibility for implementing and documenting it, I've done enough on the Julia docs side, rst is really painful :)

@dpo
Copy link
Collaborator

dpo commented Apr 14, 2025

rst??? That's so 2000. What's wrong with Markdown?

I think it's a good idea overall, though a proper NLPModels interface will also define solvers so they return stats objects.

Regarding verbosity, it would be trivial to define getters of the form get_status(workspace) = workspace.inform.status, and setters of the form set_out(workspace, out) = workspace.control.out = out.

@nimgould
Copy link
Contributor

2000, that's the nicest thing anyone has said to me all day :) I'll be happy for someone to embrace the 2020s and translate the lot!

Setters and getters sound good. How about all those multi-nested controls we are so proud of, the control.tru_control.sbls_control.sls_countrol.out, is that a set, set, set, set ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants