Skip to content

Commit

Permalink
Merge pull request libprima#40 from libprima/dev_cobyla
Browse files Browse the repository at this point in the history
Enable the Fortran implementation of lincoa and cobyla to support more types of constraints
  • Loading branch information
zaikunzhang authored Aug 4, 2023
2 parents b3f85ea + 4ff6203 commit 89724bf
Show file tree
Hide file tree
Showing 74 changed files with 2,740 additions and 984 deletions.
26 changes: 26 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2008,3 +2008,29 @@ sprimalib
COMPFLAGS
daynum
dfrv
mineq
BQPGABIM
idmat
ixl
ixu
mxl
mxu
lincon
Aeqx
Aineqx
ieq
iineq
AINEQ
cbnd
lceq
lcineq
lconstr
nlconstr
dotnet
jlumbroso
NONLCON
nonlcon
sqr
cvnd
cvpd
nlcon
2 changes: 1 addition & 1 deletion .github/scripts
12 changes: 12 additions & 0 deletions .github/workflows/lint_hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ jobs:
solver: [newuoa, cobyla, lincoa, bobyqa, uobyqa]

steps:

- name: Free disk space
uses: jlumbroso/free-disk-space@main
with:
# all of these default to true, but feel free to set to "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true

- name: Checkout repository
uses: actions/checkout@v3.5.3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_nagfor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
export PATH=$PATH:"~/local/bin"
source ~/local/bin/nag_licensing || (echo "\n\nNAG licensing failed.\n\n" && exit 2)
cd "$ROOT_DIR"/fortran/${{ matrix.solver }}
if [[ $(($(date +%d) % 2)) == 0 ]] ; then
if [[ $(($(date +%-d) % 2)) == 0 ]] ; then
bash ./flint -n --all
else
bash ./mlint -n --all
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/profile_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
id: check_matlab
run: if type 'matlab' &> /dev/null ; then echo "::set-output name=has_matlab::true" ; fi

- name: Cache MATLAB # N.B.: Clear the cache when the `latest` version of MATLAB changes in March and September
- name: Cache MATLAB # N.B.: Clear the cache when the `latest` version of MATLAB changes in March and September
uses: actions/cache@v3.3.1
with:
path: ${{ runner.tool_cache }}/MATLAB
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/profile_cobyla_small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
id: check_matlab
run: if type 'matlab' &> /dev/null ; then echo "::set-output name=has_matlab::true" ; fi

- name: Cache MATLAB # N.B.: Clear the cache when the `latest` version of MATLAB changes in March and September
- name: Cache MATLAB # N.B.: Clear the cache when the `latest` version of MATLAB changes in March and September
uses: actions/cache@v3.3.1
with:
path: ${{ runner.tool_cache }}/MATLAB
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/profile_prima_small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
id: check_matlab
run: if type 'matlab' &> /dev/null ; then echo "::set-output name=has_matlab::true" ; fi

- name: Cache MATLAB # N.B.: Clear the cache when the `latest` version of MATLAB changes in March and September
- name: Cache MATLAB # N.B.: Clear the cache when the `latest` version of MATLAB changes in March and September
uses: actions/cache@v3.3.1
with:
path: ${{ runner.tool_cache }}/MATLAB
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stress_test_fortran.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
run: |
cd "$ROOT_DIR"/fortran/tests
export TESTDIM=${{ matrix.testdim }}
RK=$((2**($(date +%d) % 3 + 2)))
RK=$((2**($(date +%-d) % 3 + 2)))
echo "RK = " $RK
if [[ $RK==16 && dfrv == *${{ matrix.compiler }}* ]] ; then
echo "r16 test is skipped for compiler " ${{ matrix.compiler }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_absoft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
source "$AFDIR"/bin/absvars.sh
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
# Use $(( )) rather than $(expr ). See https://unix.stackexchange.com/questions/63166/bash-e-exits-when-let-or-expr-evaluates-to-0
FFLAGS=-O$(($(date +%d) % 4))
FFLAGS=-O$(($(date +%-d) % 4))
FFLAGS=${FFLAGS/O0/g}
export FFLAGS
cd "$ROOT_DIR"/fortran/tests && make atest_${{ matrix.ikind }}.${{ matrix.solver }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_nagfor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
export PATH=$PATH:"~/local/bin"
source ~/local/bin/nag_licensing || echo "\n\nNAG licensing failed.\n\n"
# Use $(( )) rather than $(expr ). See https://unix.stackexchange.com/questions/63166/bash-e-exits-when-let-or-expr-evaluates-to-0
FFLAGS=-O$(($(date +%d) % 5))
FFLAGS=-O$(($(date +%-d) % 5))
FFLAGS=${FFLAGS/O0/g}
FFLAGS=${FFLAGS/O4/fast}
export FFLAGS
Expand Down
4 changes: 2 additions & 2 deletions fortran/bobyqa/bobyqa.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module bobyqa_mod
!
! Started: February 2022
!
! Last Modified: Monday, May 29, 2023 PM07:24:51
! Last Modified: Monday, July 03, 2023 AM12:01:01
!--------------------------------------------------------------------------------------------------!

implicit none
Expand All @@ -50,7 +50,7 @@ subroutine bobyqa(calfun, x, f, &
!
! or
!
! ! First define CALFUN, X, and XL, then do the following.
! ! First define CALFUN, X, and XL, and then do the following.
! call bobyqa(calfun, x, f, xl = xl, rhobeg = 0.5D0, rhoend = 1.0D-3, maxfun = 100)
!
! See examples/bobyqa_exmp.f90 for a concrete example.
Expand Down
16 changes: 12 additions & 4 deletions fortran/bobyqa/bobyqb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module bobyqb_mod
!
! Started: February 2022
!
! Last Modified: Tuesday, June 20, 2023 AM06:19:49
! Last Modified: Tuesday, August 01, 2023 PM05:26:39
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -407,10 +407,12 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
! CLOSE_ITPSET: Are the interpolation points close to XOPT?
distsq = sum((xpt - spread(xpt(:, kopt), dim=2, ncopies=npt))**2, dim=1)
!!MATLAB: distsq = sum((xpt - xpt(:, kopt)).^2) % Implicit expansion
close_itpset = all(distsq <= max((TWO * delta)**2, (TEN * rho)**2)) ! Powell's code.
close_itpset = all(distsq <= max(delta**2, (TEN * rho)**2))
! Below are some alternative definitions of CLOSE_ITPSET.
! !close_itpset = all(distsq <= (TEN * delta)**2) ! Does not work as well as Powell's version.
! N.B.: The threshold for CLOSE_ITPSET is at least DELBAR, the trust region radius for GEOSTEP.
! !close_itpset = all(distsq <= max((TWO * delta)**2, (TEN * rho)**2)) ! Powell's code.
! !close_itpset = all(distsq <= 4.0_RP * delta**2) ! Powell's NEWUOA code.
! !close_itpset = all(distsq <= max(delta**2, 4.0_RP * rho**2)) ! Powell's LINCOA code.
! ADEQUATE_GEO: Is the geometry of the interpolation set "adequate"?
adequate_geo = (shortd .and. accurate_mod) .or. close_itpset
! SMALL_TRRAD: Is the trust-region radius small? This indicator seems not impactive in practice.
Expand Down Expand Up @@ -460,7 +462,13 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
if (improve_geo) then
! XPT(:, KNEW_GEO) will become XOPT + D below. KNEW_GEO /= KOPT unless there is a bug.
knew_geo = int(maxloc(distsq, dim=1), kind(knew_geo))
delbar = max(min(TENTH * sqrt(maxval(distsq)), delta), rho)

! Set DELBAR, which will be used as the trust-region radius for the geometry-improving
! scheme GEOSTEP. Note that DELTA has been updated before arriving here.
delbar = max(min(TENTH * sqrt(maxval(distsq)), delta), rho) ! Powell's code
!delbar = rho ! Powell's UOBYQA code
!delbar = max(min(TENTH * sqrt(maxval(distsq)), HALF * delta), rho) ! Powell's NEWUOA code
!delbar = max(TENTH * delta, rho) ! Powell's LINCOA code

! Find D so that the geometry of XPT will be improved when XPT(:, KNEW_GEO) becomes XOPT + D.
d = geostep(knew_geo, kopt, bmat, delbar, sl, su, xpt, zmat)
Expand Down
3 changes: 1 addition & 2 deletions fortran/bobyqa/initialize.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module initialize_mod
!
! Started: February 2022
!
! Last Modified: Friday, May 12, 2023 PM06:53:02
! Last Modified: Monday, July 03, 2023 PM04:54:11
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -113,7 +113,6 @@ subroutine initxf(calfun, iprint, maxfun, ftarget, rhobeg, xl, xu, x0, ij, kopt,
call assert(all(x0 >= xl .and. (x0 <= xl .or. x0 >= xl + rhobeg)), 'X0 == XL or X0 >= XL + RHOBEG', srname)
call assert(all(x0 <= xu .and. (x0 >= xu .or. x0 <= xu - rhobeg)), 'X0 == XU or X0 >= XU - RHOBEG', srname)
call assert(size(xbase) == n, 'SIZE(XBASE) == N', srname)
call assert(size(xpt, 1) == n .and. size(xpt, 2) == npt, 'SIZE(XPT) == [N, NPT]', srname)
call assert(size(xhist, 1) == n .and. maxxhist * (maxxhist - maxhist) == 0, &
& 'SIZE(XHIST, 1) == N, SIZE(XHIST, 2) == 0 or MAXHIST', srname)
call assert(maxfhist * (maxfhist - maxhist) == 0, 'SIZE(FHIST) == 0 or MAXHIST', srname)
Expand Down
2 changes: 1 addition & 1 deletion fortran/classical/bobyqa/bobyqa.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module bobyqa_mod
!--------------------------------------------------------------------------------------------------!
! Classical mode. Not maintained. Not recommended. Please use the modernized version instead.
! Classical mode. Not maintained. Strongly discouraged. Please use the modernized version instead.
!
! The usage is the same as the modernized version.
!--------------------------------------------------------------------------------------------------!
Expand Down
Loading

0 comments on commit 89724bf

Please sign in to comment.