Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure on an M2 Apple silicon Mac #8

Open
AWSisco opened this issue Jul 9, 2023 · 1 comment
Open

Test failure on an M2 Apple silicon Mac #8

AWSisco opened this issue Jul 9, 2023 · 1 comment

Comments

@AWSisco
Copy link
Collaborator

AWSisco commented Jul 9, 2023

At least one test fails when inflow is installed under an arm64 architecture on a Mac with an M2 Max chip. On the same M2 Max Mac, all inflow tests pass when installed under an x86_64 (Intel-based) architecture. The failure appears to stem from very minor floating point precision differences in one of the weight tables being tested, but pytest will report a failure nonetheless. This does not appear to impact the integrity of inflow for use, but I wanted to document the test failure for reference.

For performance consistent with Intel-based Macs, inflow can be installed under an x86_64-based conda environment on Apple silicon Macs. Further reading on how to do this: https://taylorreiter.github.io/2022-04-05-Managing-multiple-architecture-specific-installations-of-conda-on-apple-M1/.

Comparing the benchmark and output weight tables:

$ diff tests/data/weight_table/weight_lis_no_intersect.csv tests/output/weight_table_test_lis_no_intersect.csv
32,33c32,33
< 45379,770746.6012,19,70,27,-2.0350,51.6550,4537900700019
< 45379,770746.6012,20,70,27,-2.0250,51.6550,4537900700020
---
> 45379,770746.6013,19,70,27,-2.0350,51.6550,4537900700019
> 45379,770746.6013,20,70,27,-2.0250,51.6550,4537900700020

The failure report from pytest:

========================================== FAILURES ==========================================
______________________ test_generate_weight_table_missing_intersections ______________________

    def test_generate_weight_table_missing_intersections():
        """
        Verify that the main routine in weight.py produces a weight table
        consistent with benchmark using a land-sea mask.
        """
        catchment_shapefile = os.path.join(DATA_DIR, 'catchment',
                                           'thames_near_cirencester_uk',
                                           'Catchment_thames_drainID45390.shp')
        connectivity_file = os.path.join(DATA_DIR, 'connectivity',
                                         'rapid_connect_45390.csv')
        lsm_file = os.path.join(DATA_DIR, 'lsm_grids', 'lis',
                                'LIS_HIST_201101210000.d01.nc')
        lsm_lat_variable = 'lat'
        lsm_lon_variable = 'lon'
        out_weight_table_file = os.path.join(OUTPUT_DIR,
                                        'weight_table_test_lis_no_intersect.csv')
        benchmark_file = os.path.join(DATA_DIR, 'weight_table',
                                      'weight_lis_no_intersect.csv')

        weight.generate_weight_table(lsm_file, catchment_shapefile,
                                     connectivity_file,
                                     out_weight_table_file,
                                     lsm_lat_variable=lsm_lat_variable,
                                     lsm_lon_variable=lsm_lon_variable,
                                     catchment_id_field_name='DrainLnID')

>       compare_weight_table_files(out_weight_table_file, benchmark_file)

tests/test_weight.py:366:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_weight.py:60: in compare_weight_table_files
    assert_almost_equal(output, benchmark)
../../miniforge3/envs/inflow/lib/python3.11/contextlib.py:81: in inner
    return func(*args, **kwds)
../../miniforge3/envs/inflow/lib/python3.11/contextlib.py:81: in inner
    return func(*args, **kwds)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<function assert_array_almost_equal.<locals>.compare at 0x143c62480>, array([[ 4.52770000e+04,  0.00000000e+00, -9.99...0.00000000e+00, -9.99900000e+03,
        -9.99900000e+03, -9.99900000e+03, -9.99900000e+03,
        -9.99900000e+03]]))
kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError:
E           Arrays are not almost equal to 7 decimals
E
E           Mismatched elements: 2 / 329 (0.608%)
E           Max absolute difference: 9.99999465e-05
E           Max relative difference: 1.29744259e-10
E            x: array([[ 4.5277000e+04,  0.0000000e+00, -9.9990000e+03, -9.9990000e+03,
E                   -9.9990000e+03, -9.9990000e+03, -9.9990000e+03],
E                  [ 4.5335000e+04,  5.5984600e+01,  2.1000000e+01,  7.0000000e+01,...
E            y: array([[ 4.5277000e+04,  0.0000000e+00, -9.9990000e+03, -9.9990000e+03,
E                   -9.9990000e+03, -9.9990000e+03, -9.9990000e+03],
E                  [ 4.5335000e+04,  5.5984600e+01,  2.1000000e+01,  7.0000000e+01,...

../../miniforge3/envs/inflow/lib/python3.11/contextlib.py:81: AssertionError
@mgeheran
Copy link
Collaborator

Thank you for posting this issue, @AWSisco. As we discussed, I will delay looking into it until there are more people running the code on the Apple M2 architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants