forked from pytorch/botorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add constrained synthetic test functions (pytorch#1832)
Summary: Pull Request resolved: pytorch#1832 Adds the following engineering-problem test functions: - PressureVesselDesign - WeldedBeam - SpeedReducer - TensionCompressionString Reviewed By: SebastianAment Differential Revision: D45821102 fbshipit-source-id: b58d23ae33afd89d9c1435598334b97f3f800f0a
- Loading branch information
1 parent
1cdd5e2
commit 211a9f2
Showing
3 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional, Tuple | ||
|
||
import torch | ||
|
||
from torch import Tensor | ||
|
||
|
||
def round_nearest( | ||
X: Tensor, increment: float, bounds: Optional[Tuple[float, float]] | ||
) -> Tensor: | ||
r"""Rounds the input tensor to the nearest multiple of `increment`. | ||
Args: | ||
X: The input to be rounded. | ||
increment: The increment to round to. | ||
bounds: An optional tuple of two floats representing the lower and upper | ||
bounds on `X`. If provided, this will round to the nearest multiple | ||
of `increment` that lies within the bounds. | ||
Returns: | ||
The roundded input. | ||
""" | ||
X_round = torch.round(X / increment) * increment | ||
if bounds is not None: | ||
X_round = torch.where(X_round < bounds[0], X_round + increment, X_round) | ||
X_round = torch.where(X_round > bounds[1], X_round - increment, X_round) | ||
return X_round |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters