def assert_dict_almost_equal(dict1, dict2, tol=1e-3):
    """
    Recursively assert that two dictionaries are almost equal.
    Allows for tiny differences (less than tol) using numpy's allclose function.
    """
    assert dict1.keys() == dict2.keys(), f"Keys mismatch: {dict1.keys()} != {dict2.keys()}"

    for key in dict1:
        val1 = dict1[key]
        val2 = dict2[key]

        if isinstance(val1, dict) and isinstance(val2, dict):
            assert_dict_almost_equal(val1, val2, tol)
        else:

            if isinstance(val1, str):
                assert val1 == val2, f"Values for key '{key}' are not equal: {val1} != {val2}"
            elif np.isscalar(val1) and np.isnan(val1):
                assert np.isnan(val2).all(), f"Values for key '{key}' are not equal: {val1} != {val2}"
            else:
                assert np.allclose(
                    val1, val2, rtol=tol
                ), f"Values for key '{key}' are not almost equal: {val1} != {val2}"

    Recursively assert that two dictionaries are almost equal.
    Allows for tiny differences (less than tol) using numpy's allclose function.
    
metadrive/tests/test_functionality/test_nondeterminism.py