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

Error Importing Astromodels with python 3.11.3 #201

Open
parsotat opened this issue Oct 2, 2023 · 3 comments
Open

Error Importing Astromodels with python 3.11.3 #201

parsotat opened this issue Oct 2, 2023 · 3 comments

Comments

@parsotat
Copy link

parsotat commented Oct 2, 2023

I have upgraded to astromodels 2.4.0 and I am trying to import the module and get the following error:

ipython                          
Python 3.11.3 (main, Apr 19 2023, 18:51:09) [Clang 14.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from typing import Dict
   ...: 
   ...: import numpy as np
   ...: from astromodels import Band
   ...: import ronswanson as dukesilver
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 4
      1 from typing import Dict
      3 import numpy as np
----> 4 from astromodels import Band
      5 import ronswanson as dukesilver

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astromodels/__init__.py:14
      7 # Import the version
      8 
      9 #
     10 #
     12 if os.environ.get("ASTROMODELS_DEBUG", None) is None:
---> 14     from .utils.configuration import astromodels_config
     15     from .core.memoization import use_astromodels_memoization
     16     from .core.model import Model

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astromodels/utils/configuration.py:5
      1 from omegaconf import OmegaConf
      3 from astromodels.utils import get_path_of_user_config
----> 5 from .config_structure import Config
      7 # Read the default Config
      8 astromodels_config: Config = OmegaConf.structured(Config)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astromodels/utils/config_structure.py:69
     63     use_parameter_transforms: bool = True
     64     ignore_parameter_bounds: bool = False
---> 69 @dataclass
     70 class Config:
     71     logging: Logging = Logging()
     72     absorption_models: AbsorptionModels = AbsorptionModels()

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:1223, in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
   1220     return wrap
   1222 # We're called as @dataclass without parens.
-> 1223 return wrap(cls)

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:1213, in dataclass.<locals>.wrap(cls)
   1212 def wrap(cls):
-> 1213     return _process_class(cls, init, repr, eq, order, unsafe_hash,
   1214                           frozen, match_args, kw_only, slots,
   1215                           weakref_slot)

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:958, in _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
    955         kw_only = True
    956     else:
    957         # Otherwise it's a field of some type.
--> 958         cls_fields.append(_get_field(cls, name, type, kw_only))
    960 for f in cls_fields:
    961     fields[f.name] = f

File ~/opt/anaconda3/envs/py311/lib/python3.11/dataclasses.py:815, in _get_field(cls, a_name, a_type, default_kw_only)
    811 # For real fields, disallow mutable defaults.  Use unhashable as a proxy
    812 # indicator for mutability.  Read the __hash__ attribute from the class,
    813 # not the instance.
    814 if f._field_type is _FIELD and f.default.__class__.__hash__ is None:
--> 815     raise ValueError(f'mutable default {type(f.default)} for field '
    816                      f'{f.name} is not allowed: use default_factory')
    818 return f

ValueError: mutable default <class 'astromodels.utils.config_structure.Logging'> for field logging is not allowed: use default_factory

@natj
Copy link

natj commented Oct 11, 2023

same error here

@israelmcmc
Copy link
Contributor

I no longer see this issue using the master branch (d5c5416) and a fresh conda Python 3.11.3 installation.

I'm not sure if it is related, but a new setuptools version was released recently. I had to use --use-pip517, as explained on #209. That's the only difference I can think of, I do remember being able to reproduce this issue before.

@israelmcmc
Copy link
Contributor

Digging a little more into this, I think @grburgess addressed this issue specifically in commit 8f4610d. This commit made to the latest release 2.4.2.

israelmcmc added a commit to israelmcmc/cosipy that referenced this issue Jun 24, 2024
… Also, interpolation now fixed this other issue EconForge/interpolation.py#112, which allows to remove the restriction on numba (which is needed for astromodels 2.4.2)
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

3 participants