Open israelmcmc opened 3 weeks ago
Hi @israelmcmc. I tested the change, the installation was successfully (except installing h5py by conda install h5py
). However, I got an error when importing things related to threeML
:
It seems related to the logging of astromodels. Could you please test on your side? I never saw this before, and I am not sure if it's specific to my M1 mac.
Thank you!
from threeML import DiracDelta
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[3], line 1
----> 1 from threeML import DiracDelta
File [~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/threeML/__init__.py:24](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/threeML/__init__.py#line=23)
20 pass
22 from pathlib import Path
---> 24 from threeML.io.logging import setup_logger
26 # Import everything from astromodels
27 from astromodels import *
File [~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/threeML/io/__init__.py:1](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/threeML/io/__init__.py#line=0)
----> 1 from .logging import (activate_logs, activate_progress_bars, activate_warnings,
2 debug_mode, loud_mode, quiet_mode, setup_logger,
3 silence_logs, silence_progress_bars, silence_warnings,
4 toggle_progress_bars, update_logging_level)
5 from .plotting.get_style import get_threeML_style, set_threeML_style
File [~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/threeML/io/logging.py:7](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/threeML/io/logging.py#line=6)
4 from contextlib import contextmanager
5 from pathlib import Path
----> 7 from astromodels import astromodels_config
8 from astromodels.utils.logging import (
9 LogFilter,
10 _console_formatter,
(...)
15 astromodels_usr_log_handler,
16 )
18 from astromodels.utils.valid_variable import is_valid_variable_name
File [~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/astromodels/__init__.py:14](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/astromodels/__init__.py#line=13)
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 [~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/astromodels/utils/configuration.py:5](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/astromodels/utils/configuration.py#line=4)
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 [~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/astromodels/utils/config_structure.py:69](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/site-packages/astromodels/utils/config_structure.py#line=68)
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 [~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py:1232](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py#line=1231), in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
1229 return wrap
1231 # We're called as @dataclass without parens.
-> 1232 return wrap(cls)
File [~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py:1222](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py#line=1221), in dataclass.<locals>.wrap(cls)
1221 def wrap(cls):
-> 1222 return _process_class(cls, init, repr, eq, order, unsafe_hash,
1223 frozen, match_args, kw_only, slots,
1224 weakref_slot)
File [~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py:958](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py#line=957), 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 [~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py:815](http://localhost:8888/lab/tree/docs/tutorials/spectral_fits/continuum_fit/grb/~/conda_envs/cosipy_3_11/lib/python3.11/dataclasses.py#line=814), 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
Thanks for checking this, @Yong2Sheng. I confirm that I can reproduce your error. I'll need to poke into this to find out what's causing it.
@Yong2Sheng Can you give it another try, please? I'm now requiring a newer version of astromodels that fixes this issue.
I tracked down the issue it to pip resolving to a very old version of 3ML, which required a very old version of speclite, not compatible with recent Python versions.
I solved this simply by requiring a more recent version of 3ML, which is good anyway.
Closes #133