From 6ce11959a22458f3f59fa3e5bc030182a308c694 Mon Sep 17 00:00:00 2001 From: Martin Fitzner Date: Thu, 2 May 2024 18:37:25 +0200 Subject: [PATCH 1/4] Add numpy env var --- baybe/utils/numerical.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/baybe/utils/numerical.py b/baybe/utils/numerical.py index ab4d9c089..6e3880311 100644 --- a/baybe/utils/numerical.py +++ b/baybe/utils/numerical.py @@ -1,11 +1,21 @@ """Utilities for numeric operations.""" +import os from collections.abc import Sequence import numpy as np import numpy.typing as npt -DTypeFloatNumpy = np.float64 +from baybe.utils.boolean import strtobool + +VARNAME_NUMPY_USE_SINGLE_PRECISION = "BAYBE_NUMPY_USE_SINGLE_PRECISION" +"""Environment variable name for enforcing single precision in numpy.""" + +DTypeFloatNumpy = ( + np.float32 + if strtobool(os.environ.get(VARNAME_NUMPY_USE_SINGLE_PRECISION, "False")) + else np.float64 +) """Floating point data type used for numpy arrays.""" DTypeFloatONNX = np.float32 From d6e75daff3d7fd6822667f9ca5b5788e902d58b3 Mon Sep 17 00:00:00 2001 From: Martin Fitzner Date: Thu, 2 May 2024 18:37:33 +0200 Subject: [PATCH 2/4] Add torch env var --- baybe/utils/torch.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/baybe/utils/torch.py b/baybe/utils/torch.py index 542c0bada..a3e10d35d 100644 --- a/baybe/utils/torch.py +++ b/baybe/utils/torch.py @@ -1,6 +1,18 @@ """Torch utilities shipped as separate module for lazy-loading.""" + +import os + import torch -DTypeFloatTorch = torch.float64 +from baybe.utils.boolean import strtobool + +VARNAME_TORCH_USE_SINGLE_PRECISION = "BAYBE_TORCH_USE_SINGLE_PRECISION" +"""Environment variable name for enforcing single precision in torch.""" + +DTypeFloatTorch = ( + torch.float32 + if strtobool(os.environ.get(VARNAME_TORCH_USE_SINGLE_PRECISION, "False")) + else torch.float64 +) """Floating point data type used for torch tensors.""" From b839eb1a85510b71716f8ff81c6d118123df5371 Mon Sep 17 00:00:00 2001 From: Martin Fitzner Date: Thu, 2 May 2024 18:37:41 +0200 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 747e1373d..efd679ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `torch`, `gpytorch` and `botorch` are lazy-loaded for improved startup time - If an exception is encountered during simulation, incomplete results are returned with a warning instead of passing through the uncaught exception +- Environment variables `BAYBE_NUMPY_USE_SINGLE_PRECISION` and + `BAYBE_TORCH_USE_SINGLE_PRECISION` to enforce single point precision usage ### Removed - `model_params` attribute from `Surrogate` base class, `GaussianProcessSurrogate` and From cc45fa450f9a6e6078234bae90c5abbb8ab1e397 Mon Sep 17 00:00:00 2001 From: Martin Fitzner Date: Thu, 16 May 2024 11:42:44 +0200 Subject: [PATCH 4/4] Add TODO --- baybe/constraints/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/baybe/constraints/base.py b/baybe/constraints/base.py index 5b6182553..e7e1cecc5 100644 --- a/baybe/constraints/base.py +++ b/baybe/constraints/base.py @@ -173,6 +173,7 @@ def to_botorch( if p in param_names ] + # TODO: Cast rhs to correct precision once BoTorch also supports single point. return ( torch.tensor(param_indices), torch.tensor(self.coefficients, dtype=DTypeFloatTorch),