-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsetup.py
More file actions
133 lines (121 loc) · 4.28 KB
/
Copy pathsetup.py
File metadata and controls
133 lines (121 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import platform
import subprocess
from setuptools import setup, Extension
import numpy
# On arm64 macOS, ensure extensions are built for the correct architecture.
# Detect actual hardware arch (not Rosetta) and add -arch flag directly.
def _get_arch_flags():
if platform.system() != "Darwin":
return []
# Use sysctl to get the real hardware architecture
try:
result = subprocess.run(
["sysctl", "-n", "hw.optional.arm64"],
capture_output=True, text=True
)
is_arm64 = result.stdout.strip() == "1"
except Exception:
is_arm64 = platform.machine() == "arm64"
if is_arm64:
return ["-arch", "arm64"]
return []
_arch_flags = _get_arch_flags()
# all extensions here
extmods = []
# build extension 1: custom spline interpolation (no external deps)
extmod = Extension(
"gwsurrogate.spline_interp_Cwrapper._spline_interp",
extra_compile_args=["-std=c++14", "-O3"] + _arch_flags,
extra_link_args=_arch_flags,
language="c++",
sources=["gwsurrogate/spline_interp_Cwrapper/_spline_interp.cpp"],
)
extmods.append(extmod)
# build extension 2: precessing utils
extmod = Extension(
"gwsurrogate.precessing_utils._utils",
sources=["gwsurrogate/precessing_utils/src/precessing_utils.c"],
include_dirs=["gwsurrogate/precessing_utils/include", numpy.get_include()],
language="c",
extra_compile_args=["-std=c99", "-fPIC", "-O3", '-Wcpp'] + _arch_flags,
extra_link_args=_arch_flags,
)
extmods.append(extmod)
# Extract code version from surrogate.py
def read_main_file(key):
with open("gwsurrogate/surrogate.py") as f:
for line in f.readlines():
if key in line:
return line.split('"')[1]
# define models to be used within pycbc
entries = {
"pycbc.waveform.td": [
"GWS-NRHybSur3dq8 = gwsurrogate.pycbc:gws_td_gen",
"GWS-NRSur7dq4 = gwsurrogate.pycbc:gws_td_gen",
"GWS-NRHybSur3dq8Tidal = gwsurrogate.pycbc:gws_td_gen",
]
}
setup(
name="gwsurrogate",
version=read_main_file("__version__"),
author=read_main_file("__author__"),
author_email="sfield@umassd.edu",
packages=[
"gwsurrogate",
"gwsurrogate.eval_pysur",
"gwsurrogate.new",
# "gwsurrogate.precessing_utils",
"gwsurrogate.spline_interp_Cwrapper",
],
license="MIT",
include_package_data=True,
contributors=[
# Alphabetical by last name.
""
],
description="An easy to use interface to gravitational wave surrogate models",
long_description_content_type="text/markdown",
long_description=open("README.md").read(),
# will start new downloads if these are installed in a non-standard location
# NOTE: These are runtime requirements needed for installation.
#
# In particular, the extensions listed above have their own build
# requirements which (if building from source) are set in the
# pyproject.toml file (not below).
#
# Notably, GWSurrogate is intended to be built against numpy 2.X
# header files but compatible with numpy>=1.7 runtime environments.
# Hence numpy>=2 constraints are not put on the install requirements
# below. We do require numpy>=1.7 as that's when the
# NPY_NO_DEPRECATED_API macro first appeared.
#
# pyproject.toml specifies build requirements, in particular you
# may can modify that file if you intend to require a specific
# version of numpy (e.g. >=1.7) as pip builds the extensions
# in an isolated environment and does not use the
# requirements below.
install_requires=[
"numpy>=1.7",
"requests",
"scipy",
"h5py",
"pytest",
"scikit-learn",
"gwtools",
"matplotlib",
],
setup_requires=["numpy"],
classifiers=[
"Intended Audience :: Other Audience",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Physics",
],
entry_points=entries,
ext_modules=extmods,
)