Skip to content

Commit

Permalink
Merge branch 'master' into update_ivc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjasa committed Apr 18, 2024
2 parents 09fd833 + 7dd5a8e commit d92da1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/openmdao_test_workflow.yml
Expand Up @@ -81,7 +81,7 @@ jobs:
OS: ubuntu-latest
PY: '3.11'
NUMPY: '1.26'
SCIPY: '1.11'
SCIPY: '1.12'
PETSc: '3.18'
PYOPTSPARSE: 'v2.10.1'
# PAROPT: true
Expand All @@ -98,7 +98,7 @@ jobs:
OS: macos-latest
PY: '3.11'
NUMPY: '1.26'
SCIPY: '1.11'
SCIPY: '1.12'
PETSc: '3.18'
# PYOPTSPARSE: 'v2.10.1'
# PAROPT: true
Expand All @@ -112,7 +112,7 @@ jobs:
OS: ubuntu-latest
PY: '3.11'
NUMPY: '1.26'
SCIPY: '1.11'
SCIPY: '1.12'
OPTIONAL: '[test]'
TESTS: true
EXCLUDE: ${{ github.event_name == 'workflow_dispatch' && ! inputs.Ubuntu_Minimal }}
Expand All @@ -137,7 +137,7 @@ jobs:
OS: ubuntu-latest
PY: '3.11'
NUMPY: '1.26'
SCIPY: '1.11'
SCIPY: '1.12'
PETSc: '3.18'
PYOPTSPARSE: 'v2.10.1'
SNOPT: '7.7'
Expand Down Expand Up @@ -554,7 +554,7 @@ jobs:
- NAME: Windows Baseline
PY: '3.11'
NUMPY: '1.24'
SCIPY: '1.11'
SCIPY: '1.12'
PYOPTSPARSE: '2.10.1'
BANDIT: true
EXCLUDE: ${{ github.event_name == 'workflow_dispatch' && ! inputs.Windows_Baseline }}
Expand Down
11 changes: 9 additions & 2 deletions openmdao/core/tests/test_approx_derivs.py
Expand Up @@ -2,7 +2,12 @@
import time
import unittest

from packaging.version import Version

import numpy as np
from scipy import __version__ as scipy_version

ScipyVersion = Version(scipy_version)

import openmdao.api as om
from openmdao.test_suite.components.impl_comp_array import TestImplCompArray, TestImplCompArrayDense
Expand Down Expand Up @@ -279,7 +284,7 @@ def compute_partials(self, inputs, partials):
model.add_design_var('p2.x2')
model.add_constraint('comp.y1')
model.add_constraint('comp.y2')

prob.setup()
prob.run_model()
model.run_linearize(driver=prob.driver)
Expand Down Expand Up @@ -1083,7 +1088,7 @@ def compute_partials(self, inputs, partials):
model.add_design_var('p2.x2')
model.add_constraint('comp.y1')
model.add_constraint('comp.y2')

prob.setup()
prob.run_model()
model.run_linearize(driver=prob.driver)
Expand Down Expand Up @@ -1586,6 +1591,8 @@ def test_newton_with_krylov_solver(self):
assert_near_equal(J['con1', 'z'][0][1], -0.78449158, 1.0e-6)
assert_near_equal(J['con1', 'x'][0][0], -0.98061448, 1.0e-6)

@unittest.skipUnless(ScipyVersion < Version("1.13"),
"scipy < 1.13 is required, see issue #3156.")
def test_newton_with_cscjac_under_cs(self):
# Basic sellar test.

Expand Down
35 changes: 19 additions & 16 deletions openmdao/drivers/tests/test_scipy_optimizer.py
Expand Up @@ -9,6 +9,8 @@
import numpy as np
from scipy import __version__ as scipy_version

ScipyVersion = Version(scipy_version)

import openmdao.api as om
from openmdao.test_suite.components.expl_comp_array import TestExplCompArrayDense, TestExplCompArraySparse, TestExplCompArrayJacVec
from openmdao.test_suite.components.paraboloid import Paraboloid
Expand Down Expand Up @@ -1234,7 +1236,7 @@ def test_sellar_mdf_COBYLA(self):
assert_near_equal(prob['z'][1], 0.0, 1e-3)
assert_near_equal(prob['x'], 0.0, 1e-3)

@unittest.skipUnless(Version(scipy_version) >= Version("1.1"),
@unittest.skipUnless(ScipyVersion >= Version("1.1"),
"scipy >= 1.1 is required.")
def test_trust_constr(self):

Expand Down Expand Up @@ -1276,7 +1278,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
self.assertTrue(prob['c'] < 10)
self.assertTrue(prob['c'] > 0)

@unittest.skipUnless(Version(scipy_version) >= Version("1.1"),
@unittest.skipUnless(ScipyVersion >= Version("1.1"),
"scipy >= 1.1 is required.")
def test_trust_constr_hess_option(self):

Expand Down Expand Up @@ -1319,7 +1321,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
self.assertTrue(prob['c'] < 10)
self.assertTrue(prob['c'] > 0)

@unittest.skipUnless(Version(scipy_version) >= Version("1.1"),
@unittest.skipUnless(ScipyVersion >= Version("1.1"),
"scipy >= 1.1 is required.")
def test_trust_constr_equality_con(self):

Expand Down Expand Up @@ -1360,7 +1362,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):

assert_near_equal(prob['con.c'], 1., 1e-3)

@unittest.skipUnless(Version(scipy_version) >= Version("1.2"),
@unittest.skipUnless(ScipyVersion >= Version("1.2"),
"scipy >= 1.2 is required.")
def test_trust_constr_inequality_con(self):

Expand Down Expand Up @@ -1398,7 +1400,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):

assert_near_equal(prob['c'], 1.0, 1e-2)

@unittest.skipUnless(Version(scipy_version) >= Version("1.2"),
@unittest.skipUnless(ScipyVersion >= Version("1.2"),
"scipy >= 1.2 is required.")
def test_trust_constr_bounds(self):
class Rosenbrock(om.ExplicitComponent):
Expand Down Expand Up @@ -1652,10 +1654,11 @@ def test_call_final_setup(self):

prob.setup()

expected_msg = \
"Problem .*: run_model must be called before total derivatives can be checked\."
with self.assertRaisesRegex(RuntimeError, expected_msg):
totals = prob.check_totals(method='fd', out_stream=False)
with self.assertRaises(RuntimeError) as cm:
prob.check_totals(method='fd', out_stream=False)

self.assertEqual(str(cm.exception), f"Problem {prob._get_inst_id()}: "
"run_model must be called before total derivatives can be checked.")

def test_cobyla_linear_constraint(self):
# Bug where ScipyOptimizeDriver tried to compute and cache the constraint derivatives for the
Expand Down Expand Up @@ -1793,7 +1796,7 @@ def compute_partials(self, inputs, partials):
assert_near_equal(prob['x'], np.array([0.234171, -0.1000]), 1e-3)
assert_near_equal(prob['f'], -0.907267, 1e-3)

@unittest.skipUnless(Version(scipy_version) >= Version("1.2"),
@unittest.skipUnless(ScipyVersion >= Version("1.2"),
"scipy >= 1.2 is required.")
def test_dual_annealing_rastrigin(self):
# Example from the Scipy documentation
Expand Down Expand Up @@ -1901,7 +1904,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
assert_near_equal(prob['x'], -np.ones(size), 1e-2)
assert_near_equal(prob['f'], 3.0, 1e-2)

@unittest.skipUnless(Version(scipy_version) >= Version("1.4"),
@unittest.skipUnless(ScipyVersion >= Version("1.4"),
"scipy >= 1.4 is required.")
def test_differential_evolution_constrained_linear(self):
# Source of example:
Expand Down Expand Up @@ -1935,8 +1938,8 @@ def test_differential_evolution_constrained_linear(self):
assert_near_equal(prob['x'], [0.96632622, 0.93367155], 1e-2)
assert_near_equal(prob['f'], 0.0011352416852625719, 1e-2)

@unittest.skipUnless(Version(scipy_version) >= Version("1.4"),
"scipy >= 1.4 is required.")
@unittest.skipUnless(ScipyVersion >= Version("1.4") and ScipyVersion < Version("1.12"),
"scipy >= 1.4, < 1.12 is required.")
def test_differential_evolution_constrained_nonlinear(self):
# Source of example:
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html
Expand Down Expand Up @@ -1969,7 +1972,7 @@ def test_differential_evolution_constrained_nonlinear(self):
assert_near_equal(prob['x'], [0.96632622, 0.93367155], 1e-2)
assert_near_equal(prob['f'], 0.0011352416852625719, 1e-2)

@unittest.skipUnless(Version(scipy_version) >= Version("1.4"),
@unittest.skipUnless(ScipyVersion >= Version("1.4"),
"scipy >= 1.4 is required.")
def test_differential_evolution_constrained_linear_nonlinear(self):
# test of the differential evolution optimizer with both
Expand Down Expand Up @@ -2004,7 +2007,7 @@ def test_differential_evolution_constrained_linear_nonlinear(self):
assert_near_equal(prob['x'], [0.94999253, 0.90250721], 1e-2)
assert_near_equal(prob['f'], 0.00250079, 1e-2)

@unittest.skipUnless(Version(scipy_version) >= Version("1.2"),
@unittest.skipUnless(ScipyVersion >= Version("1.2"),
"scipy >= 1.2 is required.")
def test_shgo_rosenbrock(self):
# Source of example:
Expand Down Expand Up @@ -2229,7 +2232,7 @@ def test_singular_jac_error_desvars_multidim_indices_con(self):
self.assertEqual(str(msg.exception),
"Constraints or objectives [('parab.f_z', inds=[(1, 1, 0)])] cannot be impacted by the design variables of the problem.")

@unittest.skipUnless(Version(scipy_version) >= Version("1.2"),
@unittest.skipUnless(ScipyVersion >= Version("1.2"),
"scipy >= 1.2 is required.")
def test_feature_shgo_rastrigin(self):
# Source of example: https://stefan-endres.github.io/shgo/
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -33,7 +33,7 @@ classifiers = [
]
dependencies = [
"networkx>=2.0",
"numpy",
"numpy<2",
"packaging",
"requests",
"scipy",
Expand Down

0 comments on commit d92da1d

Please sign in to comment.