testing

Numerical tests with controllable strictness.

The key difference to numpy.testing is the global switch TEST_ACTION that determines whether the tests raise AssertionErrors or issue ComparisonWarnings. For speed-critical applications, they may also be turned off altogether.

temfpy.testing.TEST_ACTION: str = 'warn'

Determines how the testing functions in this module (and elsewhere in TeMFpy) behave.

Allowed values:

The behaviour of the tests reacts dynamically to changing TEST_ACTION:

from temfpy import testing

testing.assert_allclose(1, 2)  # prints a warning
testing.TEST_ACTION = "raise"
testing.assert_allclose(1, 2)  # raises an exception
testing.TEST_ACTION = "pass"
testing.assert_allclose(1, 2)  # nothing happens

Testing functions

assert_allclose

Indicates if the two objects are not equal up to desired tolerance.

assert_array_less

Indicates if the first object is not elementwise smaller than the second.

check_schmidt_decomposition

Checks if the given Schmidt modes and correlation matrix are consistent.

ComparisonWarning

Generic warning class for failed equality testing or comparison.

temfpy.testing.assert_allclose(actual, desired, rtol=1e-07, atol=0.0, equal_nan=True, err_msg='', verbose=False, *, strict=False)[source]

Indicates if the two objects are not equal up to desired tolerance.

See assert_allclose() for details of the calling sequence.

Raises:

AssertionError | ComparisonWarning – If the shapes of the two arrays don’t match or any two entries deviate by more than the given tolerance.

temfpy.testing.assert_array_less(x, y, err_msg='', verbose=False, *, strict=False)[source]

Indicates if the first object is not elementwise smaller than the second.

See assert_array_less() for details of the calling sequence.

Raises:

AssertionError | ComparisonWarning – If the shapes of the two arrays don’t match or any entry of x is not less than the corresponding entry of y.

temfpy.testing.check_schmidt_decomposition(modes, C, diag_tol=1e-08)[source]

Checks if the given Schmidt modes and correlation matrix are consistent.

Parameters:
  • modes (slater.SchmidtModes | pfaffian.SchmidtModes) – Schmidt modes to check

  • C (ndarray) – (Nambu) correlation matrix

  • diag_tol (float) – Maximum absolute deviation from diagonalisation / SVD before error is raised.

Raises:

AssertionError | ComparisonWarning – If any entry of the correlation matrix deviates from its reconstruction from modes by more than diag_tol.

class temfpy.testing.ComparisonWarning[source]

Generic warning class for failed equality testing or comparison.