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

Fix installation for Python 3.11 #187

Merged
merged 3 commits into from
Jul 9, 2024

Conversation

israelmcmc
Copy link
Collaborator

@israelmcmc israelmcmc commented Jun 6, 2024

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

@Yong2Sheng
Copy link
Contributor

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

@israelmcmc
Copy link
Collaborator Author

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.

@israelmcmc
Copy link
Collaborator Author

Related to threeML/astromodels#201

… 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)
@israelmcmc
Copy link
Collaborator Author

@Yong2Sheng Can you give it another try, please? I'm now requiring a newer version of astromodels that fixes this issue.

@Yong2Sheng
Copy link
Contributor

Hi @israelmcmc, I installed the package and successfully run through the TS map notebook, it went well. Thank you!

Copy link
Contributor

@Yong2Sheng Yong2Sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installed, tested the imports and ts map notebook. It went well. Thank you @israelmcmc!

Copy link
Contributor

@Yong2Sheng Yong2Sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

@israelmcmc israelmcmc merged commit 1bdbdd9 into cositools:develop Jul 9, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

Issue with numba 0.59.0
2 participants