Ciela-Institute / caustics

A gravitational lensing simulator for the machine learning era.
https://caustics.readthedocs.io
MIT License
30 stars 11 forks source link

Cosmological distance calculations between same redshifts of different dtype don't return zero #93

Open le-zouave opened 1 year ago

le-zouave commented 1 year ago

When calling a method from caustic.Cosmology to compute distances between two equal redshifts, the output can be nonzero if the input redshifts are tensors of different float precision. For example:

import torch
import caustic
from caustic.cosmology import FlatLambdaCDM

z1 = torch.tensor(0.5, dtype=torch.float64)
z2 = torch.tensor(0.5, dtype=torch.float32)
cosmo = FlatLambdaCDM()

cosmo.transverse_comoving_distance_z1z2(z1, z2)

Out[8]: tensor(0.0002, dtype=torch.float64)

Perhaps the distance methods in caustic.Cosmology should include a failsafe for such instances.

ConnorStoneAstro commented 7 months ago

It is generally best to always work at the same datatype. I think this is a fundamental limitation of float32, since it only has so much precision.