From cebcb6bc43d11348df3f509370b023bf3bac59b8 Mon Sep 17 00:00:00 2001 From: Ambroise Odonnat Date: Thu, 6 Jun 2024 14:41:46 +0200 Subject: [PATCH] DOC benchmark_utils/__init__.py (#38) Co-authored-by: mathurinm --- benchmark_utils/__init__.py | 13 ++++++++++++- objective.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/benchmark_utils/__init__.py b/benchmark_utils/__init__.py index 5b515af..880e5cc 100644 --- a/benchmark_utils/__init__.py +++ b/benchmark_utils/__init__.py @@ -1,7 +1,18 @@ # `benchmark_utils` is a module in which you can define code to reuse in # the benchmark objective, datasets, and solvers. The folder should have the # name `benchmark_utils`, and code defined inside will be importable using -# the usual import syntax +# the usual import syntax. To import external packages in this file, use a +# `safe_import_context` named "import_ctx", as follows: + +from benchopt.utils import safe_import_context + +with safe_import_context() as import_ctx: + import numpy as np + def gradient_ols(X, y, beta): return X.T @ (X @ beta - y) + + +def value_ols(X, y, beta): + return 0.5 * np.mean((y - X @ beta) ** 2) diff --git a/objective.py b/objective.py index 6588650..5276334 100644 --- a/objective.py +++ b/objective.py @@ -32,7 +32,7 @@ class Objective(BaseObjective): # solvers or datasets should be declared in Dataset or Solver (see # simulated.py and python-gd.py). # Example syntax: requirements = ['numpy', 'pip:jax', 'pytorch:pytorch'] - requirements = [] + requirements = ["numpy"] # Minimal version of benchopt required to run this benchmark. # Bump it up if the benchmark depends on a new feature of benchopt.