NVIDIA / earth2mip

Earth-2 Model Intercomparison Project (MIP) is a python framework that enables climate researchers and scientists to inter-compare AI models for weather and climate.
https://nvidia.github.io/earth2mip/
Apache License 2.0
183 stars 40 forks source link

fixing problem where initial conditions are reperturbed #165

Closed ankurmahesh closed 7 months ago

ankurmahesh commented 7 months ago

Earth-2 MIP Pull Request

Description

Fixes #164

This pull request changes earth2mip/inference_ensemble to avoid x from getting reperturbed during each loop's rank over ensemble members. Previously, x would be perturbed, and then the perturbed x would get perturbed again, and then the perturbed x would get perturbed again. This could make the magnitude of perturbations very large if many ensemble members are run per rank.

This MR prevents x from being overwritten during the loop over ensemble members.

Checklist

nbren12 commented 7 months ago

/blossom-ci

nbren12 commented 7 months ago

/blossom-ci

nbren12 commented 7 months ago

just a btw, but I didn't understand that += modified the actually contents of a torch or numpy array rather than making a new array and reusing the name "x". Seems this is the typical behavior for += on stateful objects.

[ins] In [5]: x = torch.tensor([2.0])

[ins] In [6]: y = x = torch.tensor([2.0])

[ins] In [7]: x +=1

[ins] In [8]: y
Out[8]: tensor([3.])

[ins] In [9]: import numpy as np

[ins] In [10]: x = np.array([2.0])

[ins] In [11]: y = x

[ins] In [12]: x +=1

[ins] In [13]: y
Out[13]: array([3.])

[ins] In [14]: x = y = []

[ins] In [15]: x += [1]

[ins] In [16]: y
Out[16]: [1]

[ins] In [17]: x =y =1

[ins] In [18]: x += 1

[ins] In [19]: y
Out[19]: 1