Skip to content

Commit

Permalink
Merge pull request #380 from threeML/root6-compatibility
Browse files Browse the repository at this point in the history
Root6 compatibility
  • Loading branch information
ndilalla committed Oct 22, 2020
2 parents a61cbe6 + 2a97a35 commit 9e0d3da
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 91 deletions.
20 changes: 10 additions & 10 deletions build_local.sh
Expand Up @@ -43,10 +43,10 @@ USE_LOCAL=false

# Environment
libgfortranver="3.0"
NUMPYVER=1.15
#NUMPYVER=1.15
MATPLOTLIBVER=2
UPDATE_CONDA=false
XSPECVER="6.22.1"
XSPECVER="6.25"
xspec_channel=xspecmodels

if [[ ${TRAVIS_OS_NAME} == "linux" ]];
Expand All @@ -56,10 +56,9 @@ then
else # osx
miniconda_os=MacOSX
compilers="clang_osx-64 clangxx_osx-64 gfortran_osx-64"

# On macOS we also need the conda libx11 libraries used to build xspec
# We also need to pin down ncurses, for now only on macos.
xorg="xorg-libx11 ncurses=5"
xorg="xorg-libx11"
fi

# Get the version in the __version__ environment variable
Expand All @@ -74,7 +73,7 @@ echo "Python version: ${TRAVIS_PYTHON_VERSION}"
echo "Use local is: ${USE_LOCAL}"

if ${USE_LOCAL}; then
conda config --remove channels ${xspec_channel}
#conda config --remove channels ${xspec_channel}
use_local="--use-local"
else
conda config --add channels ${xspec_channel}
Expand All @@ -94,9 +93,10 @@ if [ -n "${XSPECVER}" ];
fi

if [[ ${TRAVIS_PYTHON_VERSION} == 2.7 ]]; then
PKG="pytest<4 openblas-devel=0.3.6 tk=8.5.19 astroquery=0.3.10 ipopt<3.13 pygmo=2.11.4 emcee>=3 pandas>=0.23"
#PKG="pytest<4 openblas-devel=0.3.6 tk=8.5.19 astroquery=0.3.10 ipopt<3.13 pygmo=2.11.4 emcee>=3 pandas>=0.23 krb5=1.14.6"
PKG="pytest<4 astroquery=0.3.10 pygmo=2.11.4 emcee>=3 pandas>=0.23 ipopt<3.13 pyyaml"
else
PKG="pytest pandas>=0.23 ultranest interpolation>=2.1.5"
PKG="pytest>=3.6 pandas>=0.23 ultranest interpolation>=2.1.5"
fi

echo "dependencies: ${MATPLOTLIB} ${NUMPY} ${XSPEC}"
Expand All @@ -112,13 +112,13 @@ conda config --add channels defaults

conda config --add channels threeml

conda config --add channels conda-forge/label/cf201901
#conda config --add channels conda-forge/label/cf201901

conda config --add channels conda-forge

# Create test environment
echo "Create test environment..."
conda create --yes --name $ENVNAME -c conda-forge ${use_local} python=$TRAVIS_PYTHON_VERSION ${PKG} codecov pytest-cov git ${MATPLOTLIB} ${NUMPY} ${XSPEC} astropy ${compilers} scipy krb5=1.14.6
conda create --yes --name $ENVNAME -c conda-forge ${use_local} python=$TRAVIS_PYTHON_VERSION ${PKG} codecov pytest-cov git ${MATPLOTLIB} ${NUMPY} ${XSPEC} astropy ${compilers} scipy

#openblas-devel=0.3.6 tk=8.5.19 astroquery=0.3.10 pygmo=2.11.4 "pytest<4"
#libgfortran=${libgfortranver}
Expand All @@ -128,7 +128,7 @@ conda create --yes --name $ENVNAME -c conda-forge ${use_local} python=$TRAVIS_PY
echo "Activate test environment..."

source $CONDA_PREFIX/etc/profile.d/conda.sh
#source $HOME/work/fermi/miniconda3/etc/profile.d/conda.sh
#source $HOME/work/miniconda3/etc/profile.d/conda.sh
conda activate $ENVNAME

# Build package
Expand Down
16 changes: 8 additions & 8 deletions ci/build_and_test.sh
Expand Up @@ -24,7 +24,7 @@ else # osx

# On macOS we also need the conda libx11 libraries used to build xspec
# We also need to pin down ncurses, for now only on macos.
xorg="xorg-libx11 ncurses=5"
xorg="xorg-libx11"
fi


Expand All @@ -39,10 +39,10 @@ echo "HOME= ${HOME}"
echo "Building ${PKG_VERSION} ..."
echo "Python version: ${TRAVIS_PYTHON_VERSION}"

libgfortranver="3.0"
NUMPYVER=1.15
#libgfortranver="3.0"
#NUMPYVER=1.15
MATPLOTLIBVER=2
XSPECVER="6.22.1"
XSPECVER="6.25"
xspec_channel=xspecmodels

echo "Building ${PKG_VERSION} ..."
Expand All @@ -60,9 +60,9 @@ if [ -n "${XSPECVER}" ];
fi

if [[ ${TRAVIS_PYTHON_VERSION} == 2.7 ]]; then
PKG="pytest<4 openblas-devel=0.3.6 tk=8.5.19 astroquery=0.3.10 ipopt<3.13 pygmo=2.11.4 emcee>=3 pandas>=0.23"
PKG="pytest<4 astroquery=0.3.10 pygmo=2.11.4 emcee>=3 pandas>=0.23 ipopt<3.13 pyyaml"
else
PKG="pytest pandas>=0.23 ultranest interpolation>=2.1.5"
PKG="pytest>=3.6 pandas>=0.23 ultranest interpolation>=2.1.5"
fi

echo "dependencies: ${MATPLOTLIB} ${NUMPY} ${XSPEC}"
Expand All @@ -78,12 +78,12 @@ conda config --add channels defaults

conda config --add channels threeml

conda config --add channels conda-forge/label/cf201901
#conda config --add channels conda-forge/label/cf201901

conda config --add channels conda-forge

# Create test environment
conda create --yes --name test_env -c conda-forge python=$TRAVIS_PYTHON_VERSION ${PKG} codecov pytest-cov git ${MATPLOTLIB} ${NUMPY} ${XSPEC} astropy ${compilers} scipy krb5=1.14.6
conda create --yes --name test_env -c conda-forge python=$TRAVIS_PYTHON_VERSION ${PKG} codecov pytest-cov git ${MATPLOTLIB} ${NUMPY} ${XSPEC} astropy ${compilers} scipy

if [[ "$TRAVIS_OS_NAME" == "removeme" ]]; then

Expand Down
28 changes: 4 additions & 24 deletions ci/cron_install_and_test.sh
Expand Up @@ -22,34 +22,14 @@ elif (( $TRAVIS_BUILD_NUMBER % 4 == 1 )); then
# Testing with xspec and root
elif (( $TRAVIS_BUILD_NUMBER % 4 == 2 )); then

if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then

echo "Testing with xspec-modelsonly and root with python $TRAVIS_PYTHON_VERSION"
bash install_3ML.sh --batch --with-xspec --with-root --python $TRAVIS_PYTHON_VERSION

else

echo "Root5 is not available for python 3."
echo "Cannot test with xspec-modelsonly and root. Exiting."
exit 0

fi
echo "Testing with xspec-modelsonly and root with python $TRAVIS_PYTHON_VERSION"
bash install_3ML.sh --batch --with-xspec --with-root --python $TRAVIS_PYTHON_VERSION

# Testing with Fermi software
else

if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then

echo "Testing with xspec-modelsonly and Fermi software with python $TRAVIS_PYTHON_VERSION"
bash install_3ML.sh --batch --with-xspec --with-fermi --python $TRAVIS_PYTHON_VERSION

else

echo "Fermi tools are not available for python 3 yet."
echo "Cannot test with xspec-modelsonly and Fermi software. Exiting."
exit 0

fi
echo "Testing with xspec-modelsonly and Fermi software with python $TRAVIS_PYTHON_VERSION"
bash install_3ML.sh --batch --with-xspec --with-fermi --python $TRAVIS_PYTHON_VERSION

fi

Expand Down
23 changes: 10 additions & 13 deletions conda-dist/recipes/threeml/meta.yaml
Expand Up @@ -22,17 +22,16 @@ requirements:
- python
#- setuptools
#- toolchain
- numpy>=1.15,<1.16 # [py2k]
- numpy>=1.15 # [py3k]
- numpy>=1.15
#- scipy >=0.18
- emcee>=3
#- astropy >=1.0.3
#- matplotlib
- uncertainties
- pyyaml==3.13
- pyyaml>=5.1
- dill
- iminuit>=1.2
- astromodels
- astromodels>=2
- astroquery<0.4 # [py2k]
- astroquery # [py3k]
- corner>=1.0.2
Expand All @@ -43,32 +42,30 @@ requirements:
- pymultinest
- ultranest # [py3k]
- dynesty>=1
- pygmo>=2.4,<=2.11.4 # [py2k]
- pygmo>=2.4 # [py3k]
#- pygmo>=2.4,<=2.11.4 # [py2k]
- pygmo>=2.4
- ipywidgets
- numba
#- ipython
- ipyparallel
- py
- tk==8.5.19 # [py2k]
#- tk==8.5.19 # [py2k]
- ipopt<3.13 # [py2k]
- numdifftools
- interpolation>=2.1.5 # [py3k]


run:
- python
- numpy>=1.15,<1.16 # [py2k]
- numpy>=1.15 # [py3k]
- scipy>=0.18
- emcee>=3
- astropy>=1.0.3
- matplotlib
- uncertainties
- pyyaml==3.13
- pyyaml>=5.1
- dill
- iminuit>=1.2
- astromodels
- astromodels>=2
- astroquery<0.4 # [py2k]
- astroquery # [py3k]
- corner>=1.0.2
Expand All @@ -78,8 +75,8 @@ requirements:
- pymultinest
- ultranest # [py3k]
- dynesty>=1
- pygmo>=2.4,<=2.11.4 # [py2k]
- pygmo>=2.4 # [py3k]
#- pygmo>=2.4,<=2.11.4 # [py2k]
- pygmo>=2.4
- ipywidgets
- ipython
- ipyparallel
Expand Down
32 changes: 11 additions & 21 deletions install_3ML.sh
Expand Up @@ -264,35 +264,32 @@ conda config --add channels defaults

conda config --add channels threeml

conda config --add channels conda-forge/label/cf201901

conda config --add channels conda-forge

if [[ ${PYTHON_VERSION} == "2.7" ]]; then
conda config --add channels conda-forge/label/cf201901
fi

PACKAGES_TO_INSTALL="astromodels threeml"
PACKAGES_TO_INSTALL="astromodels>=2 threeml"

if [[ "${INSTALL_XSPEC}" == "yes" ]]; then

PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} xspec-modelsonly=6.22.1"
PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} xspec-modelsonly=6.25"
conda config --add channels xspecmodels

fi

if [[ "${INSTALL_ROOT}" == "yes" ]]; then

PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} root5"
PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} root"

fi

if [[ "${INSTALL_FERMI}" == "yes" ]]; then

PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} fermitools fermipy"

#conda config --add channels conda-forge/label/cf201901
conda config --add channels fermi
if [[ $PYTHON_VERSION == "2.7" ]]; then
conda config --add channels fermi/label/master
PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} clhep=2.4.1.0"
else
conda config --add channels fermi
fi
PACKAGES_TO_INSTALL="${PACKAGES_TO_INSTALL} fermitools"

fi

Expand Down Expand Up @@ -483,14 +480,7 @@ EOM
conda activate ${ENV_NAME}

# Fix needed to solve the "readinto" AttributeError due to older future package
conda install --yes -c conda-forge future

# Workaround needed to meet the requirement on ccfits on linux systems
if [[ "$os_guessed" == "linux" ]] && [[ "${INSTALL_XSPEC}" == "yes" ]]; then
conda install --yes -c conda-forge ccfits=2.5
elif [[ "$os_guessed" == "osx" ]] && [[ "${INSTALL_XSPEC}" == "yes" ]]; then
conda install --yes -c conda-forge/label/cf201901 ccfits=2.5
fi
#conda install --yes -c conda-forge future

mv activate.csh $CONDA_PREFIX/bin
mv deactivate.csh $CONDA_PREFIX/bin
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -37,7 +37,7 @@ install_requires =
astropy>=1.3.3
matplotlib
uncertainties
pyyaml==3.13
pyyaml>=5.1
dill
iminuit>=1.2
astromodels
Expand Down
10 changes: 10 additions & 0 deletions threeML/__init__.py
Expand Up @@ -17,6 +17,16 @@

mpl.use("Agg")

# Workaround to a CFITSIO issue
try:
import ROOT
except ImportError:
pass
try:
import pyLikelihood
except ImportError:
pass

# Import version (this has to be placed before the import of serialization
# since __version__ needs to be defined at that stage)
from ._version import get_versions
Expand Down
2 changes: 1 addition & 1 deletion threeML/analysis_results.py
Expand Up @@ -99,7 +99,7 @@ def _load_one_results(fits_extension):

# Gather the optimized model
serialized_model = _escape_back_yaml_from_fits(fits_extension.header.get("MODEL"))
model_dict = my_yaml.load(serialized_model)
model_dict = my_yaml.load(serialized_model, Loader=yaml.FullLoader)

optimized_model = ModelParser(model_dict=model_dict).get_model()

Expand Down
4 changes: 2 additions & 2 deletions threeML/config/config.py
Expand Up @@ -52,7 +52,7 @@ def __init__(self):

try:

configuration = yaml.load(f)
configuration = yaml.load(f, Loader=yaml.FullLoader)

except:

Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self):

with open(user_config_path) as f:

configuration = yaml.load(f)
configuration = yaml.load(f, Loader=yaml.FullLoader)

# Test if the local/configuration is ok

Expand Down
25 changes: 17 additions & 8 deletions threeML/minimizer/ROOT_minimizer.py
Expand Up @@ -35,22 +35,30 @@
300: "Covariance matrix is not positive defined",
}


class FuncWrapper(ROOT.TPyMultiGenFunction):
def __init__(self, function, dimensions):

ROOT.TPyMultiGenFunction.__init__(self, self)
#root_class = None
#try:
# root_class = ROOT.TPyMultiGenFunction
#except AttributeError:
# root_class = ROOT.Math.IMultiGenFunction

class FuncWrapper(ROOT.Math.IMultiGenFunction):

def setup(self, function, dimensions):
self.function = function
self.dimensions = int(dimensions)

def NDim(self):
return self.dimensions

def DoEval(self, args):

new_args = [args[i] for i in range(self.dimensions)]

return self.function(*new_args)

def Clone(self):
f = FuncWrapper()
f.setup(f.function, f.dimensions)
ROOT.SetOwnership(f, False)
return f


class ROOTMinimizer(LocalMinimizer):
Expand All @@ -76,7 +84,8 @@ def _setup(self, user_setup_dict):

# Setup the minimizer algorithm

self.functor = FuncWrapper(self.function, self.Npar)
self.functor = FuncWrapper()
self.functor.setup(self.function, self.Npar)
self.minimizer = ROOT.Minuit2.Minuit2Minimizer("Minimize")
self.minimizer.Clear()
self.minimizer.SetMaxFunctionCalls(setup_dict["max_function_calls"])
Expand Down

0 comments on commit 9e0d3da

Please sign in to comment.