From b9c6dbd19d78ff4b6155d6595f3deddffede4c67 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 3 Aug 2024 08:14:33 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/user_guide/neuroevolution.md | 3 +-- src/evotorch/algorithms/functional/__init__.py | 3 +-- src/evotorch/core.py | 8 ++++---- src/evotorch/decorators.py | 18 ++++++------------ src/evotorch/distributions.py | 3 +-- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/docs/user_guide/neuroevolution.md b/docs/user_guide/neuroevolution.md index 60aa86a9..d0c36203 100644 --- a/docs/user_guide/neuroevolution.md +++ b/docs/user_guide/neuroevolution.md @@ -293,8 +293,7 @@ class CustomNE(NEProblem): def _network_constants(self): return {"d": self._d} # Pass self._d as 'd' to networks at instantiation - def _evaluate_network(self, network: torch.nn.Module): - ... + def _evaluate_network(self, network: torch.nn.Module): ... ``` which then allows, for example, the use of the variable `d` in the string representation of the network diff --git a/src/evotorch/algorithms/functional/__init__.py b/src/evotorch/algorithms/functional/__init__.py index 25ab4683..71723e24 100644 --- a/src/evotorch/algorithms/functional/__init__.py +++ b/src/evotorch/algorithms/functional/__init__.py @@ -256,8 +256,7 @@ def f(x: torch.Tensor) -> torch.Tensor: class MyProblem(Problem): - def __init__(self): - ... + def __init__(self): ... def _evaluate_batch(self, batch: SolutionBatch): # Stateful batch evaluation code goes here diff --git a/src/evotorch/core.py b/src/evotorch/core.py index f44d0efc..e2b4324f 100644 --- a/src/evotorch/core.py +++ b/src/evotorch/core.py @@ -610,8 +610,9 @@ def __init__(self): # for initializing solutions ) - def _evaluate_batch(self, solutions: SolutionBatch): - ... # code to compute and fill the fitnesses goes here + def _evaluate_batch( + self, solutions: SolutionBatch + ): ... # code to compute and fill the fitnesses goes here def _fill(self, values: torch.Tensor): # `values` is an empty tensor of shape (n, m) where n is the number @@ -749,8 +750,7 @@ def _evaluate_batch(self, solutions: SolutionBatch): from evotorch.logging import StdOutLogger - def f(x: torch.Tensor) -> torch.Tensor: - ... + def f(x: torch.Tensor) -> torch.Tensor: ... prob = Problem("min", f, solution_length=..., dtype=torch.float32) diff --git a/src/evotorch/decorators.py b/src/evotorch/decorators.py index 796ad215..d8e40c04 100644 --- a/src/evotorch/decorators.py +++ b/src/evotorch/decorators.py @@ -254,8 +254,7 @@ def f(x: torch.Tensor) -> torch.Tensor: @on_device("cuda") - def f(x: torch.Tensor) -> torch.Tensor: - ... + def f(x: torch.Tensor) -> torch.Tensor: ... problem = Problem( @@ -306,8 +305,7 @@ def _evaluate_batch(self, solutions: SolutionBatch): ```python @on_device("cpu") - def f(x: torch.Tensor) -> torch.Tensor: - ... + def f(x: torch.Tensor) -> torch.Tensor: ... print(f.device) # Prints: torch.device("cpu") @@ -499,8 +497,7 @@ def f(x: torch.Tensor) -> torch.Tensor: @on_aux_device - def f(x: torch.Tensor) -> torch.Tensor: - ... + def f(x: torch.Tensor) -> torch.Tensor: ... problem = Problem( @@ -632,8 +629,7 @@ def expects_ndim( # noqa: C901 @expects_ndim(2, 1) - def f(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: - ... + def f(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: ... ``` Once decorated like this, the function `f` will gain the following @@ -663,8 +659,7 @@ def f(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: ```python @expects_ndim(2, 1, randomness="error") - def f(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: - ... + def f(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor: ... ``` If `randomness` is set as "error", then, when there is batching, any @@ -941,8 +936,7 @@ def fitness(decision_values: torch.Tensor) -> torch.Tensor: ```python @rowwise(randomness="error") - def f(x: torch.Tensor) -> torch.Tensor: - ... + def f(x: torch.Tensor) -> torch.Tensor: ... ``` If `randomness` is set as "error", then, when there is batching, any diff --git a/src/evotorch/distributions.py b/src/evotorch/distributions.py index 5af92141..2636a3e8 100644 --- a/src/evotorch/distributions.py +++ b/src/evotorch/distributions.py @@ -1395,8 +1395,7 @@ def make_functional_grad_estimator( ) - def f(x: torch.Tensor) -> torch.Tensor: - ... + def f(x: torch.Tensor) -> torch.Tensor: ... fgrad = make_functional_grad_estimator(