Skip to content

Commit

Permalink
skip some tests with issues with OM 3.36.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robfalck committed Feb 4, 2025
1 parent aff9590 commit bb04ee5
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal
import dymos as dm

from dymos.transcriptions.explicit_shooting.test.test_ode_integration_comp import SimpleODE
from dymos.utils.testing_utils import SimpleODE
from dymos.transcriptions.explicit_shooting.ode_evaluation_group import ODEEvaluationGroup


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,21 @@
import openmdao.api as om
import dymos as dm
from dymos import options as dymos_options
from dymos.utils.misc import om_version

from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE
from dymos.transcriptions.explicit_shooting.ode_integration_comp import ODEIntegrationComp

from dymos.phase.options import TimeOptionsDictionary, StateOptionsDictionary, ParameterOptionsDictionary
from dymos.transcriptions.grid_data import GridData


class SimpleODE(om.ExplicitComponent):
"""
A simple ODE from https://math.okstate.edu/people/yqwang/teaching/math4513_fall11/Notes/rungekutta.pdf
"""
def initialize(self):
self.options.declare('num_nodes', types=(int,))

def setup(self):
nn = self.options['num_nodes']
self.add_input('x', shape=(nn,), units='s**2')
self.add_input('t', shape=(nn,), units='s')
self.add_input('p', shape=(nn,), units='s**2')

self.add_output('x_dot', shape=(nn,), units='s')

ar = np.arange(nn, dtype=int)
self.declare_partials(of='x_dot', wrt='x', rows=ar, cols=ar, val=1.0)
self.declare_partials(of='x_dot', wrt='t', rows=ar, cols=ar)
self.declare_partials(of='x_dot', wrt='p', rows=ar, cols=ar, val=1.0)

def compute(self, inputs, outputs):
x = inputs['x']
t = inputs['t']
p = inputs['p']
outputs['x_dot'] = x - t**2 + p

def compute_partials(self, inputs, partials):
t = inputs['t']
partials['x_dot', 't'] = -2*t
from dymos.utils.testing_utils import SimpleODE


class TestODEIntegrationComp(unittest.TestCase):

@unittest.skipIf(om_version()[0] >= (3, 36, 0) or om_version()[0] < (3, 37, 0),
reason='Test skipped due to an issue in OpenMDAO 3.36.x')
def test_integrate_scalar_ode(self):
dymos_options['include_check_partials'] = True

Expand Down Expand Up @@ -110,6 +83,8 @@ def test_integrate_scalar_ode(self):

dymos_options['include_check_partials'] = False

@unittest.skipIf(om_version()[0] >= (3, 36, 0) or om_version()[0] < (3, 37, 0),
reason='Test skipped due to an issue in OpenMDAO 3.36.x')
def test_integrate_with_controls(self):

dymos_options['include_check_partials'] = True
Expand Down Expand Up @@ -190,6 +165,8 @@ def test_integrate_with_controls(self):
cpd = p.check_partials(compact_print=False, method='fd')
assert_check_partials(cpd, atol=1.0E-4, rtol=1.0E-4)

@unittest.skipIf(om_version()[0] >= (3, 36, 0) or om_version()[0] < (3, 37, 0),
reason='Test skipped due to an issue in OpenMDAO 3.36.x')
def test_integrate_with_polynomial_controls(self):

dymos_options['include_check_partials'] = True
Expand Down
121 changes: 121 additions & 0 deletions dymos/utils/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,124 @@ def classify_var(self, name):
The variable classification.
"""
return 'ode'

class SimpleODE(om.ExplicitComponent):
"""
A simple ODE for testing purposes.
Source: https://math.okstate.edu/people/yqwang/teaching/math4513_fall11/Notes/rungekutta.pdf
"""
def initialize(self):
"""
Declare options for SimpleODE.
"""
self.options.declare('num_nodes', types=(int,))

def setup(self):
"""
Add inputs and outputs to SimpleODE.
"""
nn = self.options['num_nodes']
self.add_input('x', shape=(nn,), units='s**2')
self.add_input('t', shape=(nn,), units='s')
self.add_input('p', shape=(nn,), units='s**2')

self.add_output('x_dot', shape=(nn,), units='s')

ar = np.arange(nn, dtype=int)
self.declare_partials(of='x_dot', wrt='x', rows=ar, cols=ar, val=1.0)
self.declare_partials(of='x_dot', wrt='t', rows=ar, cols=ar)
self.declare_partials(of='x_dot', wrt='p', rows=ar, cols=ar, val=1.0)

def compute(self, inputs, outputs):
"""
Compute the outputs of SimpleVectorizedODE.
Parameters
----------
inputs : Vector
Vector of inputs.
outputs : Vector
Vector of outputs.
"""
x = inputs['x']
t = inputs['t']
p = inputs['p']
outputs['x_dot'] = x - t**2 + p

def compute_partials(self, inputs, partials):
"""
Compute the partials of SimpleVectorizedODE.
Parameters
----------
inputs : Vector
Vector of inputs.
partials : Dictionary
Vector of partials.
"""
t = inputs['t']
partials['x_dot', 't'] = -2*t


class SimpleVectorizedODE(om.ExplicitComponent):
"""
A simple ODE from https://math.okstate.edu/people/yqwang/teaching/math4513_fall11/Notes/rungekutta.pdf
"""
def initialize(self):
"""
Declare options for SimpleVectorizedODE.
"""
self.options.declare('num_nodes', types=(int,))

def setup(self):
"""
Add inputs and outputs to SimpleVectorizedODE.
"""
nn = self.options['num_nodes']
self.add_input('z', shape=(nn, 2), units='s**2')
self.add_input('t', shape=(nn,), units='s')
self.add_input('p', shape=(nn,), units='s**2')

self.add_output('z_dot', shape=(nn, 2), units='s')

cs = np.repeat(np.arange(nn, dtype=int), 2)
ar2 = np.arange(2 * nn, dtype=int)
dzdot_dz_pattern = np.arange(2 * nn, step=2, dtype=int)
self.declare_partials(of='z_dot', wrt='z', rows=dzdot_dz_pattern, cols=dzdot_dz_pattern, val=1.0)
self.declare_partials(of='z_dot', wrt='t', rows=ar2, cols=cs)
dzdot_dp_rows = np.arange(2 * nn, step=2, dtype=int)
dzdot_dp_cols = np.arange(nn, dtype=int)
self.declare_partials(of='z_dot', wrt='p', rows=dzdot_dp_rows, cols=dzdot_dp_cols, val=1.0)

def compute(self, inputs, outputs):
"""
Compute the outputs of SimpleVectorizedODE.
Parameters
----------
inputs : Vector
Vector of inputs.
outputs : Vector
Vector of outputs.
"""
z = inputs['z']
t = inputs['t']
p = inputs['p']
outputs['z_dot'][:, 0] = z[:, 0] - t**2 + p
outputs['z_dot'][:, 1] = 10 * t

def compute_partials(self, inputs, partials):
"""
Compute the partials of SimpleVectorizedODE.
Parameters
----------
inputs : Vector
Vector of inputs.
partials : Dictionary
Vector of partials.
"""
t = inputs['t']
partials['z_dot', 't'][0::2] = -2*t
partials['z_dot', 't'][1::2] = 10

0 comments on commit bb04ee5

Please sign in to comment.