ACCarnall / bagpipes

Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations. Users should install with pip, not by cloning the repository.
http://bagpipes.readthedocs.io
GNU General Public License v3.0
71 stars 37 forks source link

Cannot initiate fit -- name 'pmn' is not defined #27

Closed keheintz closed 1 year ago

keheintz commented 1 year ago

Hello,

I have just tried installing and running Bagpipes, but I get the following error, which seems to suggest that PyMultiNest is not loaded correctly: Bagpipes: fitting object


NameError Traceback (most recent call last) /var/folders/91/z2qvcffn6b5ccndf82s32_fh0000gn/T/ipykernel_56739/1459370564.py in ----> 1 fit = load_results(run_id)

/var/folders/91/z2qvcffn6b5ccndf82s32_fh0000gn/T/ipykernel_56739/2772977949.py in load_results(run_id) 6 #set_model_type(run_id) 7 fit = pipes.fit(observed_galaxy, fit_instructions, run=run_id) ----> 8 fit.fit() 9 fit.posterior.get_advanced_quantities() # posterior.model_galaxy 10 return fit

/opt/anaconda3/lib/python3.9/site-packages/bagpipes/fitting/fit.py in fit(self, verbose, n_live, use_MPI) 120 start_time = time.time() 121 --> 122 with warnings.catch_warnings(): 123 warnings.simplefilter("ignore") 124 pmn.run(self.fitted_model.lnlike,

NameError: name 'pmn' is not defined

However, this bit in the .fit file seems to be compiled ok without complaining though, so I'm not sure what the issue could be: try: import pymultinest as pmn

except (ImportError, RuntimeError, SystemExit) as e: print("Bagpipes: PyMultiNest import failed, fitting will be unavailable.")

Any ideas for a fix?

Thanks! Kasper

ACCarnall commented 1 year ago

Hi Kasper, did you try installing MultiNest yourself? It doesn't get installed by default with the code. Usually the easiest way to get it is via conda.

keheintz commented 1 year ago

Hi Adam, yes I should have installed it following bagpipes installation docs -- or do you have to install pymultinest separately / after installing MultiNest?

keheintz commented 1 year ago

Update: It looks like it can read the pymultinest import now after installing it with conda.

However, now I get the following error from reading in Bagpipes:

ModuleNotFoundError Traceback (most recent call last) Input In [1], in <cell line: 4>() 2 import pandas as pd 3 import numpy as np ----> 4 import bagpipes as pipes

File /opt/anaconda3/lib/python3.9/site-packages/bagpipes/init.py:3, in 1 from future import print_function, division, absolute_import ----> 3 from . import models 4 from . import fitting 5 from . import filters

File /opt/anaconda3/lib/python3.9/site-packages/bagpipes/models/init.py:3, in 1 from future import print_function, division, absolute_import ----> 3 from . import making 5 from .stellar_model import stellar 6 from .dust_emission_model import dust_emission

File /opt/anaconda3/lib/python3.9/site-packages/bagpipes/models/making/init.py:4, in 1 from future import print_function, division, absolute_import 3 from . import igm_inoue2014 ----> 4 from . import make_cloudy_models

File /opt/anaconda3/lib/python3.9/site-packages/bagpipes/models/making/make_cloudy_models.py:9, in 5 import sys 7 from astropy.io import fits ----> 9 from ... import utils 10 from ... import config 12 from ..model_galaxy import model_galaxy

File /opt/anaconda3/lib/python3.9/site-packages/bagpipes/utils.py:5, in 3 import os 4 import numpy as np ----> 5 from astropy.cosmology import FlatLambdaCDM 8 def make_dirs(run="."): 9 """ Make local Bagpipes directory structure in working dir. """

File /opt/anaconda3/lib/python3.9/site-packages/astropy/cosmology/init.py:13, in 2 """ astropy.cosmology contains classes and functions for cosmological 3 distance measures and other cosmology-related calculations. 4 (...) 8 9 """ 11 from . import core, flrw, funcs, parameter, units, utils # noqa F401 ---> 13 from . import io # needed before 'realizations' # noqa: F401 # isort: split 14 from . import realizations 15 from .core import * # noqa F401, F403

File /opt/anaconda3/lib/python3.9/site-packages/astropy/cosmology/io/init.py:9, in 4 """ 5 Read/Write/Interchange methods for astropy.cosmology. NOT public API. 6 """ 8 # Import to register with the I/O machinery ----> 9 from . import cosmology, ecsv, mapping, model, row, table, yaml

File /opt/anaconda3/lib/python3.9/site-packages/astropy/cosmology/io/cosmology.py:84, in 78 return itis 81 # =================================================================== 82 # Register ---> 84 convert_registry.register_reader("astropy.cosmology", Cosmology, from_cosmology) 85 convert_registry.register_writer("astropy.cosmology", Cosmology, to_cosmology) 86 convert_registry.register_identifier("astropy.cosmology", Cosmology, cosmology_identify)

File /opt/anaconda3/lib/python3.9/site-packages/astropy/io/registry/core.py:108, in UnifiedInputRegistry.register_reader(self, data_format, data_class, function, force, priority) 103 raise IORegistryError("Reader for format '{}' and class '{}' is " 104 'already defined' 105 ''.format(data_format, data_class.name)) 107 if data_class not in self._delayed_docs_classes: --> 108 self._updatedoc(data_class, 'read')

File /opt/anaconda3/lib/python3.9/site-packages/astropy/io/registry/base.py:418, in _UnifiedIORegistryBase._updatedoc(self, data_class, readwrite) 414 left_indent = ' ' * min(match.start() for match in matches if match) 416 # Get the available unified I/O formats for this class 417 # Include only formats that have a reader, and drop the 'Data class' column --> 418 format_table = self.get_formats(data_class, readwrite.capitalize()) 419 format_table.remove_column('Data class') 421 # Get the available formats as a table, then munge the output of pformat() 422 # a bit and put it into the docstring.

File /opt/anaconda3/lib/python3.9/site-packages/astropy/io/registry/core.py:404, in UnifiedIORegistry.get_formats(self, data_class, readwrite) 384 def get_formats(self, data_class=None, readwrite=None): 385 """ 386 Get the list of registered I/O formats as a ~astropy.table.Table. 387 (...) 402 Table of available I/O formats. 403 """ --> 404 return super().get_formats(data_class, readwrite)

File /opt/anaconda3/lib/python3.9/site-packages/astropy/io/registry/base.py:86, in _UnifiedIORegistryBase.get_formats(self, data_class, filter_on) 64 def get_formats(self, data_class=None, filter_on=None): 65 """ 66 Get the list of registered formats as a ~astropy.table.Table. 67 (...) 84 If filter_on is not None nor a registry name. 85 """ ---> 86 from astropy.table import Table 88 # set up the column names 89 colnames = ( 90 "Data class", "Format", 91 *[self._registries[k]["column"] for k in self._registries_order], 92 "Deprecated")

File /opt/anaconda3/lib/python3.9/site-packages/astropy/table/init.py:75, in 72 import astropy.io.misc.pandas.connect # noqa: F401 74 if optional_deps.HAS_ASDF_ASTROPY: ---> 75 import asdf_astropy.io.connect 76 else: 77 import astropy.io.misc.asdf.connect

ModuleNotFoundError: No module named 'asdf_astropy.io'

ACCarnall commented 1 year ago

Hmm, haven't seen that one before, what version of astropy are you running?

keheintz commented 1 year ago

I live to idiot-proof software! I have astropy.version = '5.1'

ACCarnall commented 1 year ago

Ok that's the same version as me. I'm pretty sure this is an astropy issue though, can you successfully run "from astropy.cosmology import FlatLambdaCDM" in a python terminal?

One potential shortcut to fixing this might be to make a new anaconda environment for bagpipes, whilst installing all the dependencies from scratch. I have a yml file that should do this for you, which I'll email. Try the instructions at https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file

keheintz commented 1 year ago

No, it actually outputs an error now (which it didn't before) so there indeed may be some issue cosmology astropy package.

But thanks for the .yml file! Will try installing in a new environment with that.