Skip to content

Commit

Permalink
Remove deprecations (#362)
Browse files Browse the repository at this point in the history
* np.float_ -> np.float64

* fix numpy 1.25 deprecations

* we now test everything

* revert change to fact

* trigger new build

* remove multi-objective test instead of skipping
  • Loading branch information
ewu63 committed Dec 4, 2023
1 parent 382fd09 commit 90c322a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/test_real.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

# all tests should pass on the private image
# except for the Intel image, where IPOPT is not available
if [[ $IMAGE == "private" ]] && [[ $COMPILERS != "intel" ]]; then
if [[ $IMAGE == "private" ]]; then
EXTRA_FLAGS='--disallow_skipped'
fi

Expand Down
2 changes: 1 addition & 1 deletion pyoptsparse/postprocessing/OptView.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def save_tec(self):

num_vars = len(keys)
num_iters = len(dat[keys[0]])
full_data = np.arange(num_iters, dtype=np.float_).reshape(num_iters, 1)
full_data = np.arange(num_iters, dtype=np.float64).reshape(num_iters, 1)
var_names = ["Iteration"]
for key in keys:
small_data = np.asarray(dat[key])
Expand Down
2 changes: 1 addition & 1 deletion pyoptsparse/pyALPSO/pyALPSO.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def objconfunc(x):
if dyniI == 0:
self.setOption("minInnerIter", opt("maxInnerIter"))

if not opt("stopCriteria") in [0, 1]:
if opt("stopCriteria") not in [0, 1]:
raise Error("Incorrect Stopping Criteria Setting")

if opt("fileout") not in [0, 1, 2, 3]:
Expand Down
4 changes: 2 additions & 2 deletions pyoptsparse/pyIPOPT/pyIPOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def __call__(
jac = extractRows(jac, indices) # Does reordering
scaleRows(jac, fact) # Perform logical scaling
else:
blc = np.array([-INFINITY])
buc = np.array([INFINITY])
blc = np.array(-INFINITY)
buc = np.array(INFINITY)
ncon = 1

jac = convertToCOO(jac) # Conver to coo format for IPOPT
Expand Down
10 changes: 5 additions & 5 deletions pyoptsparse/pySLSQP/pySLSQP.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def slgrad(m, me, la, n, f, g, df, dg, x):
gg = np.zeros([la], float)
df = np.zeros([n + 1], float)
dg = np.zeros([la, n + 1], float)
acc = np.array([self.getOption("ACC")], float)
acc = np.array(self.getOption("ACC"), float)
maxit = self.getOption("MAXIT")
iprint = self.getOption("IPRINT")
iout = self.getOption("IOUT")
Expand All @@ -204,13 +204,13 @@ def slgrad(m, me, la, n, f, g, df, dg, x):
lsei = ((n + 1) + mineq) * ((n + 1) - meq) + 2 * meq + (n + 1)
slsqpb = (n + 1) * (n / 2) + 2 * m + 3 * n + 3 * (n + 1) + 1
lwM = lsq + lsi + lsei + slsqpb + n + m
lw = np.array([lwM], int)
lw = np.array(lwM, int)
w = np.zeros(lw, float)
ljwM = max(mineq, (n + 1) - meq)
ljw = np.array([ljwM], int)
ljw = np.array(ljwM, int)
jw = np.zeros(ljw, np.intc)
nfunc = np.array([0], int)
ngrad = np.array([0], int)
nfunc = np.array(0, int)
ngrad = np.array(0, int)

# Run SLSQP
t0 = time.time()
Expand Down
4 changes: 2 additions & 2 deletions pyoptsparse/pySNOPT/pySNOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def __call__(

# Setup argument list values
start = np.array(self.getOption("Start"))
ObjAdd = np.array([0.0], float)
ObjAdd = np.array(0.0, float)
ProbNm = np.array(self.optProb.name, "c")
cdummy = -1111111 # this is a magic variable defined in SNOPT for undefined strings
cw[51, :] = cdummy # we set these to cdummy so that a placeholder is used in printout
Expand Down Expand Up @@ -704,7 +704,7 @@ def _set_snopt_options(self, iPrint: int, iSumm: int, cw: ndarray, iw: ndarray,
"""
# Set Options from the local options dictionary
# ---------------------------------------------
inform = np.array([-1], np.intc)
inform = np.array(-1, np.intc)
for name, value in self.options.items():
# these do not get set using snset
if name in self.specialOptions or name in self.pythonOptions:
Expand Down
6 changes: 3 additions & 3 deletions pyoptsparse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import numpy.typing as npt

# Either ndarray or scalar
NumpyType = Union[float, npt.NDArray[np.float_]]
NumpyType = Union[float, npt.NDArray[np.float64]]
# ndarray, list of numbers, or scalar
ArrayType = Union[NumpyType, Sequence[float]]
# funcs
Dict1DType = Dict[str, npt.NDArray[np.float_]]
Dict1DType = Dict[str, npt.NDArray[np.float64]]
# funcsSens
Dict2DType = Dict[str, Dict[str, npt.NDArray[np.float_]]]
Dict2DType = Dict[str, Dict[str, npt.NDArray[np.float64]]]
9 changes: 6 additions & 3 deletions tests/test_nsga2_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ def setup_optProb(self, n_obj):
if n_obj == 2:
self.optProb.addObj("obj2")

@parameterized.expand([(1,), (2,)])
@parameterized.expand(
[
(1,),
# (2,), # skipping flaky multi-objective test
]
)
def test_opt(self, n_obj):
if n_obj == 2:
raise unittest.SkipTest("skip flaky NSGA2 tests")
self.setup_optProb(n_obj)

# 300 generations will find x=(0,0), 200 or less will find x=(1,1)
Expand Down

0 comments on commit 90c322a

Please sign in to comment.