assert_utils.py#

Functions for making assertions about OpenMDAO Systems.

class openmdao.utils.assert_utils.SkipParameterized[source]

Bases: object

Replaces the parameterized class, skipping decorated test cases.

classmethod expand(input, name_func=None, doc_func=None, skip_on_empty=False, **legacy)[source]

Decorate a test so that it raises a SkipTest.

Parameters:
inputiterable

Not used (part of parameterized API).

name_funcfunction

Not used (part of parameterized API).

doc_funcfunction

Not used (part of parameterized API).

skip_on_emptybool

Not used (part of parameterized API).

**legacydict

Not used (part of parameterized API).

Returns:
function

The wrapper function.

openmdao.utils.assert_utils.assert_check_partials(data, atol=1e-06, rtol=1e-06)[source]

Raise assertion if any entry from the return from check_partials is above a tolerance.

Parameters:
datadict of dicts of dicts
First key:

is the component name;

Second key:

is the (output, input) tuple of strings;

Third key:

is one of [‘rel error’, ‘abs error’, ‘magnitude’, ‘J_fd’, ‘J_fwd’, ‘J_rev’];

For ‘rel error’, ‘abs error’, ‘magnitude’ the value is: A tuple containing norms for

forward - fd, adjoint - fd, forward - adjoint.

For ‘J_fd’, ‘J_fwd’, ‘J_rev’ the value is: A numpy array representing the computed

Jacobian for the three different methods of computation.

atolfloat

Absolute error. Default is 1e-6.

rtolfloat

Relative error. Default is 1e-6.

openmdao.utils.assert_utils.assert_check_totals(totals_data, atol=1e-06, rtol=1e-06)[source]

Raise assertion if any entry from the return from check_totals is above a tolerance.

Parameters:
totals_dataDict of Dicts of Tuples of Floats
First key:

is the (output, input) tuple of strings;

Second key:

is one of [‘rel error’, ‘abs error’, ‘magnitude’, ‘fdstep’];

For ‘rel error’, ‘abs error’, ‘magnitude’ the value is: A tuple containing norms for

forward - fd, adjoint - fd, forward - adjoint.

atolfloat

Absolute error. Default is 1e-6.

rtolfloat

Relative error. Default is 1e-6.

openmdao.utils.assert_utils.assert_equal_arrays(a1, a2)[source]

Check that two arrays are equal.

This is a simplified method useful when the arrays to be compared may not be numeric. It simply compares the shapes of the two arrays and then does a value by value comparison.

Parameters:
a1array

The first array to compare.

a2array

The second array to compare.

openmdao.utils.assert_utils.assert_equal_numstrings(s1, s2, atol=1e-06, rtol=1e-06)[source]

Check that two strings containing numbers are equal after convering numerical parts to floats.

Parameters:
s1str

The first numeric string to compare.

s2str

The second numeric string to compare.

atolfloat

Absolute error tolerance. Default is 1e-6.

rtolfloat

Relative error tolerance. Default is 1e-6.

openmdao.utils.assert_utils.assert_near_equal(actual, desired, tolerance=1e-15, tol_type='rel')[source]

Check relative error.

Determine that the relative error between actual and desired is within tolerance. If desired is zero, then use absolute error.

Can handle some data structures. Generates warnings for data types it cannot handle.

Parameters:
actualfloat, array-like, dict

The value from the test.

desiredfloat, array-like, dict

The value expected.

tolerancefloat

Maximum relative or absolute error. For relative tolerance: (actual - desired) / desired. For absolute tolerance: (actual - desired).

tol_type{‘rel’, ‘abs’}

Type of error to use: ‘rel’ for relative error, ‘abs’ for absolute error. Default is set to ‘rel’.

Returns:
float

The error.

openmdao.utils.assert_utils.assert_no_approx_partials(system, include_self=True, recurse=True, method='any', excludes=None)[source]

Raise assertion error if any component within system is using approximated partials.

Parameters:
systemSystem

The system under which to search for approximated partials.

include_selfbool

If True, include this system in the iteration.

recursebool

If True, iterate over the whole tree under this system.

methodstr

Specifically look for Components with this method of approx partials. Values can be ‘cs’, ‘fd’, or ‘any’. ‘any’ means either ‘cs’ or ‘fd’. The default is ‘any’.

excludesstr, iter of str, or None

Glob patterns for pathnames to exclude from the check. Default is None, which excludes nothing.

Raises:
AssertionError

If a subsystem of group is found to be using approximated partials.

openmdao.utils.assert_utils.assert_no_dict_jacobians(system, include_self=True, recurse=True)[source]

Raise an assertion error if any Group within system is found to be using dictionary jacobians.

Parameters:
systemSystem

The system under which to search for approximated partials.

include_selfbool

If True, include this system in the iteration.

recursebool

If True, iterate over the whole tree under this system.

Raises:
AssertionError

If a subsystem of group is found to be using approximated partials.

openmdao.utils.assert_utils.assert_no_warning(category, msg=None, contains=False)[source]

Context manager asserting that a warning is not issued.

Parameters:
categoryclass

The class of the warning.

msgstr or None

The text of the warning. If None then only the warning class will be checked.

containsbool

If True, check that the warning text contains msg, rather than checking equality.

Yields:
None
Raises:
AssertionError

If the warning is raised.

openmdao.utils.assert_utils.assert_warning(category, msg, contains_msg=False, ranks=None)[source]

Context manager asserting that a warning is issued.

Parameters:
categoryclass

The class of the expected warning.

msgstr

The text of the expected warning.

contains_msgbool

Set to True to check that the warning text contains msg, rather than checking equality.

ranksint or list of int, optional

The global ranks on which the warning is expected.

Yields:
None
Raises:
AssertionError

If the expected warning is not raised.

openmdao.utils.assert_utils.assert_warnings(expected_warnings)[source]

Context manager asserting that expected warnings are issued.

Parameters:
expected_warningsiterable of (class, str)

The category and text of the expected warnings.

Yields:
None
Raises:
AssertionError

If all the expected warnings are not raised.

openmdao.utils.assert_utils.skip_helper(msg)[source]

Raise a SkipTest.

Parameters:
msgstr

The skip messaage.

Raises:
SkipTest