compare_recursive

qcelemental.testing.compare_recursive(expected, computed, label=None, *, atol=1e-06, rtol=1e-16, forgive=None, equal_phase=False, quiet=False, return_message=False, return_handler=None)[source]

Recursively compares nested structures such as dictionaries and lists.

Parameters:
  • expected (Union[Dict, BaseModel, ProtoModel]) – Reference value against which computed is compared. Dict may be of any depth but should contain Plain Old Data.

  • computed (Union[Dict, BaseModel, ProtoModel]) – Input value to compare against expected. Dict may be of any depth but should contain Plain Old Data.

  • atol (float) – Absolute tolerance (see formula below).

  • label (Optional[str]) – Label for passed and error messages. Defaults to calling function name.

  • rtol (float) – Relative tolerance (see formula below). By default set to zero so atol dominates.

  • forgive (Optional[List[str]]) – Keys in top level which may change between expected and computed without triggering failure.

  • equal_phase (Union[bool, List]) – Compare computed or its opposite as equal.

  • quiet (bool) – Whether to log the return message.

  • return_message (bool) – Whether to return tuple. See below.

  • return_handler (Optional[Callable]) –

Return type:

Union[bool, Tuple[bool, str]]

Returns:

  • allclose (bool) – Returns True if expected and computed are equal within tolerance; False otherwise.

  • message (str) – When return_message=True, also return passed or error message.

Notes

absolute(computed - expected) <= (atol + rtol * absolute(expected))