eelregit / pmwd

Differentiable Cosmological Forward Model
BSD 3-Clause "New" or "Revised" License
70 stars 19 forks source link

Python 3.7 support? #10

Closed EiffL closed 2 years ago

EiffL commented 2 years ago

I assume there is reason for not enabling python 3.7 in the setup.py ^^ But colab is currently on Python 3.7. I just tried to run the example code there and it crashes with that error:

[/usr/local/lib/python3.7/dist-packages/pmwd/boltzmann.py](https://localhost:8080/#) in growth_integ(cosmo, conf)
    199     ), axis=1)
    200 
--> 201     return cosmo.replace(growth=growth)
    202 
    203 

[/usr/local/lib/python3.7/dist-packages/pmwd/tree_util.py](https://localhost:8080/#) in replace(self, **changes)
    127     def replace(self, **changes):
    128         """Create a new object of the same type, replacing fields with changes."""
--> 129         return dataclasses.replace(self, **changes)
    130 
    131     cls.replace = replace

[/usr/lib/python3.7/dataclasses.py](https://localhost:8080/#) in replace(*args, **changes)
   1270         if f.name not in changes:
   1271             if f._field_type is _FIELD_INITVAR:
-> 1272                 raise ValueError(f"InitVar {f.name!r} "
   1273                                  'must be specified with replace()')
   1274             changes[f.name] = getattr(obj, f.name)

ValueError: InitVar 'Omega_k_fixed' must be specified with replace()

I assume maybe there is a new functionality in python 3.8 that makes this work, and not in 3.7? If that's so, I'd be happy to try to implement a workaround. Being able to run things on Colab is super important.

eelregit commented 2 years ago

That error seems to be a bug of Python 3.7 https://stackoverflow.com/questions/59597283/python-dataclasses-replace-not-working-for-initvar https://bugs.python.org/issue36470

At some point I was using ClassVar https://github.com/eelregit/pmwd/blob/15da71b7c42fedf35a3a38682f468e1717b61816/pmwd/cosmology.py#L64 But I forgot why I switched to InitVar

eelregit commented 2 years ago

Fixed by #12

eelregit commented 1 year ago

Now jax needs python>=3.8 https://github.com/google/jax/blob/76b922aade17432b8ae3fe44bdca0e170b7b877d/setup.py#L64