From 80e6c1fb3f391a22c3e411f1f4036f7ae8f29ba2 Mon Sep 17 00:00:00 2001 From: Ella Wu Date: Thu, 18 Apr 2024 13:54:33 -0700 Subject: [PATCH 1/7] initialize cw to spaces --- pyoptsparse/pySNOPT/pySNOPT.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pyoptsparse/pySNOPT/pySNOPT.py b/pyoptsparse/pySNOPT/pySNOPT.py index 63185e33..c576a978 100644 --- a/pyoptsparse/pySNOPT/pySNOPT.py +++ b/pyoptsparse/pySNOPT/pySNOPT.py @@ -385,6 +385,7 @@ def __call__( self.setOption("Total real workspace", lenrw) cw = np.empty((lencw, 8), dtype="|S1") + cw[:] = " " iw = np.zeros(leniw, np.intc) rw = np.zeros(lenrw, float) snopt.sninit(iPrint, iSumm, cw, iw, rw) @@ -444,11 +445,6 @@ def __call__( start = np.array(self.getOption("Start")) 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 - cw[52, :] = cdummy - cw[53, :] = cdummy - cw[54, :] = cdummy xs = np.concatenate((xs, np.zeros(ncon, float))) bl = np.concatenate((blx, blc)) bu = np.concatenate((bux, buc)) @@ -701,11 +697,11 @@ def _set_snopt_options(self, iPrint: int, iSumm: int, cw: ndarray, iw: ndarray, if name == "Problem Type": snopt.snset(value, iPrint, iSumm, inform, cw, iw, rw) elif name == "Print file": - snopt.snset(name + " " + f"{iPrint}", iPrint, iSumm, inform, cw, iw, rw) + snopt.snset(f"{name} {iPrint}", iPrint, iSumm, inform, cw, iw, rw) elif name == "Summary file": - snopt.snset(name + " " + f"{iSumm}", iPrint, iSumm, inform, cw, iw, rw) + snopt.snset(f"{name} {iSumm}", iPrint, iSumm, inform, cw, iw, rw) else: - snopt.snset(name + " " + value, iPrint, iSumm, inform, cw, iw, rw) + snopt.snset(f"{name} {value}", iPrint, iSumm, inform, cw, iw, rw) elif isinstance(value, float): snopt.snsetr(name, value, iPrint, iSumm, inform, cw, iw, rw) elif isinstance(value, int): From 87dac2a09fc9755a9a0102e2427e384f69ebad4c Mon Sep 17 00:00:00 2001 From: Ella Wu Date: Thu, 18 Apr 2024 13:54:54 -0700 Subject: [PATCH 2/7] optionally raise import warning --- pyoptsparse/pyCONMIN/pyCONMIN.py | 2 +- pyoptsparse/pyNSGA2/pyNSGA2.py | 2 +- pyoptsparse/pyOpt_utils.py | 8 ++++++-- pyoptsparse/pySLSQP/pySLSQP.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyoptsparse/pyCONMIN/pyCONMIN.py b/pyoptsparse/pyCONMIN/pyCONMIN.py index 0fbac67d..87d084ed 100644 --- a/pyoptsparse/pyCONMIN/pyCONMIN.py +++ b/pyoptsparse/pyCONMIN/pyCONMIN.py @@ -17,7 +17,7 @@ # import the compiled module THIS_DIR = os.path.dirname(os.path.abspath(__file__)) -conmin = try_import_compiled_module_from_path("conmin", THIS_DIR) +conmin = try_import_compiled_module_from_path("conmin", THIS_DIR, raise_warning=True) class CONMIN(Optimizer): diff --git a/pyoptsparse/pyNSGA2/pyNSGA2.py b/pyoptsparse/pyNSGA2/pyNSGA2.py index 173703e9..e5418f58 100644 --- a/pyoptsparse/pyNSGA2/pyNSGA2.py +++ b/pyoptsparse/pyNSGA2/pyNSGA2.py @@ -16,7 +16,7 @@ # import the compiled module THIS_DIR = os.path.dirname(os.path.abspath(__file__)) -nsga2 = try_import_compiled_module_from_path("nsga2", THIS_DIR) +nsga2 = try_import_compiled_module_from_path("nsga2", THIS_DIR, raise_warning=True) class NSGA2(Optimizer): diff --git a/pyoptsparse/pyOpt_utils.py b/pyoptsparse/pyOpt_utils.py index 35eb7400..bc18636e 100644 --- a/pyoptsparse/pyOpt_utils.py +++ b/pyoptsparse/pyOpt_utils.py @@ -576,7 +576,9 @@ def _broadcast_to_array(name: str, value: ArrayType, n_values: int, allow_none: return value -def try_import_compiled_module_from_path(module_name: str, path: Optional[str] = None) -> Union[types.ModuleType, str]: +def try_import_compiled_module_from_path( + module_name: str, path: Optional[str] = None, raise_warning: bool = False +) -> Union[types.ModuleType, str]: """ Attempt to import a module from a given path. @@ -586,6 +588,8 @@ def try_import_compiled_module_from_path(module_name: str, path: Optional[str] = The name of the module path : Optional[str] The path to import from. If None, the default ``sys.path`` is used. + raise_warning : bool + If true, raise an import warning. By default false. Returns ------- @@ -600,7 +604,7 @@ def try_import_compiled_module_from_path(module_name: str, path: Optional[str] = try: module = importlib.import_module(module_name) except ImportError as e: - if path is not None: + if raise_warning: warnings.warn( f"{module_name} module could not be imported from {path}.", stacklevel=2, diff --git a/pyoptsparse/pySLSQP/pySLSQP.py b/pyoptsparse/pySLSQP/pySLSQP.py index d7e6b367..bb2431b4 100644 --- a/pyoptsparse/pySLSQP/pySLSQP.py +++ b/pyoptsparse/pySLSQP/pySLSQP.py @@ -17,7 +17,7 @@ # import the compiled module THIS_DIR = os.path.dirname(os.path.abspath(__file__)) -slsqp = try_import_compiled_module_from_path("slsqp", THIS_DIR) +slsqp = try_import_compiled_module_from_path("slsqp", THIS_DIR, raise_warning=True) class SLSQP(Optimizer): From 09724cdf0fe421c24b2b225c0fb00be8518fe9a0 Mon Sep 17 00:00:00 2001 From: Ella Wu Date: Thu, 18 Apr 2024 14:04:44 -0700 Subject: [PATCH 3/7] fix test --- tests/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_other.py b/tests/test_other.py index 41435b8d..f0c59b2c 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -18,7 +18,7 @@ def test_nonexistent_path(self): if "snopt" in key: sys.modules.pop(key) with self.assertWarns(UserWarning): - module = try_import_compiled_module_from_path("snopt", "/a/nonexistent/path") + module = try_import_compiled_module_from_path("snopt", "/a/nonexistent/path", raise_warning=True) self.assertTrue(isinstance(module, str)) def test_sys_path_unchanged(self): From d7dc70da74c1a7523de614d2cf23d7b70ec87065 Mon Sep 17 00:00:00 2001 From: Ella Wu Date: Fri, 19 Apr 2024 11:20:33 -0700 Subject: [PATCH 4/7] rename types.py to pyOpt_types.py --- pyoptsparse/{types.py => pyOpt_types.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pyoptsparse/{types.py => pyOpt_types.py} (100%) diff --git a/pyoptsparse/types.py b/pyoptsparse/pyOpt_types.py similarity index 100% rename from pyoptsparse/types.py rename to pyoptsparse/pyOpt_types.py From 007cd0b0bdf4b77a63b6a480d3653356a6d1ae65 Mon Sep 17 00:00:00 2001 From: Ella Wu Date: Fri, 19 Apr 2024 11:21:21 -0700 Subject: [PATCH 5/7] rename imports --- pyoptsparse/pyOpt_constraint.py | 2 +- pyoptsparse/pyOpt_gradient.py | 2 +- pyoptsparse/pyOpt_optimization.py | 2 +- pyoptsparse/pyOpt_utils.py | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyoptsparse/pyOpt_constraint.py b/pyoptsparse/pyOpt_constraint.py index 80cfe85c..e85a850d 100644 --- a/pyoptsparse/pyOpt_constraint.py +++ b/pyoptsparse/pyOpt_constraint.py @@ -8,8 +8,8 @@ # Local modules from .pyOpt_error import Error, pyOptSparseWarning +from .pyOpt_types import Dict1DType from .pyOpt_utils import INFINITY, _broadcast_to_array, convertToCOO -from .types import Dict1DType class Constraint: diff --git a/pyoptsparse/pyOpt_gradient.py b/pyoptsparse/pyOpt_gradient.py index ec6e58a9..27083c64 100644 --- a/pyoptsparse/pyOpt_gradient.py +++ b/pyoptsparse/pyOpt_gradient.py @@ -8,7 +8,7 @@ # Local modules from .pyOpt_MPI import MPI from .pyOpt_optimization import Optimization -from .types import Dict1DType, Dict2DType +from .pyOpt_types import Dict1DType, Dict2DType class Gradient: diff --git a/pyoptsparse/pyOpt_optimization.py b/pyoptsparse/pyOpt_optimization.py index ac41174d..a15ffa93 100644 --- a/pyoptsparse/pyOpt_optimization.py +++ b/pyoptsparse/pyOpt_optimization.py @@ -15,6 +15,7 @@ from .pyOpt_constraint import Constraint from .pyOpt_error import Error from .pyOpt_objective import Objective +from .pyOpt_types import Dict1DType, Dict2DType, NumpyType from .pyOpt_utils import ( ICOL, IDATA, @@ -28,7 +29,6 @@ scaleRows, ) from .pyOpt_variable import Variable -from .types import Dict1DType, Dict2DType, NumpyType class Optimization: diff --git a/pyoptsparse/pyOpt_utils.py b/pyoptsparse/pyOpt_utils.py index bc18636e..7edba239 100644 --- a/pyoptsparse/pyOpt_utils.py +++ b/pyoptsparse/pyOpt_utils.py @@ -8,6 +8,7 @@ mat = {'csr':[rowp, colind, data], 'shape':[nrow, ncols]} # A csr matrix mat = {'csc':[colp, rowind, data], 'shape':[nrow, ncols]} # A csc matrix """ + # Standard Python modules import importlib import os @@ -24,7 +25,7 @@ # Local modules from .pyOpt_error import Error -from .types import ArrayType +from .pyOpt_types import ArrayType # Define index mnemonics IROW = 0 From 11eb3ed883942f0c86b138c2203fccb3a330e09b Mon Sep 17 00:00:00 2001 From: Ella Wu Date: Mon, 22 Apr 2024 10:42:57 -0700 Subject: [PATCH 6/7] version bump --- pyoptsparse/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyoptsparse/__init__.py b/pyoptsparse/__init__.py index aa852adb..2730086d 100644 --- a/pyoptsparse/__init__.py +++ b/pyoptsparse/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.10.2" +__version__ = "2.10.3" from .pyOpt_history import History from .pyOpt_variable import Variable From 73848dde2de2f8658e2127b867996726113491ad Mon Sep 17 00:00:00 2001 From: Marco Mangano Date: Tue, 23 Apr 2024 18:44:03 -0400 Subject: [PATCH 7/7] bugfix version revert --- pyoptsparse/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyoptsparse/__init__.py b/pyoptsparse/__init__.py index 2730086d..aa852adb 100644 --- a/pyoptsparse/__init__.py +++ b/pyoptsparse/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.10.3" +__version__ = "2.10.2" from .pyOpt_history import History from .pyOpt_variable import Variable