ralna / spral

Sparse Parallel Robust Algorithms Library
https://ralna.github.io/spral/
Other
105 stars 27 forks source link

Interfacing SPRAL with IPOPT #151

Open bharswami opened 1 year ago

bharswami commented 1 year ago

I am trying to interface SPRAL with IPOPT. I am running into some issues with getting the right output for a simple optimization problem too. The sequence of function calls that are made in IpSpralSolverInterface.cpp is:

spral_ssids_analyse_ptr32(false, ndim_, NULL, ia, ja, val_, &akeep_, &control_, &info);
spral_ssids_factor_ptr32(false, ia, ja, val_, scaling_, akeep_, &fkeep_, &control_, &info);
spral_ssids_solve(0, nrhs, rhs_vals, ndim_, akeep_, fkeep_, &control_, &info);

This is different from the calls made in ssids.c that comes with SPRAL Git repository.

/* Perform analyse and factorise with data checking */
bool check = true;
spral_ssids_analyse(check, n, NULL, ptr, row, NULL, &akeep, &options,
      &inform);
if(inform.flag<0) {
   spral_ssids_free(&akeep, &fkeep);
   exit(1);
}
spral_ssids_factor(posdef, NULL, NULL, val, NULL, akeep, &fkeep, &options,
      &inform);
if(inform.flag<0) {
   spral_ssids_free(&akeep, &fkeep);
   exit(1);
}
/* Solve */
spral_ssids_solve1(0, x, akeep, fkeep, &options, &inform);
if(inform.flag<0) {
   spral_ssids_free(&akeep, &fkeep);
   exit(1);
}

Could someone please clarify as to which function calls are more appropriate?

jfowkes commented 1 year ago

Good question, so the IPOPT interface in IpSpralSolverInterface.cpp uses more specific versions of the SSIDS functions tailored to the data types that IPOPT expects (in particular 32bit column pointers ptr and multiple right-hand sides).

The differences are essentially as follows: spral_ssids_analyse_ptr32 - performs analyse phase for 32bit column pointers spral_ssids_analyse - performs analyse phase for 64bit column pointers spral_ssids_factor_ptr32 - performs factorisation for 32bit column pointers spral_ssids_factor - performs factorisation for 64bit column pointers spral_ssids_solve - solves for multiple right-hand sides (IPOPT) spral_ssids_solve1 - solves for a single right-hand side (example)

For more details please see the SSIDS C documentation: https://www.numerical.rl.ac.uk/spral/doc/latest/C/ssids.html

bharswami commented 1 year ago

The SPRAL solver interface file has the ptr32 functions. Is it because the code is old?

jfowkes commented 1 year ago

I think it's more likely that IPOPT use 32bit integers to index sparse matrices, you need to have a really large matrix to need 64bits, as in ptr would need to hold more than 2,147,483,647 entries! Matrices of that size are unlikely to arise in interior point problems.

bharswami commented 1 year ago

I am trying to run simple optimization problems with ipopt and spral. I am encountering lot of NaNs and infs. I have no idea what both the codes do. Is there someone who can help me out a bit so that I can fix these issues?

jfowkes commented 1 year ago

I suggest you ask for help on the IPOPT GitHub, SPRAL is just a linear system solver that is used to solver the interior point linear systems that arise within IPOPT. For more on interior point see: https://en.wikipedia.org/wiki/Interior-point_method