forked from automl/ConfigSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
213 lines (187 loc) · 6.78 KB
/
setup.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
"""Setup.py for ConfigSpace"""
import os
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
from Cython.Build import cythonize # must go after setuptools
# Helper functions
def read_file(fname):
"""Get contents of file from the modules directory"""
return open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read()
def get_version(fname):
"""Get the module version"""
with open(fname, encoding="utf-8") as file_handle:
return file_handle.readlines()[-1].split()[-1].strip("\"'")
def get_authors(fname):
"""Get the authors"""
with open(fname, "r") as f:
content = f.read()
return [
line.replace(",", "").replace('"', "").replace(" ", "") # Remove noise
for line in content.split("\n")
if line.startswith(" ") # Lines with space
]
class BuildExt(build_ext):
"""build_ext command for use when numpy headers are needed.
SEE tutorial: https://stackoverflow.com/questions/2379898
SEE fix: https://stackoverflow.com/questions/19919905
"""
def finalize_options(self):
build_ext.finalize_options(self)
import numpy
self.include_dirs.append(numpy.get_include())
# Configure setup parameters
MODULE_NAME = "ConfigSpace"
MODULE_URL = "https://github.com/automl/ConfigSpace"
SHORT_DESCRIPTION = (
"Creation and manipulation of parameter configuration spaces for "
"automated algorithm configuration and hyperparameter tuning."
)
KEYWORDS = (
"algorithm configuration hyperparameter optimization empirical "
"evaluation black box"
)
LICENSE = "BSD 3-clause"
PLATS = ["Linux", "Windows", "Mac"]
AUTHOR_EMAIL = "[email protected]"
TEST_SUITE = "pytest"
INSTALL_REQS = ["numpy", "pyparsing", "scipy", "typing_extensions", "more_itertools"]
MIN_PYTHON_VERSION = ">=3.7"
CLASSIFIERS = [
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Development Status :: 4 - Beta",
"Natural Language :: English",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
]
# These do not really change the speed of the benchmarks
COMPILER_DIRECTIVES = {
"boundscheck": False,
"wraparound": False,
"language_level": "3",
}
"""
# Profiling
Set the below flag to True to enable profiling of the code. This will cause some minor performance
overhead so it should only be used for debugging purposes.
Use [`py-spy`](https://github.com/benfred/py-spy) with [speedscope.app](https://www.speedscope.app/)
```bash
pip install py-spy
py-spy record --rate 800 --format speedscope --subprocesses --native -o profile.svg -- python <script>
# Open in speedscope.app
```
If timing something really really low in time, use a higher `--rate`
You'll want to create a basic script that does the bar minimum as this allows you to bump up
the --rate option and get much higher fidelity information.
# Refs
* https://mclare.blog/posts/further-adventures-in-cython-profiling
* https://cython.readthedocs.io/en/latest/src/tutorial/profiling_tutorial.html#enabling-profiling-for-a-complete-source-file # noqa: E501
* py-spy
"""
PROFILING = False
if PROFILING:
COMPILER_DIRECTIVES["profile"] = True
COMPILER_DIRECTIVES["linetrace"] = True
EXTENSIONS = [
Extension(
"ConfigSpace.hyperparameters.beta_float",
sources=["ConfigSpace/hyperparameters/beta_float.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.beta_integer",
sources=["ConfigSpace/hyperparameters/beta_integer.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.categorical",
sources=["ConfigSpace/hyperparameters/categorical.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.constant",
sources=["ConfigSpace/hyperparameters/constant.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.float_hyperparameter",
sources=["ConfigSpace/hyperparameters/float_hyperparameter.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.hyperparameter",
sources=["ConfigSpace/hyperparameters/hyperparameter.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.integer_hyperparameter",
sources=["ConfigSpace/hyperparameters/integer_hyperparameter.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.normal_float",
sources=["ConfigSpace/hyperparameters/normal_float.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.normal_integer",
sources=["ConfigSpace/hyperparameters/normal_integer.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.numerical",
sources=["ConfigSpace/hyperparameters/numerical.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.ordinal",
sources=["ConfigSpace/hyperparameters/ordinal.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.uniform_float",
sources=["ConfigSpace/hyperparameters/uniform_float.pyx"]
),
Extension(
"ConfigSpace.hyperparameters.uniform_integer",
sources=["ConfigSpace/hyperparameters/uniform_integer.pyx"]
),
Extension("ConfigSpace.forbidden", sources=["ConfigSpace/forbidden.pyx"]),
Extension("ConfigSpace.conditions", sources=["ConfigSpace/conditions.pyx"]),
Extension("ConfigSpace.c_util", sources=["ConfigSpace/c_util.pyx"]),
Extension("ConfigSpace.util", sources=["ConfigSpace/util.pyx"]),
Extension(
"ConfigSpace.configuration_space",
sources=["ConfigSpace/configuration_space.pyx"],
),
]
extras_reqs = {
"dev": [
"pytest>=4.6",
"mypy",
"pre-commit",
"pytest-cov",
"automl_sphinx_theme>=0.1.11",
],
}
setup(
name=MODULE_NAME,
version=get_version("ConfigSpace/__version__.py"),
cmdclass={"build_ext": BuildExt},
url=MODULE_URL,
description=SHORT_DESCRIPTION,
long_description_content_type="text/markdown",
ext_modules=cythonize(EXTENSIONS, compiler_directives=COMPILER_DIRECTIVES),
long_description=read_file("README.md"),
license=LICENSE,
platforms=PLATS,
author=get_authors("ConfigSpace/__authors__.py"),
author_email=AUTHOR_EMAIL,
test_suite=TEST_SUITE,
install_requires=INSTALL_REQS,
extras_require=extras_reqs,
keywords=KEYWORDS,
packages=find_packages(),
python_requires=MIN_PYTHON_VERSION,
classifiers=CLASSIFIERS,
)