Skip to content

Commit

Permalink
Upgrade numba and llvmlite (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosfelt authored Feb 17, 2022
1 parent 047efee commit 2aac5f4
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sphinx:

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
version: 3.8
install:
- method: pip
path: .
Expand Down
14 changes: 1 addition & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,4 @@ Singularity (for running Docker containers on the HPC):
```
export NEPTUNE_API_TOKEN=
singularity exec -B `pwd`/:/summit_user docker://marcosfelt/summit:snar_benchmark snar_experiment.py
```
### Releases
Below is the old process for building a release. In the future, we will have this automated using Github actions.
1. Install [s3pypi](https://github.com/novemberfiveco/s3pypi) and [dephell](https://dephell.org/docs/installation.html)
2. Install AWS credentials to upload pypi.rxns.io (Kobi is the one who controls this).
3. Bump the version in pyproject.toml and then run:
```dephell deps convert --from=pyproject.toml --to=setup.py```
4. Go into setup.py and delete the lines for extras_install_requires
4. Upload the package to the private pypi repository:
```s3pypi --bucket pypi.rxns.io``
```
18 changes: 17 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,24 @@ Additionally, if you want to use the experimental ENTMOOT feature you need to in
# with pip:
pip install summit[entmoot]
# with poetry
# with poetryff
poetry add summit -E entmoot
# with pipenv
pipenv install summit[entmoot]
Notes about installing on Apple M1
***********************************

You might run into some issues when installing scientific python packages such as Summit on Apple M1. Follow the steps below to install via pip:

.. code-block:: bash
arch -arm64 brew install llvm@11
brew install hdf5
HDF5_DIR=/opt/homebrew/opt/hdf5 PIP_NO_BINARY="h5py" LLVM_CONFIG="/opt/homebrew/Cellar/llvm@11/11.1.0_3/bin/llvm-config" arch -arm64 poetry install
More resources

* [LLVM isssue](https://github.com/numba/llvmlite/issues/693#issuecomment-909501195)
* [Installing H5py (for numpy)](https://docs.h5py.org/en/stable/build.html#custom-installation)
200 changes: 106 additions & 94 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ keywords = ["machine-learning", "chemistry", "bayesian-reaction-optimization", "
python = "^3.8, <3.11"
pandas = "^1.1.0"
scipy = ">=1.8.0"
numpy = "^1.21.0"
llvmlite="^0.38.0"
numba="^0.55.0"
fastprogress = "^0.2.3"
matplotlib = "^3.2.2"
scikit-learn = "^1.0"
llvmlite="^0.38.0"
torch = "^1.4.0"
skorch = "^0.9.0"
cython = "^0.29.21"

# Dependencies for TSEMO and SOBO
GPy = "^1.9"
gpyopt = "^1.2.6"
numpy = "^1.22.0"
pyrff = "^2.0.1"
pymoo = "^0.4.1"

Expand Down
39 changes: 23 additions & 16 deletions summit/strategies/snobfit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pdb
from .base import Strategy, Transform
from summit.domain import *
from summit.utils.dataset import DataSet

import math
import numpy
from copy import deepcopy
import numpy as np
import pandas as pd
import warnings

Expand Down Expand Up @@ -155,10 +155,10 @@ def suggest_experiments(
if len(next_experiments) and len(invalid_experiments):
valid_next_experiments = True
# pass NaN if at least one constraint is violated
invalid_experiments[(obj_name, "DATA")] = np.nan
invalid_experiments[(obj_name, "DATA")] = numpy.nan
elif len(invalid_experiments):
# pass NaN if at least one constraint is violated
invalid_experiments[(obj_name, "DATA")] = np.nan
invalid_experiments[(obj_name, "DATA")] = numpy.nan
prev_res = invalid_experiments
else:
valid_next_experiments = True
Expand Down Expand Up @@ -201,7 +201,11 @@ def from_dict(cls, d):
snobfit = super().from_dict(d)
params = d["strategy_params"]["prev_param"]
if params is not None:
params[0] = (np.array(params[0][0]), params[0][1], np.array(params[0][2]))
params[0] = (
numpy.array(params[0][0]),
params[0][1],
numpy.array(params[0][2]),
)
params[1] = [DataSet.from_dict(p) for p in params[1]]
snobfit.prev_param = params
return snobfit
Expand Down Expand Up @@ -252,7 +256,7 @@ def _inner_suggest_experiments(
elif isinstance(v, CategoricalVariable):
if v.ds is not None:
descriptor_names = v.ds.data_columns
descriptors = np.asarray(
descriptors = numpy.asarray(
[
v.ds.loc[:, [l]].values.tolist()
for l in v.ds.data_columns
Expand All @@ -261,15 +265,17 @@ def _inner_suggest_experiments(
else:
raise ValueError("No descriptors given for {}".format(v.name))
for d in descriptors:
bounds.append([np.min(np.asarray(d)), np.max(np.asarray(d))])
bounds.append(
[numpy.min(numpy.asarray(d)), numpy.max(numpy.asarray(d))]
)
input_var_names.extend(descriptor_names)
else:
raise TypeError(
"SNOBFIT can not handle variable type: {}".format(v.type)
)
else:
output_var_names.extend(v.name)
bounds = np.asarray(bounds, dtype=float)
bounds = numpy.asarray(bounds, dtype=float)

# Initialization
x0 = []
Expand All @@ -290,14 +296,14 @@ def _inner_suggest_experiments(
if v.is_objective and v.maximize:
outputs[v.name] = -1 * outputs[v.name]

x0 = inputs.data_to_numpy()
y0 = outputs.data_to_numpy()
x0 = inputs.data_to_numpy().astype(float)
y0 = outputs.data_to_numpy().astype(float)

# Add uncertainties to measurements TODO: include uncertainties in input
y = []
for i in range(y0.shape[0]):
y.append([y0[i].tolist()[0], math.sqrt(numpy.spacing(1))])
y0 = np.asarray(y, dtype=float)
y0 = numpy.asarray(y, dtype=float)
# If no prev_res are given but prev_param -> raise error
elif prev_param is not None:
raise ValueError(
Expand All @@ -307,8 +313,8 @@ def _inner_suggest_experiments(

# if no previous results are given initialize with empty lists
if not len(x0):
x0 = np.array(x0).reshape(0, len(bounds))
y0 = np.array(y0).reshape(0, 2)
x0 = numpy.array(x0).reshape(0, len(bounds)).astype(float)
y0 = numpy.array(y0).reshape(0, 2).astype(float)

""" Determine SNOBFIT parameters
config structure variable defining the box [u,v] in which the
Expand All @@ -320,7 +326,7 @@ def _inner_suggest_experiments(
the program should continue from the values stored in
file.mat, the call should have only 4 input parameters!)
n-vector (n = dimension of the problem) of minimal
stnp.spacing(1), i.e., two points are considered to be different
stnumpy.spacing(1), i.e., two points are considered to be different
if they differ by at least dx(i) in at least one
coordinate i
"""
Expand Down Expand Up @@ -400,7 +406,7 @@ def snobfit(self, x, f, config, dx=None, prev_param=None):
the program should continue from the values stored in
file.mat, the call should have only 4 input parameters!)
n-vector (n = dimension of the problem) of minimal
stnp.spacing(1), i.e., two points are considered to be different
stnumpy.spacing(1), i.e., two points are considered to be different
if they differ by at least dx(i) in at least one
coordinate i
prev_res results of previous iterations
Expand Down Expand Up @@ -573,6 +579,7 @@ def snobfit(self, x, f, config, dx=None, prev_param=None):

nx = len(xnew)
oldxbest = xbest

xl, xu, x, f, nsplit, small, near, d, np, t, inew, fnan, u, v = snobupdt(
xl,
xu,
Expand Down Expand Up @@ -980,13 +987,13 @@ def snobfit(self, x, f, config, dx=None, prev_param=None):

# Function to check whether a point meets the constraints of the domain
def check_constraints(self, tmp_next_experiments):
constr_mask = np.asarray([True] * len(tmp_next_experiments)).T
constr_mask = numpy.asarray([True] * len(tmp_next_experiments)).T
if len(self.domain.constraints) > 0:
constr = [c.constraint_type + "0" for c in self.domain.constraints]
constr_mask = [
pd.eval(c.lhs + constr[i], resolvers=[tmp_next_experiments])
for i, c in enumerate(self.domain.constraints)
]
constr_mask = np.asarray([c.tolist() for c in constr_mask]).T
constr_mask = numpy.asarray([c.tolist() for c in constr_mask]).T
constr_mask = constr_mask.all(1)
return constr_mask
9 changes: 6 additions & 3 deletions summit/strategies/sobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ def suggest_experiments(
outputs = outputs.to_numpy()

if self.prev_param is not None:
X_step = self.prev_param[0]
Y_step = self.prev_param[1]
X_step = self.prev_param[0].astype(float)
Y_step = self.prev_param[1].astype(float)

X_step = np.vstack((X_step, inputs))
Y_step = np.vstack((Y_step, outputs))
Expand Down Expand Up @@ -393,7 +393,10 @@ def reset(self):

def to_dict(self):
if self.prev_param is not None:
param = [self.prev_param[0].tolist(), self.prev_param[1].tolist()]
param = [
self.prev_param[0].astype(float).tolist(),
self.prev_param[1].astype(float).tolist(),
]
else:
param = None

Expand Down
2 changes: 1 addition & 1 deletion summit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def jsonify_dict(d, copy=True):
d[k] = jsonify_dict(v)
elif type(v) in (np.int64, np.int32, np.int8):
d[k] = int(v)
elif type(v) in (np.float16, np.float32, np.float64, np.float128):
elif type(v) in (np.float16, np.float32, np.float64):
d[k] = float(v)
elif type(v) in [str, int, float, bool, tuple] or v is None:
pass
Expand Down
8 changes: 4 additions & 4 deletions tests/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ def test_sobo(
os.remove("sobo_test.json")

if strategy.prev_param is not None:
assert strategy.prev_param[0].all() == strategy_2.prev_param[0].all()
assert strategy.prev_param[1].all() == strategy_2.prev_param[1].all()
# assert np.isclose(strategy.prev_param[0], strategy_2.prev_param[0])
# assert np.isclose(strategy.prev_param[1], strategy_2.prev_param[1])
assert strategy.use_descriptors == strategy_2.use_descriptors
assert strategy.gp_model_type == strategy_2.gp_model_type
assert strategy.acquisition_type == strategy_2.acquisition_type
Expand Down Expand Up @@ -813,8 +813,8 @@ def test_entmoot(
os.remove("entmoot_test.json")

if strategy.prev_param is not None:
assert strategy.prev_param[0].all() == strategy_2.prev_param[0].all()
assert strategy.prev_param[1].all() == strategy_2.prev_param[1].all()
# assert np.isclose(strategy.prev_param[0], strategy_2.prev_param[0])
# assert np.isclose(strategy.prev_param[1], strategy_2.prev_param[1])
assert strategy.use_descriptors == strategy_2.use_descriptors
assert strategy.estimator_type == strategy_2.estimator_type
assert strategy.std_estimator_type == strategy_2.std_estimator_type
Expand Down

0 comments on commit 2aac5f4

Please sign in to comment.