Skip to content

Commit

Permalink
Add support for mesa>11035
Browse files Browse the repository at this point in the history
This has moved all the shared library building logic into mesa itself
thus now we just need to flip an option in the makefile and recompile
  • Loading branch information
rjfarmer committed Sep 7, 2018
1 parent dd639cd commit 018b94e
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 51 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Note: pyMesa currently only works on linux, macs will fail to build.

[gfort2py](https://github.com/rjfarmer/gfort2py) (Also available via pip) (needs version >= 1.0.11)

numpy
All versions need numpy and patch

if using MESA < 11035 then you also need:

libtool

automake

chrpath

patch


## Building

### SDK's
Expand All @@ -42,6 +42,9 @@ chmod u+x mesa-setup.sh

This script should only be run once to setup up mesa. It can be ran again if you do a ./clean inside the MESA_DIR.

#### MESA < 11035
If using mesa version < 11035 then the following applies:

Adipls, gyre and stella are not currently built as part of this.

While we can use the individual MESA modules we can not currently run a full star (or binary) model, in either python or fortran.
Expand All @@ -51,6 +54,7 @@ While we can use the individual MESA modules we can not currently run a full sta
- 10000
- 10108
- 10398
- >11035 (non released mesa version)
Other versions can be supported upon request.

Expand All @@ -66,14 +70,15 @@ Will override the version check and attempt to build MESA using the patches for
````bash
# Set MESA_DIR and initialize the sdk

# If using MESA < 11035 set the LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MESA_DIR/lib:$LD_LIBRARY_PATH
python3
````

## Structure

The only python file that is actually needed to run this is pyMesaUtils.py. This file contains the code needed to interface with mesa. Inside the mesa_models/ folder
contain examples of how to interface with most of meas's modules. pydfriddr/ folder contains examples for testing MESA's analytic derivatives with a numerical derivative.
contain examples of how to interface with most of MESA's modules. pydfriddr/ folder contains examples for testing MESA's analytic derivatives with a numerical derivative.


## Usage
Expand Down Expand Up @@ -157,6 +162,8 @@ An example of this can be found in eos.py.

## Uninstalling

If using MESA < 11035:

The best bet is just to re-download mesa, during the setup phase we alter a lot of files. If you want to try to keep your MESA_DIR then something like this should work:

````bash
Expand All @@ -176,6 +183,9 @@ rm -rf $MESA_DIR/crlibm/crlibm-patches $MESA_DIR/{star,binary}/skip_test

````

If using MESA >= 11035, then in utils/makefile_header switch USE_SHARED=YES to USE_SHARED=NO and do a ./clean
and ./mk in $MESA_DIR


## Bug reports:

Expand All @@ -191,7 +201,7 @@ or issues on the github tracker.

## Citating

People who use pyMESA in papers should cite this using the zenodo link for the version they used. If you use pyMesa in a project (resaech or teaching), let me know and i can help advertise here (also useful for me to help
People who use pyMESA in papers should cite this using the zenodo link for the version they used. If you use pyMesa in a project (research or teaching), let me know and i can help advertise here (also useful for me to help
with funding requests). Current versions citation is in the CITATION file.

## Known Projects using pyMesa
Expand Down
87 changes: 58 additions & 29 deletions mesa-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if [[ ! "$PATH" == *"$MESASDK_ROOT"* ]];then
exit 1
fi

DO_NOTHING=0

MESA_VERSION=$(<"$MESA_DIR/data/version_number")

export SHARED_LIB=so
Expand Down Expand Up @@ -101,7 +103,9 @@ then
#if [[ "$SDK_HAS_LAPACK_SO" == "1" ]]; then
#cp patches/0003-sdk-with-lapack-10000.patch "$MESA_DIR"/patches/.
#fi

elif [[ "$MESA_VERSION" -gt 11035 ]]
then
cp patches/0001-turn-shared-on.patch "$MESA_DIR"/patches/.
else
echo "MESA version $MESA_VERSION is not supported"
echo "Open an issue on github to request your mesa version"
Expand All @@ -118,16 +122,22 @@ cd "$MESA_DIR"
echo "Clean MESA"
./clean

#Skip Tests in star as we can't run a full model yet
/usr/bin/touch star/skip_test
/usr/bin/touch binary/skip_test
if [[ "$MESA_VERSION" -lt 11035 ]]
then
#Skip Tests in star as we can't run a full model yet
/usr/bin/touch star/skip_test
/usr/bin/touch binary/skip_test
fi

if [ -z "$PYMESA_SKIP_PATCH" ]
then
echo "Patching mesa"

mkdir -p "$MESA_DIR/crlibm/crlibm-patches"

if [[ "$MESA_VERSION" -lt 11035 ]]
then
mkdir -p "$MESA_DIR/crlibm/crlibm-patches"
fi

for i in patches/*;
do
patch -f -p1 < $i
Expand All @@ -141,12 +151,16 @@ then
exit 0
fi

if [[ "$(uname)" == "Darwin" ]];then
export DYLD_LIBRARY_PATH=../../make:../make:$MESA_DIR/lib:$DYLD_LIBRARY_PATH
else
export LD_LIBRARY_PATH=../../make:../make:$MESA_DIR/lib:$LD_LIBRARY_PATH
if [[ "$MESA_VERSION" -lt 11035 ]]
then
if [[ "$(uname)" == "Darwin" ]];then
export DYLD_LIBRARY_PATH=../../make:../make:$MESA_DIR/lib:$DYLD_LIBRARY_PATH
else
export LD_LIBRARY_PATH=../../make:../make:$MESA_DIR/lib:$LD_LIBRARY_PATH
fi
fi


./mk
if [[ $? != 0 ]] || [[ ! -f "$MESA_DIR/lib/libstar.$SHARED_LIB" ]] ;then
echo
Expand All @@ -161,24 +175,39 @@ if [[ $? != 0 ]] || [[ ! -f "$MESA_DIR/lib/libstar.$SHARED_LIB" ]] ;then
exit 1
fi

echo
echo
echo
echo "****************************************************************"
echo "pyMESA build was succesfull"
if [[ "$(uname)" == "Darwin" ]];then
echo "Each time you wish to use this you must set the DYLD_LIBRARAY_PATH variable"
else
echo "Each time you wish to use this you must set the LD_LIBRARAY_PATH variable"
fi
echo "After the mesasdk has been initilized:"
if [[ "$(uname)" == "Darwin" ]];then
echo 'export DYLD_LIBRARY_PATH=$MESA_DIR/lib:$DYLD_LIBRARY_PATH'
if [[ "$MESA_VERSION" -lt 11035 ]]
then
echo
echo
echo
echo "****************************************************************"
echo "pyMESA build was succesfull"
if [[ "$(uname)" == "Darwin" ]];then
echo "Each time you wish to use this you must set the DYLD_LIBRARAY_PATH variable"
else
echo "Each time you wish to use this you must set the LD_LIBRARAY_PATH variable"
fi
echo "After the mesasdk has been initilized:"
if [[ "$(uname)" == "Darwin" ]];then
echo 'export DYLD_LIBRARY_PATH=$MESA_DIR/lib:$DYLD_LIBRARY_PATH'
else
echo 'export LD_LIBRARY_PATH=$MESA_DIR/lib:$LD_LIBRARY_PATH'
fi
echo "Do not run this script again on the same MESA_DIR"
echo "****************************************************************"
echo
echo
echo
else
echo 'export LD_LIBRARY_PATH=$MESA_DIR/lib:$LD_LIBRARY_PATH'
echo
echo
echo
echo "****************************************************************"
echo "pyMESA build was succesfull"
echo "****************************************************************"
echo
echo
echo

fi
echo "Do not run this script again on the same MESA_DIR"
echo "****************************************************************"
echo
echo
echo

25 changes: 25 additions & 0 deletions patches/0001-turn-shared-on.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0d8d4c40c318afcddd18a99ebd82edc7c036a69b Mon Sep 17 00:00:00 2001
From: Robert Farmer <[email protected]>
Date: Fri, 7 Sep 2018 15:04:04 +0200
Subject: [PATCH] turn shared on

---
utils/makefile_header | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/makefile_header b/utils/makefile_header
index c22aa247f..688b4cf2f 100644
--- a/utils/makefile_header
+++ b/utils/makefile_header
@@ -86,7 +86,7 @@ USE_STUB_FOR_CRLIBM = NO

# step 9) Build shared libraries? Needed if you want mesa to be usable in python

-USE_SHARED = NO
+USE_SHARED = YES


#################################################################
--
2.17.1

46 changes: 30 additions & 16 deletions pyMesaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ def _versiontuple(v):
LIB_DIR = os.path.join(MESA_DIR,'lib')
INCLUDE_DIR = os.path.join(MESA_DIR,'include')

if "LD_LIBRARY_PATH" not in os.environ:
raise ValueError("Must set LD_LIBRARY_PATH environment variable")
elif LIB_DIR not in os.environ['LD_LIBRARY_PATH']:
raise ValueError("Must have $MESA_DIR/lib in LD_LIBRARY_PATH environment variable")


RATES_DATA=os.path.join(DATA_DIR,'rates_data')
EOSDT_DATA=os.path.join(DATA_DIR,'eosDT_data')
EOSPT_DATA=os.path.join(DATA_DIR,'eosPT_data')
Expand All @@ -78,6 +72,12 @@ def _versiontuple(v):
v=f.readline().strip()
MESA_VERSION=int(v)

if MESA_VERSION < 11035:
if "LD_LIBRARY_PATH" not in os.environ:
raise ValueError("Must set LD_LIBRARY_PATH environment variable")
elif LIB_DIR not in os.environ['LD_LIBRARY_PATH']:
raise ValueError("Must have $MESA_DIR/lib in LD_LIBRARY_PATH environment variable")

p=sys.platform.lower()

if p == "linux" or p == "linux2":
Expand Down Expand Up @@ -135,23 +135,37 @@ def buildModule(module):
finally:
os.chdir(cwd)

os.chdir(LIB_DIR)
try:
x = subprocess.call("chrpath -r lib"+module+"."+LIB_EXT,shell=True)
if x:
raise ValueError("chrpath failed")
except:
raise
finally:
os.chdir(cwd)
if MESA_VERSION < 11035:
os.chdir(LIB_DIR)
try:
x = subprocess.call("chrpath -r lib"+module+"."+LIB_EXT,shell=True)
if x:
raise ValueError("chrpath failed")
except:
raise
finally:
os.chdir(cwd)

print("Built "+str(module))

def buildRunStarSupport():
cwd = os.getcwd()
os.chdir(os.path.join(MESA_DIR,'star','make'))
try:
x = subprocess.call('gfortran -Wno-uninitialized -fno-range-check -fmax-errors=12 -fPIC -shared -fprotect-parens -fno-sign-zero -fbacktrace -ggdb -finit-real=snan -fopenmp -std=f2008 -Wno-error=tabs -I../public -I../private -I../../include -I'+os.path.join(MESASDK_ROOT,'include')+' -Wunused-value -Werror -W -Wno-compare-reals -Wno-unused-parameter -fimplicit-none -O2 -ffree-form -x f95-cpp-input -I../defaults -I../job -I../other ../job/run_star_support.f90 -o librun_star_support.'+SHARED_LIB,shell=True)
compile_cmd = ['gfortran -Wno-uninitialized -fno-range-check',
'-fmax-errors=12 -fPIC -shared -fprotect-parens',
'-fno-sign-zero -fbacktrace -ggdb -finit-real=snan',
'-fopenmp -std=f2008 -Wno-error=tabs -I../public',
'-I../private -I../../include',
'-I'+os.path.join(MESASDK_ROOT,'include'),
'-Wunused-value -Werror -W -Wno-compare-reals',
'-Wno-unused-parameter -fimplicit-none -O2',
'-ffree-form -x f95-cpp-input -I../defaults',
'-I../job -I../other ../job/run_star_support.f90',
'-Wl,-rpath=' + LIB_DIR,
'-o librun_star_support.'+LIB_EXT]

x = subprocess.call(" ".join(compile_cmd),shell=True))
if x:
raise ValueError("Build run_star_support failed")
except:
Expand Down

0 comments on commit 018b94e

Please sign in to comment.