threeML / astromodels

Spatial and spectral models for astrophysics
BSD 3-Clause "New" or "Revised" License
44 stars 45 forks source link

Cannot import astromodels #182

Closed ivvv closed 2 years ago

ivvv commented 2 years ago

I am on ARM64, conda python 3.10 and installed astromodels with pip with no errors, here is a check:

M1 ~ % pip install astromodels
Requirement already satisfied: astromodels in ./miniconda3/envs/py310/lib/python3.10/site-packages (2.3.2)
Requirement already satisfied: scipy>=0.14 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (1.8.1)
Requirement already satisfied: astropy>=1.2 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (5.1)
Requirement already satisfied: dill in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (0.3.5.1)
Requirement already satisfied: colorama in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (0.4.4)
Requirement already satisfied: future in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (0.18.2)
Requirement already satisfied: PyYAML>=5.1 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (6.0)
Requirement already satisfied: numpy>=1.6 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (1.22.4)
Requirement already satisfied: numba in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (0.55.2)
Requirement already satisfied: h5py in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (3.6.0)
Requirement already satisfied: interpolation in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (2.2.1)
Requirement already satisfied: tables in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (3.7.0)
Requirement already satisfied: omegaconf in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (2.2.2)
Requirement already satisfied: pandas in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astromodels) (1.4.2)
Requirement already satisfied: pyerfa>=2.0 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astropy>=1.2->astromodels) (2.0.0.1)
Requirement already satisfied: packaging>=19.0 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from astropy>=1.2->astromodels) (21.3)
Requirement already satisfied: tempita>=0.5.2 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from interpolation->astromodels) (0.5.2)
Requirement already satisfied: setuptools in ./miniconda3/envs/py310/lib/python3.10/site-packages (from numba->astromodels) (62.3.2)
Requirement already satisfied: llvmlite<0.39,>=0.38.0rc1 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from numba->astromodels) (0.38.1)
Requirement already satisfied: antlr4-python3-runtime==4.9.* in ./miniconda3/envs/py310/lib/python3.10/site-packages (from omegaconf->astromodels) (4.9.3)
Requirement already satisfied: python-dateutil>=2.8.1 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from pandas->astromodels) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from pandas->astromodels) (2022.1)
Requirement already satisfied: numexpr>=2.6.2 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from tables->astromodels) (2.8.1)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from packaging>=19.0->astropy>=1.2->astromodels) (3.0.9)
Requirement already satisfied: six>=1.5 in ./miniconda3/envs/py310/lib/python3.10/site-packages (from python-dateutil>=2.8.1->pandas->astromodels) (1.16.0)
M1 ~ %

When I try import astromodels in e.g. ipython session I see the following error:

In [2]: import astromodels
[WARNING ] The naima package is not available. Models that depend on it will not be available
[WARNING ] The GSL library or the pygsl wrapper cannot be loaded. Models that depend on it will not be available.
[WARNING ] The ebltable package is not available. Models that depend on it will not be available
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 import astromodels

File ~/miniconda3/envs/py310/lib/python3.10/site-packages/astromodels/__init__.py:16, in <module>
     14 from .utils.configuration import astromodels_config
     15 from .core.memoization import use_astromodels_memoization
---> 16 from .core.model import Model
     17 from .core.model_parser import clone_model, load_model
     18 from .core.parameter import (IndependentVariable, Parameter,
     19                              SettingOutOfBounds, turn_off_parameter_transforms)

File ~/miniconda3/envs/py310/lib/python3.10/site-packages/astromodels/core/model.py:20, in <module>
     18 from astromodels.core.property import FunctionProperty
     19 from astromodels.core.tree import DuplicatedNode, Node
---> 20 from astromodels.functions.function import Function, get_function
     21 from astromodels.sources import (ExtendedSource, ParticleSource, PointSource,
     22                                  Source, SourceType)
     23 from astromodels.utils.disk_usage import disk_usage

File ~/miniconda3/envs/py310/lib/python3.10/site-packages/astromodels/functions/__init__.py:26, in <module>
     22     from .functions_1D import EBLattenuation
     24 if has_atomdb:
---> 26     from .apec import APEC, VAPEC
     28 from .dark_matter.dm_models import DMFitFunction, DMSpectra
     29 from .function import (Function1D, Function2D, Function3D, FunctionMeta,
     30                        ModelAssertionViolation)

ModuleNotFoundError: No module named 'astromodels.functions.apec'

As a result, when I try to import threeml it fails with the same error because of astromodels.

Can you please check?

grburgess commented 2 years ago

Thanks for the issue, will have a look.

grburgess commented 2 years ago

@ivvv Do you have pyatomdb installed?

ivvv commented 2 years ago

I have atomdb installed, and pyatomdb too. And did export ATOMDB=${HOME}/atomdb

import pyatomdb
pyatomdb.__version__
'0.10.8'
ivvv commented 2 years ago

Tried to build and install astromodels from a cloned github repository, but this failed with a number of errors. One complication may be that there is no HEASOFT for ARM64, so I have it through homebrew and rosetta for x86_64, but I thought HEASOFT and Xspec are not needed by default, unless I want to use Xspec models.

ivvv commented 2 years ago

Further update, I managed to install it with no errors and no problems to import atromodels and threeML, but I had to activate a virtualenv where I had python and xspec (and HEASOFT) compiled for x86_64. I am not sure if there will be a penalty on performance as running x86_64 on arm64 is through rosetta.

grburgess commented 2 years ago

@ivvv ok, interesting. From what I know, there is no real penalty at all (some x86 instructions run faster on the arm than natively). Let me know if there are further problems.

ivvv commented 2 years ago

Will do, for now it seems good.

ivvv commented 2 years ago

Unfortunately I have to re-open this thicket as the problem happens in Linux too (Ubuntu).

Trying to import astromodels fails with the same error:

ModuleNotFoundError: No module named 'astromodels.functions.apec

Looking at the github and also in the astromodels distribution files, no sub-folder apec is to be found in functions folder.

I have ATOMDB installed and so it attempts to import from .apec but there is no such folder.

When I closed the ticket, I thought it worked, but actually ATOMDB wasn't properly set up on my M1 macBook and it was not trying to import APEC and VAPEC.

I tried to re-install astromodels after I installed pyatomdb, but no success.

Can you please have a look?

ivvv commented 2 years ago

OK, solved it by editing __init__.py with the following change:

if has_atomdb:

        #from .functions import APEC, VAPEC
        from .functions.functions_1D.apec import APEC, VAPEC

And then it worked as expected.

grburgess commented 2 years ago

Oops. That was a change over. You can make a PR if you like or we will update it in the next release.

grburgess commented 2 years ago

Fixed on the dev branch. Thanks!