From fb2a65c779da9e263318ef05135f41ea6e0df078 Mon Sep 17 00:00:00 2001 From: "Alexander V. Hopp" Date: Wed, 30 Oct 2024 08:25:52 +0100 Subject: [PATCH 1/4] Use DTypeFloatNumpy in comp_rep_bounds of continuous space --- baybe/searchspace/continuous.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/baybe/searchspace/continuous.py b/baybe/searchspace/continuous.py index 308d15999..d27eef0bc 100644 --- a/baybe/searchspace/continuous.py +++ b/baybe/searchspace/continuous.py @@ -277,9 +277,12 @@ def comp_rep_columns(self) -> tuple[str, ...]: @property def comp_rep_bounds(self) -> pd.DataFrame: """The minimum and maximum values of the computational representation.""" + from baybe.utils.numerical import DTypeFloatNumpy + return pd.DataFrame( {p.name: p.bounds.to_tuple() for p in self.parameters}, index=["min", "max"], + dtype=DTypeFloatNumpy, ) def _drop_parameters(self, parameter_names: Collection[str]) -> SubspaceContinuous: From b85e8997fbb55906e187b27ebc3aca27d434bc0a Mon Sep 17 00:00:00 2001 From: "Alexander V. Hopp" Date: Tue, 5 Nov 2024 10:46:03 +0100 Subject: [PATCH 2/4] Move lazy import to top of file --- baybe/searchspace/continuous.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/baybe/searchspace/continuous.py b/baybe/searchspace/continuous.py index d27eef0bc..c7b993a08 100644 --- a/baybe/searchspace/continuous.py +++ b/baybe/searchspace/continuous.py @@ -30,6 +30,7 @@ from baybe.serialization import SerialMixin, converter, select_constructor_hook from baybe.utils.basic import to_tuple from baybe.utils.dataframe import get_transform_objects, pretty_print_df +from baybe.utils.numerical import DTypeFloatNumpy from baybe.utils.plotting import to_string if TYPE_CHECKING: @@ -277,8 +278,6 @@ def comp_rep_columns(self) -> tuple[str, ...]: @property def comp_rep_bounds(self) -> pd.DataFrame: """The minimum and maximum values of the computational representation.""" - from baybe.utils.numerical import DTypeFloatNumpy - return pd.DataFrame( {p.name: p.bounds.to_tuple() for p in self.parameters}, index=["min", "max"], From 6da1313443c2150844d46e72547aa4689cfeea33 Mon Sep 17 00:00:00 2001 From: "Alexander V. Hopp" Date: Tue, 5 Nov 2024 10:48:03 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d4c8f791..bfe01dbb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Rare bug arising from degenerate `SubstanceParameter.comp_df` rows that caused wrong number of recommendations being returned +- `ContinuousConstraint`s can now be used in single point precision ### Deprecations - Passing a dataframe via the `data` argument to `Objective.transform` is no longer From fdc55e5c385ed7d674247e2d6a61752e7b3c8e1a Mon Sep 17 00:00:00 2001 From: "Alexander V. Hopp" Date: Thu, 7 Nov 2024 12:18:20 +0100 Subject: [PATCH 4/4] Adjust single point admonition --- docs/userguide/envvars.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/userguide/envvars.md b/docs/userguide/envvars.md index 75af38224..836ddf8c7 100644 --- a/docs/userguide/envvars.md +++ b/docs/userguide/envvars.md @@ -104,7 +104,7 @@ BAYBE_CACHE_DIR="" ``` you can turn off disk caching entirely. -## Floating Point Precision +## EXPERIMENTAL: Floating Point Precision In general, double precision is recommended because numerical stability during optimization can be bad when single precision is used. This impacts gradient-based optimization, i.e. search spaces with continuous parameters, more than optimization without gradients. @@ -113,10 +113,11 @@ If you still want to use single precision, you can set the following Boolean var - `BAYBE_NUMPY_USE_SINGLE_PRECISION` (defaults to `False`) - `BAYBE_TORCH_USE_SINGLE_PRECISION` (defaults to `False`) -```{admonition} Continuous Constraints in Single Precision +```{admonition} Experimental feature only! :class: warning -Currently, due to explicit casting in BoTorch, -[`ContinuousConstraint`](baybe.constraints.base.ContinuousConstraint)s do not support -single precision and cannot be used if the corresponding environment variables are -activated. +Currently, it cannot be guaranteed that all calculations will be performed in single precision, +even when setting the aforementioned variables. The reason is that there are several code snippets +within `BoTorch` that transform single precision variables to double precision variables. +Consequently, this feature is currently only available as an *experimental* feature. +We are however actively working on fully enabling single precision. ``` \ No newline at end of file