From a549362eb37dd25483e0120f39353db2b8db6f04 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:31:54 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- profit/al/active_learning.py | 1 + profit/al/mcmc_al.py | 8 +- profit/config.py | 10 +- profit/defaults.py | 1 + profit/run/local.py | 8 +- profit/run/slurm.py | 10 +- profit/sur/encoders.py | 1 + profit/sur/gp/backend/init_kernels.py | 1 + profit/sur/gp/gpy_surrogate.py | 16 +- profit/sur/gp/sklearn_surrogate.py | 10 +- profit/ui/app.py | 234 ++++++++++-------- profit/util/halton.py | 1 + profit/util/util.py | 1 + .../simulation_files/custom_components.py | 1 + .../mockup/simulation_files/mockup_worker.py | 1 + tests/unit_tests/config/mockup.py | 1 + tests/unit_tests/run/simulation.py | 1 + tests/unit_tests/sur/test_encoder.py | 1 + tests/unit_tests/variable/test_variable.py | 1 + 19 files changed, 182 insertions(+), 126 deletions(-) diff --git a/profit/al/active_learning.py b/profit/al/active_learning.py index 4590ed0..bf78b7a 100644 --- a/profit/al/active_learning.py +++ b/profit/al/active_learning.py @@ -4,6 +4,7 @@ In order to get the most out of the least number of training points, the next point is inferred by calculating an acquisition function like the minimization of local variance or expected improvement. """ + import numpy as np from abc import abstractmethod from warnings import warn diff --git a/profit/al/mcmc_al.py b/profit/al/mcmc_al.py index 22f3892..973cdce 100644 --- a/profit/al/mcmc_al.py +++ b/profit/al/mcmc_al.py @@ -73,9 +73,11 @@ def __init__( var.name for var in variables.list if var.kind.lower() == "activelearning" ] Xpred = [ - np.linspace(*var.constraints, nsearch) - if var.name in al_keys - else np.unique(var.value) + ( + np.linspace(*var.constraints, nsearch) + if var.name in al_keys + else np.unique(var.value) + ) for var in variables.input_list ] self.Xpred = np.hstack( diff --git a/profit/config.py b/profit/config.py index 921dea2..44bb5be 100644 --- a/profit/config.py +++ b/profit/config.py @@ -536,11 +536,11 @@ def process_entries(self, base_config): { "class": name, "columns": select, - "parameters": { - k: float(v) for k, v in config.get("parameters", {}) - } - if not isinstance(config, str) - else {}, + "parameters": ( + {k: float(v) for k, v in config.get("parameters", {})} + if not isinstance(config, str) + else {} + ), } ) diff --git a/profit/defaults.py b/profit/defaults.py index a393e94..2fef4c8 100644 --- a/profit/defaults.py +++ b/profit/defaults.py @@ -1,4 +1,5 @@ """Global default configuration values.""" + from os import path, getcwd # Base Config diff --git a/profit/run/local.py b/profit/run/local.py index 6b18851..20192bb 100644 --- a/profit/run/local.py +++ b/profit/run/local.py @@ -35,9 +35,11 @@ def __repr__(self): return ( f"<{self.__class__.__name__} (" + ", debug" if self.debug - else "" + f", {self.command}" - if self.command != "profit-worker" - else "" + ")>" + else ( + "" + f", {self.command}" + if self.command != "profit-worker" + else "" + ")>" + ) ) @property diff --git a/profit/run/slurm.py b/profit/run/slurm.py index ce45102..664c1f1 100644 --- a/profit/run/slurm.py +++ b/profit/run/slurm.py @@ -68,11 +68,11 @@ def __repr__(self): return ( f"<{self.__class__.__name__} (" + f", {self.cpus} cpus" + ", OpenMP" if self.openmp - else "" + ", debug" - if self.debug - else "" + ", custom script" - if self.custom - else "" + ")>" + else ( + "" + ", debug" + if self.debug + else "" + ", custom script" if self.custom else "" + ")>" + ) ) @property diff --git a/profit/sur/encoders.py b/profit/sur/encoders.py index 3f67e27..5d3e6a0 100644 --- a/profit/sur/encoders.py +++ b/profit/sur/encoders.py @@ -16,6 +16,7 @@ class Encoder(CustomABC): Attributes: label (str): Label of the encoder class. """ + labels = {} def __init__(self, columns, parameters=None): diff --git a/profit/sur/gp/backend/init_kernels.py b/profit/sur/gp/backend/init_kernels.py index 3514d60..a94ddc9 100644 --- a/profit/sur/gp/backend/init_kernels.py +++ b/profit/sur/gp/backend/init_kernels.py @@ -4,6 +4,7 @@ that is written to `kernels_base.f90`. This code has to be compiled via `make` subsequently. """ + # %% from sympy import symbols, sqrt, exp, diff from sympy.utilities.codegen import codegen diff --git a/profit/sur/gp/gpy_surrogate.py b/profit/sur/gp/gpy_surrogate.py index 7cb619a..90ae066 100644 --- a/profit/sur/gp/gpy_surrogate.py +++ b/profit/sur/gp/gpy_surrogate.py @@ -155,13 +155,15 @@ def select_kernel(self, kernel): kern = [] for key in full_str: kern += [ - key - if key in ("+", "*") - else "self.GPy.kern.{}({}, lengthscale={}, variance={})".format( - key, - self.ndim, - self.hyperparameters.get("length_scale", [1]), - self.hyperparameters.get("sigma_f", 1) ** 2, + ( + key + if key in ("+", "*") + else "self.GPy.kern.{}({}, lengthscale={}, variance={})".format( + key, + self.ndim, + self.hyperparameters.get("length_scale", [1]), + self.hyperparameters.get("sigma_f", 1) ** 2, + ) ) ] return eval("".join(kern)) diff --git a/profit/sur/gp/sklearn_surrogate.py b/profit/sur/gp/sklearn_surrogate.py index c8f14e3..ff49b81 100644 --- a/profit/sur/gp/sklearn_surrogate.py +++ b/profit/sur/gp/sklearn_surrogate.py @@ -144,10 +144,12 @@ def select_kernel(self, kernel): kernel = [] for key in full_str: kernel += [ - key - if key in ("+", "*") - else getattr(sklearn_kernels, key)( - length_scale=self.hyperparameters["length_scale"] + ( + key + if key in ("+", "*") + else getattr(sklearn_kernels, key)( + length_scale=self.hyperparameters["length_scale"] + ) ) ] except AttributeError: diff --git a/profit/ui/app.py b/profit/ui/app.py index 6d34917..947e03d 100644 --- a/profit/ui/app.py +++ b/profit/ui/app.py @@ -122,9 +122,11 @@ def init_app(config): dcc.Dropdown( id="invar_2", options=dd_opts_in, - value=invars[1] - if len(invars) > 1 - else invars[0], + value=( + invars[1] + if len(invars) > 1 + else invars[0] + ), style=dd_sty, ), dcc.Checklist( @@ -144,9 +146,11 @@ def init_app(config): dcc.Dropdown( id="invar_3", options=dd_opts_in, - value=invars[2] - if len(invars) > 2 - else invars[0], + value=( + invars[2] + if len(invars) > 2 + else invars[0] + ), style=dd_sty, ), dcc.Checklist( @@ -1265,26 +1269,36 @@ def update_figure( ), z=mesh_out[i].reshape((fit_sampling, fit_sampling)), name=f"fit: {fit_dd}={fit_dd_values[i]:.2f}", - surfacecolor=fit_dd_values[i] - * np.ones([fit_sampling, fit_sampling]) - if fit_color == "multi-fit" - else ( - mesh_in[i][invars.index(color_dd)].reshape( - (fit_sampling, fit_sampling) + surfacecolor=( + fit_dd_values[i] * np.ones([fit_sampling, fit_sampling]) + if fit_color == "multi-fit" + else ( + mesh_in[i][invars.index(color_dd)].reshape( + (fit_sampling, fit_sampling) + ) + if ( + fit_color == "marker-color" + and color_dd in invars + ) + else mesh_out[i].reshape( + (fit_sampling, fit_sampling) + ) ) - if (fit_color == "marker-color" and color_dd in invars) - else mesh_out[i].reshape((fit_sampling, fit_sampling)) ), opacity=fit_opacity, - coloraxis="coloraxis2" - if ( - fit_color == "multi-fit" - or ( - fit_color == "output" - and (color_dd != outvar and color_dd != "OUTPUT") + coloraxis=( + "coloraxis2" + if ( + fit_color == "multi-fit" + or ( + fit_color == "output" + and ( + color_dd != outvar and color_dd != "OUTPUT" + ) + ) ) - ) - else "coloraxis", + else "coloraxis" + ), showlegend=True if len(invars) > 2 else False, ) ) @@ -1302,33 +1316,38 @@ def update_figure( * mesh_out_std[i].reshape((fit_sampling, fit_sampling)), showlegend=False, name=f"fit+v: {fit_dd}={fit_dd_values[i]:.2f}", - surfacecolor=fit_dd_values[i] - * np.ones([fit_sampling, fit_sampling]) - if fit_color == "multi-fit" - else ( - mesh_in[i][invars.index(color_dd)].reshape( - (fit_sampling, fit_sampling) - ) - if ( - fit_color == "marker-color" - and color_dd in invars - ) - else mesh_out[i].reshape( - (fit_sampling, fit_sampling) + surfacecolor=( + fit_dd_values[i] + * np.ones([fit_sampling, fit_sampling]) + if fit_color == "multi-fit" + else ( + mesh_in[i][invars.index(color_dd)].reshape( + (fit_sampling, fit_sampling) + ) + if ( + fit_color == "marker-color" + and color_dd in invars + ) + else mesh_out[i].reshape( + (fit_sampling, fit_sampling) + ) ) ), opacity=fit_opacity, - coloraxis="coloraxis2" - if ( - fit_color == "multi-fit" - or ( - fit_color == "output" - and ( - color_dd != outvar and color_dd != "OUTPUT" + coloraxis=( + "coloraxis2" + if ( + fit_color == "multi-fit" + or ( + fit_color == "output" + and ( + color_dd != outvar + and color_dd != "OUTPUT" + ) ) ) - ) - else "coloraxis", + else "coloraxis" + ), ) ) fig.add_trace( @@ -1344,33 +1363,38 @@ def update_figure( * mesh_out_std[i].reshape((fit_sampling, fit_sampling)), showlegend=False, name=f"fit-v: {fit_dd}={fit_dd_values[i]:.2f}", - surfacecolor=fit_dd_values[i] - * np.ones([fit_sampling, fit_sampling]) - if fit_color == "multi-fit" - else ( - mesh_in[i][invars.index(color_dd)].reshape( - (fit_sampling, fit_sampling) - ) - if ( - fit_color == "marker-color" - and color_dd in invars - ) - else mesh_out[i].reshape( - (fit_sampling, fit_sampling) + surfacecolor=( + fit_dd_values[i] + * np.ones([fit_sampling, fit_sampling]) + if fit_color == "multi-fit" + else ( + mesh_in[i][invars.index(color_dd)].reshape( + (fit_sampling, fit_sampling) + ) + if ( + fit_color == "marker-color" + and color_dd in invars + ) + else mesh_out[i].reshape( + (fit_sampling, fit_sampling) + ) ) ), opacity=fit_opacity, - coloraxis="coloraxis2" - if ( - fit_color == "multi-fit" - or ( - fit_color == "output" - and ( - color_dd != outvar and color_dd != "OUTPUT" + coloraxis=( + "coloraxis2" + if ( + fit_color == "multi-fit" + or ( + fit_color == "output" + and ( + color_dd != outvar + and color_dd != "OUTPUT" + ) ) ) - ) - else "coloraxis", + else "coloraxis" + ), ) ) fig.update_layout( @@ -1420,20 +1444,24 @@ def update_figure( ) ) fig.update_xaxes( - range=[ - log10(min(fig.data[1]["x"])), - log10(max(fig.data[1]["x"])), - ] - if invar1_log == ["log"] - else [min(fig.data[1]["x"]), max(fig.data[1]["x"])] + range=( + [ + log10(min(fig.data[1]["x"])), + log10(max(fig.data[1]["x"])), + ] + if invar1_log == ["log"] + else [min(fig.data[1]["x"]), max(fig.data[1]["x"])] + ) ) fig.update_yaxes( - range=[ - log10(min(fig.data[1]["y"])), - log10(max(fig.data[1]["y"])), - ] - if invar2_log == ["log"] - else [min(fig.data[1]["y"]), max(fig.data[1]["y"])] + range=( + [ + log10(min(fig.data[1]["y"])), + log10(max(fig.data[1]["y"])), + ] + if invar2_log == ["log"] + else [min(fig.data[1]["y"]), max(fig.data[1]["y"])] + ) ) fig.update_layout( xaxis_title=invar, @@ -1531,9 +1559,11 @@ def update_figure( fig.update_traces( marker=dict( coloraxis="coloraxis2", - color=indata[color_dd][sel_y] - if color_dd in indata.dtype.names - else outdata[color_dd][sel_y], + color=( + indata[color_dd][sel_y] + if color_dd in indata.dtype.names + else outdata[color_dd][sel_y] + ), ), selector=dict(mode="markers"), ) @@ -1549,12 +1579,14 @@ def update_figure( fig.update_traces( marker=dict( coloraxis="coloraxis2", - color=outdata[outvar][sel_y] - if color_dd == "OUTPUT" - else ( - indata[color_dd][sel_y] - if color_dd in indata.dtype.names - else outdata[color_dd][sel_y] + color=( + outdata[outvar][sel_y] + if color_dd == "OUTPUT" + else ( + indata[color_dd][sel_y] + if color_dd in indata.dtype.names + else outdata[color_dd][sel_y] + ) ), ), selector=dict(mode="markers"), @@ -1581,12 +1613,14 @@ def update_figure( fig.update_traces( marker=dict( coloraxis="coloraxis", - color=outdata[outvar][sel_y] - if color_dd == "OUTPUT" - else ( - indata[color_dd][sel_y] - if color_dd in indata.dtype.names - else outdata[color_dd][sel_y] + color=( + outdata[outvar][sel_y] + if color_dd == "OUTPUT" + else ( + indata[color_dd][sel_y] + if color_dd in indata.dtype.names + else outdata[color_dd][sel_y] + ) ), ), selector=dict(mode="markers"), @@ -1605,12 +1639,14 @@ def update_figure( fig.update_traces( marker=dict( coloraxis="coloraxis", - color=outdata[outvar][sel_y] - if color_dd == "OUTPUT" - else ( - indata[color_dd][sel_y] - if color_dd in indata.dtype.names - else outdata[color_dd][sel_y] + color=( + outdata[outvar][sel_y] + if color_dd == "OUTPUT" + else ( + indata[color_dd][sel_y] + if color_dd in indata.dtype.names + else outdata[color_dd][sel_y] + ) ), ), selector=dict(mode="markers"), diff --git a/profit/util/halton.py b/profit/util/halton.py index 9eaf1a8..e774d49 100644 --- a/profit/util/halton.py +++ b/profit/util/halton.py @@ -27,6 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ + import numpy as np diff --git a/profit/util/util.py b/profit/util/util.py index be0cf55..ab2be20 100644 --- a/profit/util/util.py +++ b/profit/util/util.py @@ -2,6 +2,7 @@ This file contains miscellaneous useful functions. """ + from os import path from typing import Union from collections.abc import MutableMapping, Mapping diff --git a/tests/integration_tests/mockup/simulation_files/custom_components.py b/tests/integration_tests/mockup/simulation_files/custom_components.py index 44aa2bb..437ecde 100644 --- a/tests/integration_tests/mockup/simulation_files/custom_components.py +++ b/tests/integration_tests/mockup/simulation_files/custom_components.py @@ -1,4 +1,5 @@ """ mockup 1D example with a custom postprocessor """ + from profit.run import Postprocessor, Worker import numpy as np diff --git a/tests/integration_tests/mockup/simulation_files/mockup_worker.py b/tests/integration_tests/mockup/simulation_files/mockup_worker.py index fb31333..cf9b29f 100644 --- a/tests/integration_tests/mockup/simulation_files/mockup_worker.py +++ b/tests/integration_tests/mockup/simulation_files/mockup_worker.py @@ -1,4 +1,5 @@ """ versatile mockup Worker """ + from profit.run import Worker import numpy as np diff --git a/tests/unit_tests/config/mockup.py b/tests/unit_tests/config/mockup.py index 4d58b70..a67d90a 100644 --- a/tests/unit_tests/config/mockup.py +++ b/tests/unit_tests/config/mockup.py @@ -1,4 +1,5 @@ """Mockup domain code.""" + import numpy as np from h5py import File diff --git a/tests/unit_tests/run/simulation.py b/tests/unit_tests/run/simulation.py index faf91f5..b6b953d 100644 --- a/tests/unit_tests/run/simulation.py +++ b/tests/unit_tests/run/simulation.py @@ -1,4 +1,5 @@ """ versatile mockup Worker """ + from profit.run import Worker import numpy as np diff --git a/tests/unit_tests/sur/test_encoder.py b/tests/unit_tests/sur/test_encoder.py index 3087491..237636f 100644 --- a/tests/unit_tests/sur/test_encoder.py +++ b/tests/unit_tests/sur/test_encoder.py @@ -8,6 +8,7 @@ - PCA - Karuhnen-Loeve """ + import numpy as np from profit.sur.encoders import Encoder diff --git a/tests/unit_tests/variable/test_variable.py b/tests/unit_tests/variable/test_variable.py index b57f91e..eff978c 100644 --- a/tests/unit_tests/variable/test_variable.py +++ b/tests/unit_tests/variable/test_variable.py @@ -5,6 +5,7 @@ - ActiveLearning - VariableGroup """ + import numpy as np from profit.util.variable import Variable