-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add non-linear equality constraints in COBYLA #14
Comments
Yes, this should be done. A quick comment is that I suggest ranging the constraints as
(BTW, what the ellipsis mean?) This will be consistent with what has been done in the MATLAB interface: It does not make any difference in theory, but will affect the numerical behavior of the solver. Thanks. |
Ok for re-ordering the non-linear constraints as you suggested. Implementing non-linear equality constraints as suggested, implies to re-think about the API for non-linear inequality constraints in the Julia interface because it is not very practical to provide a single function that computes the objective function, the non-linear inequality constraints, and the non-linear equality constraints. For the user, it is certainly more practical to provide one function for each of these. For non-linear constraints, the number of constraints must be provided as well. What I have in mind is something like: cobyla(args...; kwds..., nonlinear_eq=(n_eq, c_eq), nonlinear_ineq=(n_ineq, c_ineq)) where
In Julia, the ellipsis expands the expression on the left. For example,
|
Yes, they should be separated. I thought the objective function and the nonlinear (inequality) constraints were already separated, no?
Sorry, we have to be more considerate here (see again "What is an interface / wrapper? "). Ideally, we should not ask the user to provide the number of constraints. It is the wrapper's job to figure this number out. We should not ask the user for additional information that is already implied in the user's input. Otherwise, our wrapper is not user-friendly and only half-baked, I am afraid. In the MATLAB interface, the number of constraints is obtained by evaluating the nonlinear constraints at x0 and then checking the length. Of course, the evaluated constraint value should not be thrown away, because the evaluation is expensive in practice. Instead, it is sent to the Fortran code, which (optionally) accepts the constraint value at x0 and uses it during the initialization. See https://github.com/libprima/prima/blob/8f7e80cd6fbe6e9d9a547c1f680dca07fd5823f8/matlab/interfaces/cobyla.m#L417-L421 However, the C interface currently does not accept the constraint value at x0. This has to be changed. See my proposal at libprima/prima#99. I am not sure whether @jschueller currently has time for it or not. For
The Fortran code returns the value of the nonlinear constraint at the solution in Thanks. |
I mostly agree. I am not sure that calling Fortran 2008 is easy or even doable in Julia. I am pretty sure it should be, but I am not familiar with that (especially Fortan 2008 may have a quite different ABI than old FORTRAN which is close to C except that all arguments are passed by address). In the meantime, the most important is to converge on the API from the end-user point of view. For now, we can code something intermediate and recognize the following keyword syntaxes (in the case of non-linear inequalities, the same rules apply for equalities):
if the value is I am about to solve a PR along these lines... In the long term, we can keep the BTW Directly calling Fortran would solve the issue that the C wrapper transpose the matrices of linear constraints, so with Julia calling the C wrapper these matrices are actually transposed twice, which is unecessary as Julia and Fortran have the same column-major storage order. |
My suggestion is to have only
and tolerate the waste of After doing this, let us wait for the update of the C interface (which will be done) or switch to the Fortran code. I guess the second would be ideal, especially after knowing that Julia also stores arrays in columns. In addition, the C interface indeed skips many optional inputs and outputs for simplicity, which is understandable (e.g., However, I am not sure how easy it is to interface Julia directly with the Fortran code. |
I would also keep: nonlinear_ineq = (v_ineq, c_ineq)
nonlinear_ineq = (c_ineq, v_ineq) with x, fx, nf, rc, cstrv, v_eq, v_ineq = cobyla(f, x0; kwds...) with |
This is solved by commit b99ce9c when PR https://github.com/libprima/PRIMA.jl/pull/17/commits is merged. |
Does this mean to use an input
Thanks. |
I guess the names in the high-level interfaces had better conform to the conventions in the respective language. Take
Another example is
Let us follow the conventions in Julia when choosing the names. Is there any "standard" optimization package in Julia to take as a reference? What about For example, the MATLAB interface of PRIMA is compatible with
will still work if you replace
In addition, the Python interface of PDFO (predecessor of PRIMA) is compatible with
will still work if you replace
In this way, we do not need to design a new API, and users do not need to learn how to use PRIMA as long as they already know how to use the standard libraries. If there is no good convention to follow, then being self-consistent and consistent with the Fortran backend may be a good idea. Thanks. |
A few comments:
To address this latter point, I have updated PR #17 as follows:
These changes constitute a major step in the direction of a unified driver (as you have done for other interface), say: x, info = prima(f, x0; kwds...) which, depending on the constraints (specified by the keywords |
Understood. However, good variable names also increase the readability of the code and ease the understanding of the users. So they have to be well thought out, especially if they are visible to end users. The names (and API) adopted by standard/popular libraries ( I like the idea of packing "secondary" outputs (and inputs/options, see libprima/prima#102) in a structure (or something equivalent). However, I would like to note that the Fortran backend uses Thanks. |
BTW, the Fortran implementation of PRIMA did not use any "structure" (the name is "derived type" in Fortran) for the input, output, or anywhere. This is because I wanted to provide a reference implementation that exposes the algorithms without using any language-specific features. In addition, I was afraid that using derived types as input or output may introduce problems when interfacing with other languages. In contrast, the wrappers/interfaces/implementations of PRIMA in other languages should use structures (or something equivalent in the respective language) whenever this leads to better code than otherwise. |
Yes, something like this would be wonderful! Thank you. |
Done in commit 476aad1 |
There is no general consensus:
So, for me, we should keep the same API for all the solvers in PRIMA (including the driver one) and simply take care of wrapping this API in other more general packages such as
Ok so let us keep that for now. For the name, again (i) there is no consensus among different softwares (I have seen From the point of view of a Julia user, an important point is to extend standard methods such as |
This issue was solved by b99ce9c. |
We need to add non-linear equality constraints in COBYLA. The Fortran code only supports non-linear inequality constraints. Assuming
c_ineq(x)
andc_eq(x)
are two Julia functions implementing the non-linear constraints:a possibility is to turn them in non-linear inequality constraints:
with something like:
which amounts to impose that:
The text was updated successfully, but these errors were encountered: