jacobwilliams / slsqp

Modern Fortran Edition of the SLSQP Optimizer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array bounds error in slsqp_module for unconstrained optimization problem, i.e. m = meq = 0

jbdv-no opened this issue · comments

Not 100% sure if this is intended to be supported or not, but I interpret the documentation to imply that it should be possible (while arguably not optimal) to use SLSQP to solve an unconstrained optimization problem (i.e. m=0, meq=0).

If so, this leads to a runtime error in line 434 of slsqp_module.f90 :

a(:,ig) = (cvecr-cvecl) / ( fact*delta(ig) )

when array bounds checking is enabled:

nagfor: Runtime Error: slsqp_module.f90, line 434: Rank 1 of CVECR has extent 0 instead of 1

or

gfortran: Fortran runtime error: Array bound mismatch for dimension 1 of array 'a' (1/0)

As I understand the variable declarations, when m = meq = 0, a has bounds (max(1,me%m),me%n+1) = (1, me%n+1), while cvecr (as well as cvecl and cvec ) has bounds (me%m) = (0), explaining the error message.

Without array bounds checking, the algorithm seems to be working as expected. As a workaround, I have added an if-statement around the problematic line of code, which seems to solve the problem with array bounds checking turned on, and still gives expected results.

if (size(a, dim=1) == size(cvecr) ) then
    a(:,ig) = (cvecr-cvecl) / ( fact*delta(ig) )
end if

However, I cannot be sure this quick fix has no unintended side effects, so would just like to bring this issue to your attention if it is indeed a valid one.

PS: Truly appreciate all your efforts making incredibly useful projects available in modern Fortran, thank you!

Thanks for reporting this! I can look into it...