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

Ormorod cmake #1

Open
wants to merge 125 commits into
base: cmake-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
182e021
General code cleanup
williamjameshandley Mar 8, 2022
0a89af0
Updated to cray makefile for NERSC compatibility (#85)
Pablo-Lemos May 26, 2022
e00386b
numpy int64 incompatibility fix (#84)
williamjameshandley May 26, 2022
6f2ecc3
removed cmake modifying setup_cmake_template.py gymnastics
Jun 3, 2022
e183ec9
removed run_cmake workflow and added macos to CI
Jun 3, 2022
48fd7d2
removed run_cmake workflow and added macos to CI
Jun 3, 2022
ee21164
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 3, 2022
7268b3c
added cmake-dev to pull request branches
Jun 3, 2022
4dd1323
changed macos workflow to use pip3
Jun 3, 2022
9df751e
removed gcc from matrix
Jun 3, 2022
1168bb1
manually added cmake fortran compiler
Jun 3, 2022
1668aa4
specified python 3.8 for macos
Jun 3, 2022
8d6158e
back to just pip
Jun 3, 2022
b2e6324
added python setup to macos
Jun 3, 2022
5124d57
changed to brewed python
Jun 3, 2022
8a00e8b
changed to python3 and pip3
Jun 3, 2022
73a6180
changed to python3 and pip3
Jun 3, 2022
911e102
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 3, 2022
b0c97fa
readded checkout
Jun 3, 2022
bb21b1a
switched to gcc, with additional brew install
Jun 3, 2022
feda699
took out fortran compiler from cmake
Jun 3, 2022
de74629
specify fortran compiler with environment variable
Jun 3, 2022
4cfab4f
echo which gfortran and gcc
Jun 3, 2022
2bed9c4
echo which gfortran and gcc
Jun 3, 2022
0992223
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 3, 2022
551535f
removed echo
Jun 3, 2022
aa74597
removed accidental t
Jun 3, 2022
01e6fec
added gfortran to brew install
Jun 3, 2022
7085bd5
set FC envonment variable in correct place
Jun 3, 2022
7ffa247
gfortran -> gfortran-11
Jun 3, 2022
efb7819
set CXX compiler to gcc-11
Jun 3, 2022
ad64364
Merge pull request #2 from PolyChord/master
AdamOrmondroyd Jun 3, 2022
4f3f5ae
removed brew install gfortran
Jun 3, 2022
c19997d
explicit numpy import
Jun 3, 2022
fef777c
renamed matrix element to homebrew
Jun 6, 2022
35d3503
attempt to brew install specific python version
Jun 6, 2022
ac5ae4b
explicit python version everywhere
Jun 6, 2022
ba2d09e
use pyenv to control python version
Jun 6, 2022
9993932
specify 3.8.13
Jun 6, 2022
ddb866e
changed pip3 back to pip
Jun 6, 2022
ed990e0
set global python to matrix version
Jun 6, 2022
586f347
added eval "$(pyenv init -)" to hopefully get pyenv working
Jun 6, 2022
836d0f0
Added eval "$(pyenv init -)"; python --version to install pypolychord…
Jun 6, 2022
75ef79e
set PYTHON_EXECUTABLE to which python
Jun 6, 2022
9a7c58e
try using setup-python
Jun 6, 2022
d6ac7f8
back to just python3.8
Jun 6, 2022
529c2e0
check which python
Jun 6, 2022
462e27a
check which python
Jun 6, 2022
ca44fdd
commented our accidental pyenv eval
Jun 6, 2022
cb24c94
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 6, 2022
f9cf0ad
add set Python3_EXECUTABLE
Jun 6, 2022
e3170f0
instead set Python3_ROOT_DIR
Jun 6, 2022
ec01ab1
changed to setup-python@v3
Jun 6, 2022
8b46ed4
put Python3_ROOT_DIR where I think it's actually supposed to go
Jun 6, 2022
c8e887f
got python path in a separate command
Jun 6, 2022
5a89e66
got python path in a separate command
Jun 6, 2022
093c21e
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 6, 2022
de17a23
message(python path)
Jun 6, 2022
4e1f803
added message type STATUS
Jun 6, 2022
23b56af
try making python venv
Jun 6, 2022
505c168
added source env to all run sections
Jun 6, 2022
13eef87
got rid of venv stuff again, added echo to which python
Jun 6, 2022
de4e8cc
readded ROOT_DIR
Jun 6, 2022
f0f85c3
corrected indentation
Jun 6, 2022
e559584
pip install cmake instead of brew install
Jun 6, 2022
ad10659
add cmake --version
Jun 6, 2022
8dea67c
Revert "add cmake --version"
Jun 6, 2022
93f5507
Revert "pip install cmake instead of brew install"
Jun 6, 2022
06b92c2
changed find strategy to LOCATION
Jun 6, 2022
df15b25
set python version for cmake to sys.executable, rather than messing w…
Jun 6, 2022
5224ba0
added missing underscore
Jun 6, 2022
a74def4
changed sys.executable to /Users/adam/Documents/polychordtest/env_pyp…
Jun 6, 2022
9052838
corrected placement of -DPython3_EXECUTABLE
Jun 6, 2022
152abd3
commented out non-mpi test
Jun 6, 2022
c8fb44d
explicit numpy install
Jun 6, 2022
c748a5c
uncommented non-mpi test
Jun 6, 2022
b091072
changed to python 3.9
Jun 6, 2022
4a4b1e5
back to python3.8, specify macos 10.15
Jun 6, 2022
5d204d4
added import pypolychord test
Jun 6, 2022
36e916a
specify 3.8.2
Jun 7, 2022
03089e0
removed unecessary pyenv install
Jun 7, 2022
01f7b55
removed explicit numpy import
Jun 7, 2022
b207ada
switched from gcc to clang
Jun 7, 2022
f0a4a63
let's see what brew install numpy does
Jun 7, 2022
5a4aa5f
back to just 3.8
Jun 7, 2022
2341fa4
added print statement to check run_pypolychord gets to when run_pypol…
Jun 7, 2022
3bc5c61
added more print statements
Jun 7, 2022
ecdc8b2
even more print statements
Jun 7, 2022
45af7ad
missing quote marks
Jun 7, 2022
bf2d410
added hello_world.py and workflow step
Jun 7, 2022
0f298e1
ls before python run_pypolychord.py
Jun 7, 2022
81b2cc3
import pypolychord
Jun 7, 2022
b4369a2
numpy import
Jun 7, 2022
d563da6
from pypolychord.settings import PolyChordSettings
Jun 7, 2022
cd1a0b0
from pypolychord.priors import UniformPrior
Jun 7, 2022
7fb8d51
removed all but UniformPrior import
Jun 7, 2022
78acc66
specify numpy 1.21
Jun 7, 2022
5719486
specify numpy 1.21
Jun 7, 2022
992cd44
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 7, 2022
42fe609
specity numpy 1.21 in setup
Jun 7, 2022
e917863
requirement numpy 1.21
Jun 7, 2022
c903fd4
numpy 1.21.6
Jun 7, 2022
f860e63
macos-12
Jun 7, 2022
e667733
python 3.9.13
Jun 7, 2022
68fe2c3
from scipy.special import erfinv
Jun 7, 2022
3b4d96c
copied across run_pypolychord.py up until running
Jun 7, 2022
6c3eeaf
just import erfinv lol
Jun 7, 2022
6e04e7d
remembered to install scipy
Jun 7, 2022
53fe9e1
install polychord again
Jun 7, 2022
57d43e0
import pypolychord
Jun 7, 2022
fba2c02
run_pypolychord.py
Jun 7, 2022
cf0ab71
actually run this time
Jun 7, 2022
7670737
added flush
Jun 7, 2022
d78fd7c
changed cmake_build_ext to CMakeBuildExt
Jun 7, 2022
390745d
changed build_py to build_ext
Jun 7, 2022
2e258e3
back to build_py
Jun 7, 2022
c5c39fa
Revert "back to build_py"
Jun 7, 2022
0364713
Revert "changed build_py to build_ext"
Jun 7, 2022
7d52dec
Merge branch 'cmake-dev' into ormorod-cmake
Jun 8, 2022
144fadf
Merge branch 'cmake-dev' into ormorod-cmake
Jun 8, 2022
896ab1a
removed accidental tkinter import
AdamOrmondroyd Jun 8, 2022
0978711
Merge branch 'ormorod-cmake' of github.com:Ormorod/PolyChordLite into…
Jun 8, 2022
717d076
build_cmake attempt to set compilers properly
Jun 8, 2022
3c2fdea
added env to cmake call
Jun 8, 2022
85acf5a
added gfortran to brew install
Jun 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, cmake-dev ]
# don't run the CRON part in my fork
# schedule:
# - cron: "0 0 * * *"
Expand Down Expand Up @@ -42,3 +42,44 @@ jobs:

- name: Test pypolychord (MPI)
run: mpirun -np 2 python run_pypolychord.py

pip_macos:
runs-on: macos-12
# env:
# FC: gfortran-11
# # CXX: gcc-11
# CXX: gfortran-11
strategy:
matrix:
# cc: [gcc]
cc: [clang]
python-version: [3.9.13]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
brew install cmake openmpi gcc gfortran
python -m pip install --upgrade pip

- name: Install pypolychord
run: |
python -m pip install -v .

- name: Import pypolychord
run: python -c "import pypolychord"

- name: Hello world
run: python hello_world.py

- name: Test pypolychord
run: |
python run_pypolychord.py

# - name: Test pypolychord (MPI)
# run: mpirun -np 2 python run_pypolychord.py
83 changes: 0 additions & 83 deletions .github/workflows/run_cmake.yaml

This file was deleted.

31 changes: 3 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ if (python)
# The Compiled .so file
#################################################################


# PyPolyChord stuff
message(STATUS "Enabling Python package build")
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)

# find out the suffix for the current python version
EXECUTE_PROCESS(
Expand Down Expand Up @@ -112,31 +113,5 @@ if (python)
# place all outputs in one place
install(TARGETS _pypolychord
LIBRARY DESTINATION ${target_lib_dir})

#################################################################
# The simple python module
#################################################################

set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup_cmake_template.py")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
set(DEPS "${CMAKE_CURRENT_SOURCE_DIR}/pypolychord/__init__.py")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp") # dummy target for dependence

# fill in the variables of the setup.py file
configure_file(${SETUP_PY_IN} ${SETUP_PY})

# custom target
add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} build
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${DEPS} _pypolychord)
add_custom_target(target ALL DEPENDS ${OUTPUT})

# installation with setup.py
if (python_user_install)
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install)")
else (python_user_install)
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --user)")
endif (python_user_install)


endif (python)
8 changes: 4 additions & 4 deletions Makefile_cray
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ LDSHARED = $(LD) -shared
# Archive tool
AR = ar rv

FFLAGS += -fpp -fpic -qopenmp -dynamic
CXXFLAGS += -fpic -qopenmp -dynamic
FFLAGS += -cpp -fpic -fopenmp -dynamic
CXXFLAGS += -fpic -fopenmp -dynamic
CFLAGS += -fpic
#setting for Edison/Cori on NERSC
ifneq ($(NERSC_HOST),)
FFLAGS += -axMIC-AVX512,CORE-AVX2
CXXFLAGS += -axMIC-AVX512,CORE-AVX2
FFLAGS += -ffree-line-length-none -fallow-argument-mismatch
CXXFLAGS += -ffree-line-length-none -fallow-argument-mismatch
endif

ifdef IPO
Expand Down
57 changes: 57 additions & 0 deletions hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
print("hello world")
from scipy.special import erfinv
print("from numpy import pi, log, sqrt")
from numpy import pi, log, sqrt
print("import pypolychord")
import pypolychord
print("from pypolychord.settings import PolyChordSettings")
from pypolychord.settings import PolyChordSettings
print("from pypolychord.priors import UniformPrior")
from pypolychord.priors import UniformPrior
try:
from mpi4py import MPI
except ImportError:
pass


#| Define a four-dimensional spherical gaussian likelihood,
#| width sigma=0.1, centered on the 0 with one derived parameter.
#| The derived parameter is the squared radius

nDims = 4
nDerived = 1
sigma = 0.1

def likelihood(theta):
""" Simple Gaussian Likelihood"""

nDims = len(theta)
r2 = sum(theta**2)
logL = -log(2*pi*sigma*sigma)*nDims/2.0
logL += -r2/2/sigma/sigma

return logL, [r2]

#| Define a box uniform prior from -1 to 1

def prior(hypercube):
""" Uniform prior from [-1,1]^D. """
return UniformPrior(-1, 1)(hypercube)

#| Optional dumper function giving run-time read access to
#| the live points, dead points, weights and evidences

def dumper(live, dead, logweights, logZ, logZerr):
print("Last dead point:", dead[-1])

#| Initialise the settings
print("about to create settings")
settings = PolyChordSettings(nDims, nDerived)
settings.file_root = 'gaussian'
settings.nlive = 200
settings.do_clustering = True
settings.read_resume = False

#| Run PolyChord
print("about to run_pypolychord", flush=True)
output = pypolychord.run_polychord(likelihood, nDims, nDerived, settings, prior, dumper)
3 changes: 3 additions & 0 deletions pypolychord/polychord.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def wrap_loglikelihood(theta, phi):
def wrap_prior(cube, theta):
theta[:] = prior(cube)

settings.grade_dims = [int(d) for d in settings.grade_dims]
settings.nlives = {float(logL):int(nlive) for logL, nlive in settings.nlives.items()}

# Run polychord from module library
_pypolychord.run(wrap_loglikelihood,
wrap_prior,
Expand Down
8 changes: 6 additions & 2 deletions run_pypolychord.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
print("from numpy import pi, log, sqrt")
from numpy import pi, log, sqrt
print("import pypolychord")
import pypolychord
print("from pypolychord.settings import PolyChordSettings")
from pypolychord.settings import PolyChordSettings
print("from pypolychord.priors import UniformPrior")
from pypolychord.priors import UniformPrior
try:
from mpi4py import MPI
Expand Down Expand Up @@ -39,15 +43,15 @@ def dumper(live, dead, logweights, logZ, logZerr):
print("Last dead point:", dead[-1])

#| Initialise the settings

print("about to create settings")
settings = PolyChordSettings(nDims, nDerived)
settings.file_root = 'gaussian'
settings.nlive = 200
settings.do_clustering = True
settings.read_resume = False

#| Run PolyChord

print("about to run_pypolychord")
output = pypolychord.run_polychord(likelihood, nDims, nDerived, settings, prior, dumper)

#| Create a paramnames file
Expand Down
31 changes: 28 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,38 @@ def build_extension(self, ext) -> None:

def build_cmake(self, ext):
print(self.build_temp)
cwd = pathlib.Path().absolute()
cwd = pathlib.Path().cwd()
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)

# os.chdir(str(build_temp))
# self.spawn(["cmake", str(cwd), f"-DPython3_EXECUTABLE={sys.executable}"])
# self.spawn(["make"])
env = {}
env["PATH"] = os.environ["PATH"]
if self.distribution.no_mpi is None:
env["MPI"] = "1"
# These need to be set so that build_ext uses the right compilers
cc_compiler = subprocess.check_output(["make", "print_CC"]).decode('utf-8').strip()
os.environ["CC"] = cc_compiler

cxx_compiler = subprocess.check_output(["make", "print_CXX"]).decode('utf-8').strip()
os.environ["CXX"] = cxx_compiler
else:
env["MPI"] = "0"

if self.distribution.debug_flags is not None:
self.distribution.ext_modules[0].extra_compile_args += ["-g", "-O0"]
env["DEBUG"] = "1"

# BASE_PATH = os.path.dirname(os.path.abspath(__file__))
os.chdir(str(build_temp))
self.spawn(["cmake", str(cwd)])
self.spawn(["make"])
print("managed to change directory")
env["PWD"] = str(build_temp)
env.update({k : os.environ[k] for k in ["CC", "CXX", "FC"] if k in os.environ})
subprocess.check_call(["cmake", str(cwd), f"-DPython3_EXECUTABLE={sys.executable}"], env=env) #, cwd=str(build_temp))
print("cmade")
subprocess.check_call(["make", "-e"], env=env) #, cwd=str(build_temp))
os.chdir(cwd)

class DistributionWithOption(Distribution, object):
Expand Down
Loading