Skip to content

Commit b53e4c7

Browse files
committed
250403.192158.CST revert unwanted changes in checkexit.f90, evaluate.f90, and checkbreak.py; add comment to the top of cobyla_example.py
1 parent 0db7e7d commit b53e4c7

File tree

6 files changed

+82
-81
lines changed

6 files changed

+82
-81
lines changed

fortran/common/checkexit.f90

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module checkexit_mod
77
!
88
! Started: September 2021
99
!
10-
! Last Modified: Thu 03 Apr 2025 05:43:33 PM CST
10+
! Last Modified: Tuesday, September 26, 2023 AM10:51:16
1111
!--------------------------------------------------------------------------------------------------!
1212

1313
implicit none
1414
private
15-
public:: checkexit
15+
public :: checkexit
1616

1717
interface checkexit
1818
module procedure checkexit_unc, checkexit_con
@@ -28,25 +28,25 @@ function checkexit_unc(maxfun, nf, f, ftarget, x) result(info)
2828
!--------------------------------------------------------------------------------------------------!
2929

3030
! Common modules
31-
use, non_intrinsic:: consts_mod, only : RP, IK, DEBUGGING
32-
use, non_intrinsic:: debug_mod, only : assert
33-
use, non_intrinsic:: infnan_mod, only : is_nan, is_posinf, is_inf
34-
use, non_intrinsic:: infos_mod, only : INFO_DFT, NAN_INF_X, NAN_INF_F, FTARGET_ACHIEVED, MAXFUN_REACHED
31+
use, non_intrinsic :: consts_mod, only : RP, IK, DEBUGGING
32+
use, non_intrinsic :: debug_mod, only : assert
33+
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf, is_inf
34+
use, non_intrinsic :: infos_mod, only : INFO_DFT, NAN_INF_X, NAN_INF_F, FTARGET_ACHIEVED, MAXFUN_REACHED
3535

3636
implicit none
3737

3838
! Inputs
39-
integer(IK), intent(in):: maxfun
40-
integer(IK), intent(in):: nf
41-
real(RP), intent(in):: f
42-
real(RP), intent(in):: ftarget
43-
real(RP), intent(in):: x(:)
39+
integer(IK), intent(in) :: maxfun
40+
integer(IK), intent(in) :: nf
41+
real(RP), intent(in) :: f
42+
real(RP), intent(in) :: ftarget
43+
real(RP), intent(in) :: x(:)
4444

4545
! Outputs
46-
integer(IK):: info
46+
integer(IK) :: info
4747

4848
! Local variables
49-
character(len=*), parameter:: srname = 'CHECKEXIT_UNC'
49+
character(len=*), parameter :: srname = 'CHECKEXIT_UNC'
5050

5151
! Preconditions
5252
if (DEBUGGING) then
@@ -66,7 +66,7 @@ function checkexit_unc(maxfun, nf, f, ftarget, x) result(info)
6666
info = INFO_DFT ! Default info, indicating that the solver should not exit.
6767

6868
! Although X should not contain NaN unless there is a bug, we include the following for security.
69-
! X can be Inf, as finite+finite can be Inf numerically.
69+
! X can be Inf, as finite + finite can be Inf numerically.
7070
if (any(is_nan(x) .or. is_inf(x))) then
7171
info = NAN_INF_X
7272
end if
@@ -103,27 +103,27 @@ function checkexit_con(maxfun, nf, cstrv, ctol, f, ftarget, x) result(info)
103103
!--------------------------------------------------------------------------------------------------!
104104

105105
! Common modules
106-
use, non_intrinsic:: consts_mod, only : RP, IK, DEBUGGING
107-
use, non_intrinsic:: debug_mod, only : assert
108-
use, non_intrinsic:: infnan_mod, only : is_nan, is_posinf, is_inf
109-
use, non_intrinsic:: infos_mod, only : INFO_DFT, NAN_INF_X, NAN_INF_F, FTARGET_ACHIEVED, MAXFUN_REACHED
106+
use, non_intrinsic :: consts_mod, only : RP, IK, DEBUGGING
107+
use, non_intrinsic :: debug_mod, only : assert
108+
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf, is_inf
109+
use, non_intrinsic :: infos_mod, only : INFO_DFT, NAN_INF_X, NAN_INF_F, FTARGET_ACHIEVED, MAXFUN_REACHED
110110

111111
implicit none
112112

113113
! Inputs
114-
integer(IK), intent(in):: maxfun
115-
integer(IK), intent(in):: nf
116-
real(RP), intent(in):: cstrv
117-
real(RP), intent(in):: ctol
118-
real(RP), intent(in):: f
119-
real(RP), intent(in):: ftarget
120-
real(RP), intent(in):: x(:)
114+
integer(IK), intent(in) :: maxfun
115+
integer(IK), intent(in) :: nf
116+
real(RP), intent(in) :: cstrv
117+
real(RP), intent(in) :: ctol
118+
real(RP), intent(in) :: f
119+
real(RP), intent(in) :: ftarget
120+
real(RP), intent(in) :: x(:)
121121

122122
! Outputs
123-
integer(IK):: info
123+
integer(IK) :: info
124124

125125
! Local variables
126-
character(len=*), parameter:: srname = 'CHECKEXIT_CON'
126+
character(len=*), parameter :: srname = 'CHECKEXIT_CON'
127127

128128
! Preconditions
129129
if (DEBUGGING) then
@@ -144,7 +144,7 @@ function checkexit_con(maxfun, nf, cstrv, ctol, f, ftarget, x) result(info)
144144
info = INFO_DFT ! Default info, indicating that the solver should not exit.
145145

146146
! Although X should not contain NaN unless there is a bug, we include the following for security.
147-
! X can be Inf, as finite+finite can be Inf numerically.
147+
! X can be Inf, as finite + finite can be Inf numerically.
148148
if (any(is_nan(x) .or. is_inf(x))) then
149149
info = NAN_INF_X
150150
end if

fortran/common/evaluate.f90

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ module evaluate_mod
66
!
77
! Started: August 2021
88
!
9-
! Last Modified: Thu 03 Apr 2025 05:48:45 PM CST
9+
! Last Modified: Monday, September 25, 2023 PM08:52:04
1010
!--------------------------------------------------------------------------------------------------!
1111

1212
implicit none
1313
private
14-
public:: moderatex
15-
public:: moderatef
16-
public:: moderatec
17-
public:: evaluate
14+
public :: moderatex
15+
public :: moderatef
16+
public :: moderatec
17+
public :: evaluate
1818

1919
interface evaluate
2020
module procedure evaluatef, evaluatefc
@@ -28,15 +28,15 @@ function moderatex(x) result(y)
2828
!--------------------------------------------------------------------------------------------------!
2929
! This function moderates a decision variable. It replaces NaN by 0 and Inf/-Inf by REALMAX/-REALMAX.
3030
!--------------------------------------------------------------------------------------------------!
31-
use, non_intrinsic:: consts_mod, only : RP, ZERO, REALMAX
32-
use, non_intrinsic:: infnan_mod, only : is_nan
33-
use, non_intrinsic:: linalg_mod, only : trueloc
31+
use, non_intrinsic :: consts_mod, only : RP, ZERO, REALMAX
32+
use, non_intrinsic :: infnan_mod, only : is_nan
33+
use, non_intrinsic :: linalg_mod, only : trueloc
3434
implicit none
3535

3636
! Inputs
37-
real(RP), intent(in):: x(:)
37+
real(RP), intent(in) :: x(:)
3838
! Outputs
39-
real(RP):: y(size(x))
39+
real(RP) :: y(size(x))
4040

4141
y = x
4242
y(trueloc(is_nan(x))) = ZERO
@@ -49,14 +49,14 @@ pure elemental function moderatef(f) result(y)
4949
! This function moderates the function value of a MINIMIZATION problem. It replaces NaN and any
5050
! value above FUNCMAX by FUNCMAX.
5151
!--------------------------------------------------------------------------------------------------!
52-
use, non_intrinsic:: consts_mod, only : RP, REALMAX, FUNCMAX
53-
use, non_intrinsic:: infnan_mod, only : is_nan
52+
use, non_intrinsic :: consts_mod, only : RP, REALMAX, FUNCMAX
53+
use, non_intrinsic :: infnan_mod, only : is_nan
5454
implicit none
5555

5656
! Inputs
57-
real(RP), intent(in):: f
57+
real(RP), intent(in) :: f
5858
! Outputs
59-
real(RP):: y
59+
real(RP) :: y
6060

6161
y = f
6262
if (is_nan(y)) then
@@ -71,18 +71,18 @@ end function moderatef
7171
function moderatec(c) result(y)
7272
!--------------------------------------------------------------------------------------------------!
7373
! This function moderates the constraint value, the constraint demanding this value to be NONNEGATIVE.
74-
! It replaces any value below-CONSTRMAX by-CONSTRMAX, and any NaN or value above CONSTRMAX by
74+
! It replaces any value below -CONSTRMAX by -CONSTRMAX, and any NaN or value above CONSTRMAX by
7575
! CONSTRMAX.
7676
!--------------------------------------------------------------------------------------------------!
77-
use, non_intrinsic:: consts_mod, only : RP, CONSTRMAX
78-
use, non_intrinsic:: infnan_mod, only : is_nan
79-
use, non_intrinsic:: linalg_mod, only : trueloc
77+
use, non_intrinsic :: consts_mod, only : RP, CONSTRMAX
78+
use, non_intrinsic :: infnan_mod, only : is_nan
79+
use, non_intrinsic :: linalg_mod, only : trueloc
8080
implicit none
8181

8282
! Inputs
83-
real(RP), intent(in):: c(:)
83+
real(RP), intent(in) :: c(:)
8484
! Outputs
85-
real(RP):: y(size(c))
85+
real(RP) :: y(size(c))
8686

8787
y = c
8888
y(trueloc(is_nan(c))) = CONSTRMAX
@@ -96,21 +96,21 @@ subroutine evaluatef(calfun, x, f)
9696
! handled by a moderated extreme barrier.
9797
!--------------------------------------------------------------------------------------------------!
9898
! Common modules
99-
use, non_intrinsic:: consts_mod, only : RP, DEBUGGING
100-
use, non_intrinsic:: debug_mod, only : assert
101-
use, non_intrinsic:: infnan_mod, only : is_nan, is_posinf
102-
use, non_intrinsic:: pintrf_mod, only : OBJ
99+
use, non_intrinsic :: consts_mod, only : RP, DEBUGGING
100+
use, non_intrinsic :: debug_mod, only : assert
101+
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf
102+
use, non_intrinsic :: pintrf_mod, only : OBJ
103103
implicit none
104104

105105
! Inputs
106-
procedure(OBJ):: calfun ! N.B.: INTENT cannot be specified if a dummy procedure is not a POINTER
107-
real(RP), intent(in):: x(:)
106+
procedure(OBJ) :: calfun ! N.B.: INTENT cannot be specified if a dummy procedure is not a POINTER
107+
real(RP), intent(in) :: x(:)
108108

109109
! Output
110-
real(RP), intent(out):: f
110+
real(RP), intent(out) :: f
111111

112112
! Local variables
113-
character(len=*), parameter:: srname = 'EVALUATEF'
113+
character(len=*), parameter :: srname = 'EVALUATEF'
114114

115115
! Preconditions
116116
if (DEBUGGING) then
@@ -154,22 +154,22 @@ subroutine evaluatefc(calcfc, x, f, constr)
154154
! constraint value. Nan/Inf are handled by a moderated extreme barrier.
155155
!--------------------------------------------------------------------------------------------------!
156156
! Common modules
157-
use, non_intrinsic:: consts_mod, only : RP, DEBUGGING
158-
use, non_intrinsic:: debug_mod, only : assert
159-
use, non_intrinsic:: infnan_mod, only : is_nan, is_posinf
160-
use, non_intrinsic:: pintrf_mod, only : OBJCON
157+
use, non_intrinsic :: consts_mod, only : RP, DEBUGGING
158+
use, non_intrinsic :: debug_mod, only : assert
159+
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf
160+
use, non_intrinsic :: pintrf_mod, only : OBJCON
161161
implicit none
162162

163163
! Inputs
164-
procedure(OBJCON):: calcfc ! N.B.: INTENT cannot be specified if a dummy procedure is not a POINTER
165-
real(RP), intent(in):: x(:)
164+
procedure(OBJCON) :: calcfc ! N.B.: INTENT cannot be specified if a dummy procedure is not a POINTER
165+
real(RP), intent(in) :: x(:)
166166

167167
! Outputs
168-
real(RP), intent(out):: f
169-
real(RP), intent(out):: constr(:)
168+
real(RP), intent(out) :: f
169+
real(RP), intent(out) :: constr(:)
170170

171171
! Local variables
172-
character(len=*), parameter:: srname = 'EVALUATEFC'
172+
character(len=*), parameter :: srname = 'EVALUATEFC'
173173

174174
! Preconditions
175175
if (DEBUGGING) then

pyprima/src/pyprima/common/checkbreak.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
Python implementation by Nickolai Belakovski
99
'''
1010

11-
from ..common.evaluate import evaluate, moderatex, moderatef, moderatec
12-
from ..common.consts import (EPS, RHOBEG_DEFAULT, RHOEND_DEFAULT, CTOL_DEFAULT,
13-
CWEIGHT_DEFAULT, FTARGET_DEFAULT, IPRINT_DEFAULT,
14-
MAXFUN_DIM_DEFAULT, DEBUGGING, BOUNDMAX,
15-
ETA1_DEFAULT, ETA2_DEFAULT, GAMMA1_DEFAULT,
16-
GAMMA2_DEFAULT)
17-
from ..common.preproc import preproc
18-
from ..common.present import present
19-
from ..common.linalg import matprod
2011
from .infos import INFO_DEFAULT, NAN_INF_X, NAN_INF_F, FTARGET_ACHIEVED, MAXFUN_REACHED
2112

2213
import numpy as np

pyprima/src/pyprima/common/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
22
This module provides subroutines that handle the X/F/C histories of the solver, taking into
3-
! account that MAXHIST may be smaller than NF.
3+
account that MAXHIST may be smaller than NF.
44
55
Translated from the modern-Fortran reference implementation in PRIMA by Zaikun ZHANG (www.zhangzk.net).
66

pyprima/src/pyprima/common/preproc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ def preproc(solver, num_vars, iprint, maxfun, maxhist, ftarget, rhobeg, rhoend,
248248
if (is_constrained):
249249
warn(f'{solver}: Invalid CWEIGHT; it should be a nonnegative number; it is set to {cweight}')
250250

251-
#====================!
252-
# Calculation ends !
253-
#====================!
251+
#====================#
252+
# Calculation ends #
253+
#====================#
254254

255255
# Postconditions
256256
if DEBUGGING:

pyprima/src/pyprima/examples/cobyla/cobyla_example.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
'''
2+
This is an example to illustrate the usage of the solver.
3+
4+
Translated from the modern-Fortran reference implementation in PRIMA by Zaikun ZHANG (www.zhangzk.net).
5+
6+
Dedicated to late Professor M. J. D. Powell FRS (1936--2015).
7+
8+
Python implementation by Nickolai Belakovski
9+
'''
10+
111
import numpy as np
212
from pyprima.cobyla.cobyla import cobyla
313

@@ -27,9 +37,9 @@ def calcfc_chebyquad(x):
2737

2838
def calcfc_hexagon(x):
2939
# Test problem 10 in Powell's original algorithm
30-
40+
3141
assert len(x) == 9
32-
42+
3343
f = -0.5 * (x[0] * x[3] - x[1] * x[2] + x[2] * x[8] - x[4] * x[8] + x[4] * x[7] - x[5] * x[6])
3444
constr = np.zeros(14)
3545
constr[0] = -1 + x[2]**2 + x[3]**2
@@ -52,7 +62,7 @@ def calcfc_hexagon(x):
5262

5363
if __name__ == "__main__":
5464
n_chebyquad = 6
55-
65+
5666
# The following lines illustrates how to call the solver to solve the Chebyquad problem.
5767
x_chebyquad = np.array([i/(n_chebyquad+1) for i in range(1, n_chebyquad+1)]) # Starting point
5868
m = 0 # Dimension of constraints. M must be specified correctly, or the program will crash!

0 commit comments

Comments
 (0)