From e8ed5d6017f2f491716ba3fc7e1ca69088efd8d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:14:33 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.11.0 → 24.1.1](https://github.com/psf/black/compare/23.11.0...24.1.1) - [github.com/astral-sh/ruff-pre-commit: v0.1.6 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.6...v0.2.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ba7d62bb..2d155d1aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,7 +57,7 @@ repos: - id: yamllint exclude: tests/optimization/fixtures - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 24.1.1 hooks: - id: black language_version: python3.10 @@ -79,7 +79,7 @@ repos: - --blank exclude: src/estimagic/optimization/algo_options.py - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.6 + rev: v0.2.0 hooks: - id: ruff - repo: https://github.com/nbQA-dev/nbQA From d166db05fa6976c385fadf164dbc98269a293355 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:15:25 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/estimagic/batch_evaluators.py | 1 + src/estimagic/benchmarking/cartis_roberts.py | 3 ++- src/estimagic/benchmarking/more_wild.py | 1 + src/estimagic/benchmarking/run_benchmark.py | 1 + src/estimagic/cli.py | 1 + src/estimagic/dashboard/dashboard_app.py | 1 + src/estimagic/dashboard/plot_functions.py | 1 + src/estimagic/decorators.py | 1 + src/estimagic/differentiation/derivatives.py | 8 +++++--- src/estimagic/differentiation/finite_differences.py | 1 + src/estimagic/estimation/estimate_msm.py | 1 + src/estimagic/examples/logit.py | 1 + src/estimagic/examples/numdiff_functions.py | 1 + src/estimagic/inference/ml_covs.py | 1 + src/estimagic/logging/read_from_database.py | 1 + src/estimagic/logging/read_log.py | 1 + src/estimagic/optimization/bhhh.py | 1 + src/estimagic/optimization/cyipopt_optimizers.py | 1 + src/estimagic/optimization/fides_optimizers.py | 1 + src/estimagic/optimization/nag_optimizers.py | 1 + src/estimagic/optimization/neldermead.py | 1 + src/estimagic/optimization/nlopt_optimizers.py | 1 + src/estimagic/optimization/pounders.py | 1 + src/estimagic/optimization/pounders_auxiliary.py | 7 ++++--- src/estimagic/optimization/pounders_history.py | 1 + src/estimagic/optimization/pygmo_optimizers.py | 1 + src/estimagic/optimization/scipy_optimizers.py | 1 + src/estimagic/optimization/simopt_optimizers.py | 1 + .../optimization/subsolvers/_conjugate_gradient.py | 1 + src/estimagic/optimization/subsolvers/_steihaug_toint.py | 1 + src/estimagic/optimization/subsolvers/_trsbox.py | 1 + src/estimagic/optimization/subsolvers/bntr.py | 4 ++-- src/estimagic/optimization/subsolvers/gqtpar.py | 5 ++--- .../optimization/subsolvers/linear_subsolvers.py | 5 ++--- src/estimagic/optimization/tao_optimizers.py | 7 ++++--- src/estimagic/optimization/tiktak.py | 1 + src/estimagic/parameters/block_trees.py | 1 + src/estimagic/parameters/check_constraints.py | 1 + src/estimagic/parameters/consolidate_constraints.py | 1 + src/estimagic/parameters/conversion.py | 1 + src/estimagic/parameters/kernel_transformations.py | 1 + src/estimagic/parameters/process_constraints.py | 1 + src/estimagic/parameters/space_conversion.py | 1 + src/estimagic/parameters/tree_registry.py | 1 + src/estimagic/process_user_function.py | 1 + src/estimagic/sensitivity/msm_sensitivity.py | 1 + src/estimagic/visualization/derivative_plot.py | 1 + tests/dashboard/test_colors.py | 1 + tests/dashboard/test_dashboard_app.py | 1 + tests/dashboard/test_run_dashboard.py | 1 + .../differentiation/test_compare_derivatives_with_jax.py | 1 + tests/estimation/test_estimate_msm.py | 1 + .../test_estimate_msm_dict_params_and_moments.py | 1 + tests/examples/test_logit.py | 1 + tests/optimization/test_bhhh.py | 1 + tests/optimization/test_criterion_versions.py | 1 + tests/optimization/test_derivative_versions.py | 1 + tests/optimization/test_fides_options.py | 1 + tests/optimization/test_ipopt_options.py | 1 + tests/optimization/test_linear_subsolvers.py | 1 + tests/optimization/test_many_algorithms.py | 1 + tests/optimization/test_optimization_helpers.py | 1 + tests/optimization/test_optimizations_with_scaling.py | 1 + tests/optimization/test_optimize.py | 1 + tests/optimization/test_pounders_history.py | 1 + tests/optimization/test_pounders_integration.py | 1 + tests/optimization/test_pounders_unit.py | 1 + tests/optimization/test_quadratic_subsolvers.py | 1 + tests/optimization/test_tao_optimizers.py | 1 + tests/optimization/test_with_advanced_constraints.py | 1 + tests/optimization/test_with_constraints.py | 1 + tests/optimization/test_with_logging.py | 1 + tests/parameters/test_process_constraints.py | 1 + 73 files changed, 87 insertions(+), 18 deletions(-) diff --git a/src/estimagic/batch_evaluators.py b/src/estimagic/batch_evaluators.py index c66aa3f93..ce979ae37 100644 --- a/src/estimagic/batch_evaluators.py +++ b/src/estimagic/batch_evaluators.py @@ -4,6 +4,7 @@ can be used used as batch evaluator in estimagic. """ + from joblib import Parallel, delayed try: diff --git a/src/estimagic/benchmarking/cartis_roberts.py b/src/estimagic/benchmarking/cartis_roberts.py index 293ed1272..be89d5034 100644 --- a/src/estimagic/benchmarking/cartis_roberts.py +++ b/src/estimagic/benchmarking/cartis_roberts.py @@ -14,6 +14,7 @@ - https://vanderbei.princeton.edu/ampl/nlmodels/cute/index.html """ + from functools import partial import numpy as np @@ -5128,7 +5129,7 @@ def get_start_points_methanl8(): "start_x": [-1] * 98, "solution_x": None, "start_criterion": 3.2160e4, - "solution_criterion": None + "solution_criterion": None, # we found a lower minimum than Cartis and Roberts (2019) at 1651.837; # according to table 3 in their paper, the minimum is at 4292.197. # We suspect, however, that the true optimum is even lower. diff --git a/src/estimagic/benchmarking/more_wild.py b/src/estimagic/benchmarking/more_wild.py index aa951143d..250c155b6 100644 --- a/src/estimagic/benchmarking/more_wild.py +++ b/src/estimagic/benchmarking/more_wild.py @@ -20,6 +20,7 @@ - Whether the base start vector is multiplied by a factor of ten or not (column 4). """ + from functools import partial import numpy as np diff --git a/src/estimagic/benchmarking/run_benchmark.py b/src/estimagic/benchmarking/run_benchmark.py index e02203a95..2f1a9b1b0 100644 --- a/src/estimagic/benchmarking/run_benchmark.py +++ b/src/estimagic/benchmarking/run_benchmark.py @@ -7,6 +7,7 @@ - Add option for deterministic noise or wiggle. """ + import numpy as np from estimagic import batch_evaluators diff --git a/src/estimagic/cli.py b/src/estimagic/cli.py index c57cba967..7cd5eef7f 100644 --- a/src/estimagic/cli.py +++ b/src/estimagic/cli.py @@ -1,4 +1,5 @@ """This module comprises all CLI capabilities of estimagic.""" + import click from estimagic.dashboard.run_dashboard import run_dashboard diff --git a/src/estimagic/dashboard/dashboard_app.py b/src/estimagic/dashboard/dashboard_app.py index 987933774..9fd684275 100644 --- a/src/estimagic/dashboard/dashboard_app.py +++ b/src/estimagic/dashboard/dashboard_app.py @@ -1,4 +1,5 @@ """Show the development of one database's criterion and parameters over time.""" + from functools import partial from pathlib import Path diff --git a/src/estimagic/dashboard/plot_functions.py b/src/estimagic/dashboard/plot_functions.py index a442624f7..b7a06b20d 100644 --- a/src/estimagic/dashboard/plot_functions.py +++ b/src/estimagic/dashboard/plot_functions.py @@ -1,4 +1,5 @@ """Helper functions for the dashboard.""" + from bokeh.models import HoverTool, Legend from bokeh.plotting import figure diff --git a/src/estimagic/decorators.py b/src/estimagic/decorators.py index 419ebbd0d..9f3243010 100644 --- a/src/estimagic/decorators.py +++ b/src/estimagic/decorators.py @@ -23,6 +23,7 @@ https://realpython.com/primer-on-python-decorators/ """ + import functools import inspect import warnings diff --git a/src/estimagic/differentiation/derivatives.py b/src/estimagic/differentiation/derivatives.py index 8ea3bc1df..fe3a09a39 100644 --- a/src/estimagic/differentiation/derivatives.py +++ b/src/estimagic/differentiation/derivatives.py @@ -747,9 +747,11 @@ def _convert_evals_to_numpy( evals = [val.astype(float) if not _is_scalar_nan(val) else val for val in evals] else: evals = [ - np.array(tree_leaves(val, registry=registry), dtype=np.float64) - if not _is_scalar_nan(val) - else val + ( + np.array(tree_leaves(val, registry=registry), dtype=np.float64) + if not _is_scalar_nan(val) + else val + ) for val in evals ] diff --git a/src/estimagic/differentiation/finite_differences.py b/src/estimagic/differentiation/finite_differences.py index 3b613fda3..c3a15b3a5 100644 --- a/src/estimagic/differentiation/finite_differences.py +++ b/src/estimagic/differentiation/finite_differences.py @@ -8,6 +8,7 @@ warnings or errors for that case. """ + from typing import NamedTuple import numpy as np diff --git a/src/estimagic/estimation/estimate_msm.py b/src/estimagic/estimation/estimate_msm.py index e5fb23d11..d68fb5ba5 100644 --- a/src/estimagic/estimation/estimate_msm.py +++ b/src/estimagic/estimation/estimate_msm.py @@ -1,4 +1,5 @@ """Do a method of simlated moments estimation.""" + import functools import warnings from collections.abc import Callable diff --git a/src/estimagic/examples/logit.py b/src/estimagic/examples/logit.py index 9ad8c5abd..dc9365bd8 100644 --- a/src/estimagic/examples/logit.py +++ b/src/estimagic/examples/logit.py @@ -1,4 +1,5 @@ """Likelihood functions and derivatives of a logit model.""" + import numpy as np import pandas as pd diff --git a/src/estimagic/examples/numdiff_functions.py b/src/estimagic/examples/numdiff_functions.py index d99bf6b17..8ddd6139a 100644 --- a/src/estimagic/examples/numdiff_functions.py +++ b/src/estimagic/examples/numdiff_functions.py @@ -8,6 +8,7 @@ We pickled them so we don't need statsmodels as a dependency. """ + import numpy as np from scipy.stats import norm diff --git a/src/estimagic/inference/ml_covs.py b/src/estimagic/inference/ml_covs.py index de649e292..c71cd1bc0 100644 --- a/src/estimagic/inference/ml_covs.py +++ b/src/estimagic/inference/ml_covs.py @@ -1,4 +1,5 @@ """Functions for inferences in maximum likelihood models.""" + import numpy as np import pandas as pd diff --git a/src/estimagic/logging/read_from_database.py b/src/estimagic/logging/read_from_database.py index af28ecf6e..1ed7fd012 100644 --- a/src/estimagic/logging/read_from_database.py +++ b/src/estimagic/logging/read_from_database.py @@ -9,6 +9,7 @@ ``read_log.py`` instead. """ + import traceback import warnings diff --git a/src/estimagic/logging/read_log.py b/src/estimagic/logging/read_log.py index b5ed2cca0..39e55488b 100644 --- a/src/estimagic/logging/read_log.py +++ b/src/estimagic/logging/read_log.py @@ -7,6 +7,7 @@ path_or_database. Otherwise, the functions may be very slow. """ + from dataclasses import dataclass from pathlib import Path from typing import Union diff --git a/src/estimagic/optimization/bhhh.py b/src/estimagic/optimization/bhhh.py index 37baf753b..7249698ed 100644 --- a/src/estimagic/optimization/bhhh.py +++ b/src/estimagic/optimization/bhhh.py @@ -1,4 +1,5 @@ """Implement Berndt-Hall-Hall-Hausman (BHHH) algorithm.""" + import numpy as np from estimagic.decorators import mark_minimizer diff --git a/src/estimagic/optimization/cyipopt_optimizers.py b/src/estimagic/optimization/cyipopt_optimizers.py index 4e98f4c4b..2bfa70afe 100644 --- a/src/estimagic/optimization/cyipopt_optimizers.py +++ b/src/estimagic/optimization/cyipopt_optimizers.py @@ -1,4 +1,5 @@ """Implement cyipopt's Interior Point Optimizer.""" + import numpy as np from estimagic.config import IS_CYIPOPT_INSTALLED diff --git a/src/estimagic/optimization/fides_optimizers.py b/src/estimagic/optimization/fides_optimizers.py index d33f843b5..e8f45e56c 100644 --- a/src/estimagic/optimization/fides_optimizers.py +++ b/src/estimagic/optimization/fides_optimizers.py @@ -1,4 +1,5 @@ """Implement the fides optimizer.""" + import logging import numpy as np diff --git a/src/estimagic/optimization/nag_optimizers.py b/src/estimagic/optimization/nag_optimizers.py index 3e786af99..36d224e3b 100644 --- a/src/estimagic/optimization/nag_optimizers.py +++ b/src/estimagic/optimization/nag_optimizers.py @@ -9,6 +9,7 @@ and algorithm. """ + import warnings import numpy as np diff --git a/src/estimagic/optimization/neldermead.py b/src/estimagic/optimization/neldermead.py index 5e4156bd2..c7ac39aba 100644 --- a/src/estimagic/optimization/neldermead.py +++ b/src/estimagic/optimization/neldermead.py @@ -1,4 +1,5 @@ """Implementation of parallelosation of Nelder-Mead algorithm.""" + import numpy as np from estimagic.batch_evaluators import process_batch_evaluator diff --git a/src/estimagic/optimization/nlopt_optimizers.py b/src/estimagic/optimization/nlopt_optimizers.py index 196df5bb9..1eca21ae5 100644 --- a/src/estimagic/optimization/nlopt_optimizers.py +++ b/src/estimagic/optimization/nlopt_optimizers.py @@ -3,6 +3,7 @@ The documentation is heavily based on (nlopt documentation)[nlopt.readthedocs.io]. """ + import numpy as np from estimagic.config import IS_NLOPT_INSTALLED diff --git a/src/estimagic/optimization/pounders.py b/src/estimagic/optimization/pounders.py index ebec3b5d9..c96129054 100644 --- a/src/estimagic/optimization/pounders.py +++ b/src/estimagic/optimization/pounders.py @@ -1,4 +1,5 @@ """Implement the POUNDERS algorithm.""" + import warnings import numpy as np diff --git a/src/estimagic/optimization/pounders_auxiliary.py b/src/estimagic/optimization/pounders_auxiliary.py index 3f5b2158e..f6c04753e 100644 --- a/src/estimagic/optimization/pounders_auxiliary.py +++ b/src/estimagic/optimization/pounders_auxiliary.py @@ -1,4 +1,5 @@ """Auxiliary functions for the pounders algorithm.""" + from typing import NamedTuple, Union import numpy as np @@ -15,9 +16,9 @@ class ResidualModel(NamedTuple): intercepts: Union[np.ndarray, None] = None # shape (n_residuals,) linear_terms: Union[np.ndarray, None] = None # shape (n_residuals, n_params) - square_terms: Union[ - np.ndarray, None - ] = None # shape (n_residuals, n_params, n_params) + square_terms: Union[np.ndarray, None] = ( + None # shape (n_residuals, n_params, n_params) + ) class MainModel(NamedTuple): diff --git a/src/estimagic/optimization/pounders_history.py b/src/estimagic/optimization/pounders_history.py index 9506d96c4..643b23995 100644 --- a/src/estimagic/optimization/pounders_history.py +++ b/src/estimagic/optimization/pounders_history.py @@ -1,4 +1,5 @@ """History class for pounders and similar optimizers.""" + import numpy as np diff --git a/src/estimagic/optimization/pygmo_optimizers.py b/src/estimagic/optimization/pygmo_optimizers.py index 906ac926a..0044fa5df 100644 --- a/src/estimagic/optimization/pygmo_optimizers.py +++ b/src/estimagic/optimization/pygmo_optimizers.py @@ -1,4 +1,5 @@ """Implement pygmo optimizers.""" + import contextlib import warnings diff --git a/src/estimagic/optimization/scipy_optimizers.py b/src/estimagic/optimization/scipy_optimizers.py index 82a15859c..661956f27 100644 --- a/src/estimagic/optimization/scipy_optimizers.py +++ b/src/estimagic/optimization/scipy_optimizers.py @@ -34,6 +34,7 @@ terminate if it returned True. """ + import functools import numpy as np diff --git a/src/estimagic/optimization/simopt_optimizers.py b/src/estimagic/optimization/simopt_optimizers.py index 23b5ff465..d0baa418c 100644 --- a/src/estimagic/optimization/simopt_optimizers.py +++ b/src/estimagic/optimization/simopt_optimizers.py @@ -4,6 +4,7 @@ However, for the moment they are not supported. """ + import numpy as np from estimagic.config import IS_SIMOPT_INSTALLED diff --git a/src/estimagic/optimization/subsolvers/_conjugate_gradient.py b/src/estimagic/optimization/subsolvers/_conjugate_gradient.py index 7f07cd57f..78868d135 100644 --- a/src/estimagic/optimization/subsolvers/_conjugate_gradient.py +++ b/src/estimagic/optimization/subsolvers/_conjugate_gradient.py @@ -1,4 +1,5 @@ """Implementation of the Conjugate Gradient algorithm.""" + import numpy as np diff --git a/src/estimagic/optimization/subsolvers/_steihaug_toint.py b/src/estimagic/optimization/subsolvers/_steihaug_toint.py index ad64c8160..ec2abb219 100644 --- a/src/estimagic/optimization/subsolvers/_steihaug_toint.py +++ b/src/estimagic/optimization/subsolvers/_steihaug_toint.py @@ -1,4 +1,5 @@ """Implementation of the Steihaug-Toint Conjugate Gradient algorithm.""" + import numpy as np diff --git a/src/estimagic/optimization/subsolvers/_trsbox.py b/src/estimagic/optimization/subsolvers/_trsbox.py index dc529de77..33dc9db71 100644 --- a/src/estimagic/optimization/subsolvers/_trsbox.py +++ b/src/estimagic/optimization/subsolvers/_trsbox.py @@ -1,4 +1,5 @@ """Implementation of the quadratic trustregion solver TRSBOX.""" + import numpy as np diff --git a/src/estimagic/optimization/subsolvers/bntr.py b/src/estimagic/optimization/subsolvers/bntr.py index e54f9b492..8f23c0d53 100644 --- a/src/estimagic/optimization/subsolvers/bntr.py +++ b/src/estimagic/optimization/subsolvers/bntr.py @@ -1,4 +1,5 @@ """Auxiliary functions for the quadratic BNTR trust-region subsolver.""" + from functools import reduce from typing import NamedTuple, Union @@ -583,8 +584,7 @@ def _perform_gradient_descent_step( square_terms = x_inactive.T @ hessian_inactive @ x_inactive predicted_reduction = trustregion_radius * ( - gradient_norm - - 0.5 * trustregion_radius * square_terms / (gradient_norm**2) + gradient_norm - 0.5 * trustregion_radius * square_terms / (gradient_norm**2) ) actual_reduction = f_candidate_initial - f_candidate diff --git a/src/estimagic/optimization/subsolvers/gqtpar.py b/src/estimagic/optimization/subsolvers/gqtpar.py index 15b2bd5bb..d658ba402 100644 --- a/src/estimagic/optimization/subsolvers/gqtpar.py +++ b/src/estimagic/optimization/subsolvers/gqtpar.py @@ -1,4 +1,5 @@ """Auxiliary functions for the quadratic GQTPAR trust-region subsolver.""" + from typing import NamedTuple, Union import numpy as np @@ -356,9 +357,7 @@ def _update_lambdas_when_factorization_unsuccessful( ) v_norm = np.linalg.norm(v) - lambda_lower_bound = max( - lambdas.lower_bound, lambdas.candidate + delta / v_norm**2 - ) + lambda_lower_bound = max(lambdas.lower_bound, lambdas.candidate + delta / v_norm**2) lambda_new_candidate = _get_new_lambda_candidate( lower_bound=lambda_lower_bound, upper_bound=lambdas.upper_bound ) diff --git a/src/estimagic/optimization/subsolvers/linear_subsolvers.py b/src/estimagic/optimization/subsolvers/linear_subsolvers.py index fd33dda36..be33fb4a5 100644 --- a/src/estimagic/optimization/subsolvers/linear_subsolvers.py +++ b/src/estimagic/optimization/subsolvers/linear_subsolvers.py @@ -1,4 +1,5 @@ """Collection of linear trust-region subsolvers.""" + from typing import NamedTuple, Union import numpy as np @@ -326,9 +327,7 @@ def _get_distance_to_trustregion_boundary( else: distance_to_boundary = ( np.sqrt( - np.maximum( - 0, g_dot_x**2 + g_sumsq * (trustregion_radius**2 - x_sumsq) - ) + np.maximum(0, g_dot_x**2 + g_sumsq * (trustregion_radius**2 - x_sumsq)) ) - g_dot_x ) / g_sumsq diff --git a/src/estimagic/optimization/tao_optimizers.py b/src/estimagic/optimization/tao_optimizers.py index 8248589b9..fc183ef7d 100644 --- a/src/estimagic/optimization/tao_optimizers.py +++ b/src/estimagic/optimization/tao_optimizers.py @@ -1,4 +1,5 @@ """This module implements the POUNDERs algorithm.""" + import contextlib import functools @@ -257,9 +258,9 @@ def _process_pounders_results(residuals_out, tao): "n_derivative_evaluations": None, "n_iterations": None, "success": bool(convergence_code >= 0), - "reached_convergence_criterion": convergence_reason - if convergence_code >= 0 - else None, + "reached_convergence_criterion": ( + convergence_reason if convergence_code >= 0 else None + ), "message": convergence_reason, # Further results. "solution_criterion_values": residuals_out.array, diff --git a/src/estimagic/optimization/tiktak.py b/src/estimagic/optimization/tiktak.py index c9e32d975..42278ab1e 100644 --- a/src/estimagic/optimization/tiktak.py +++ b/src/estimagic/optimization/tiktak.py @@ -10,6 +10,7 @@ `GitHub Repository `_) """ + import warnings from functools import partial diff --git a/src/estimagic/parameters/block_trees.py b/src/estimagic/parameters/block_trees.py index 3961b5758..526fd276b 100644 --- a/src/estimagic/parameters/block_trees.py +++ b/src/estimagic/parameters/block_trees.py @@ -1,4 +1,5 @@ """Functions to convert between array and block-tree representations of a matrix.""" + import numpy as np import pandas as pd from pybaum import tree_flatten, tree_unflatten diff --git a/src/estimagic/parameters/check_constraints.py b/src/estimagic/parameters/check_constraints.py index ea6ab88fe..216516e0e 100644 --- a/src/estimagic/parameters/check_constraints.py +++ b/src/estimagic/parameters/check_constraints.py @@ -3,6 +3,7 @@ See the module docstring of process_constraints for naming conventions. """ + from functools import partial import numpy as np diff --git a/src/estimagic/parameters/consolidate_constraints.py b/src/estimagic/parameters/consolidate_constraints.py index c31486522..875edd2c6 100644 --- a/src/estimagic/parameters/consolidate_constraints.py +++ b/src/estimagic/parameters/consolidate_constraints.py @@ -6,6 +6,7 @@ Check the module docstring of process_constraints for naming conventions. """ + import numpy as np import pandas as pd diff --git a/src/estimagic/parameters/conversion.py b/src/estimagic/parameters/conversion.py index 895053927..1a7f2cf73 100644 --- a/src/estimagic/parameters/conversion.py +++ b/src/estimagic/parameters/conversion.py @@ -1,4 +1,5 @@ """Aggregate the multiple parameter and function output conversions into on.""" + from typing import NamedTuple import numpy as np diff --git a/src/estimagic/parameters/kernel_transformations.py b/src/estimagic/parameters/kernel_transformations.py index c144b74b7..c12502922 100644 --- a/src/estimagic/parameters/kernel_transformations.py +++ b/src/estimagic/parameters/kernel_transformations.py @@ -28,6 +28,7 @@ https://google.github.io/styleguide/pyguide.html """ + import numpy as np from estimagic.utilities import ( diff --git a/src/estimagic/parameters/process_constraints.py b/src/estimagic/parameters/process_constraints.py index ae76301bb..0dbf89595 100644 --- a/src/estimagic/parameters/process_constraints.py +++ b/src/estimagic/parameters/process_constraints.py @@ -14,6 +14,7 @@ only be done after consolidation. """ + import numpy as np import pandas as pd diff --git a/src/estimagic/parameters/space_conversion.py b/src/estimagic/parameters/space_conversion.py index 528d95747..08e8f810c 100644 --- a/src/estimagic/parameters/space_conversion.py +++ b/src/estimagic/parameters/space_conversion.py @@ -32,6 +32,7 @@ n_internal the length of the internal parameter vector. """ + from functools import partial from typing import NamedTuple diff --git a/src/estimagic/parameters/tree_registry.py b/src/estimagic/parameters/tree_registry.py index 688200f44..dcf0f86c3 100644 --- a/src/estimagic/parameters/tree_registry.py +++ b/src/estimagic/parameters/tree_registry.py @@ -1,4 +1,5 @@ """Wrapper around pybaum get_registry to tailor it to estimagic.""" + from functools import partial from itertools import product diff --git a/src/estimagic/process_user_function.py b/src/estimagic/process_user_function.py index a511b0df8..fc8168fce 100644 --- a/src/estimagic/process_user_function.py +++ b/src/estimagic/process_user_function.py @@ -1,4 +1,5 @@ """Process user provided functions.""" + import inspect from functools import partial diff --git a/src/estimagic/sensitivity/msm_sensitivity.py b/src/estimagic/sensitivity/msm_sensitivity.py index cffa1e87f..b25161887 100644 --- a/src/estimagic/sensitivity/msm_sensitivity.py +++ b/src/estimagic/sensitivity/msm_sensitivity.py @@ -7,6 +7,7 @@ (https://onlinelibrary.wiley.com/doi/full/10.1002/jae.2779) """ + import numpy as np import pandas as pd from estimagic.exceptions import INVALID_SENSITIVITY_MSG diff --git a/src/estimagic/visualization/derivative_plot.py b/src/estimagic/visualization/derivative_plot.py index 228db1e53..f0406a9a6 100644 --- a/src/estimagic/visualization/derivative_plot.py +++ b/src/estimagic/visualization/derivative_plot.py @@ -1,4 +1,5 @@ """Visualize and compare derivative estimates.""" + import itertools import numpy as np diff --git a/tests/dashboard/test_colors.py b/tests/dashboard/test_colors.py index 62029cd0d..83a8058dd 100644 --- a/tests/dashboard/test_colors.py +++ b/tests/dashboard/test_colors.py @@ -1,4 +1,5 @@ """This only tests that we get the right number of colors, not the exact colors.""" + import pytest from estimagic.dashboard.colors import get_colors diff --git a/tests/dashboard/test_dashboard_app.py b/tests/dashboard/test_dashboard_app.py index 8e56714dc..1de2d4b3e 100644 --- a/tests/dashboard/test_dashboard_app.py +++ b/tests/dashboard/test_dashboard_app.py @@ -1,4 +1,5 @@ """Test the functions of the dashboard app.""" + import numpy as np import pandas as pd import pandas.testing as pdt diff --git a/tests/dashboard/test_run_dashboard.py b/tests/dashboard/test_run_dashboard.py index 37df1a380..8fe0213f2 100644 --- a/tests/dashboard/test_run_dashboard.py +++ b/tests/dashboard/test_run_dashboard.py @@ -1,4 +1,5 @@ """Test the functions to run the dashboard.""" + from click.testing import CliRunner from estimagic.cli import cli from estimagic.config import EXAMPLE_DIR diff --git a/tests/differentiation/test_compare_derivatives_with_jax.py b/tests/differentiation/test_compare_derivatives_with_jax.py index ffc8b8820..8c30b891d 100644 --- a/tests/differentiation/test_compare_derivatives_with_jax.py +++ b/tests/differentiation/test_compare_derivatives_with_jax.py @@ -3,6 +3,7 @@ This test module only runs if jax is installed. """ + import numpy as np import pytest from estimagic.config import IS_JAX_INSTALLED diff --git a/tests/estimation/test_estimate_msm.py b/tests/estimation/test_estimate_msm.py index 397d167c4..6113f265b 100644 --- a/tests/estimation/test_estimate_msm.py +++ b/tests/estimation/test_estimate_msm.py @@ -1,4 +1,5 @@ """Most test exploit the special case where simulate_moments just returns parameters.""" + import itertools import numpy as np diff --git a/tests/estimation/test_estimate_msm_dict_params_and_moments.py b/tests/estimation/test_estimate_msm_dict_params_and_moments.py index 8ef3cd1e4..7c2e499e5 100644 --- a/tests/estimation/test_estimate_msm_dict_params_and_moments.py +++ b/tests/estimation/test_estimate_msm_dict_params_and_moments.py @@ -1,4 +1,5 @@ """Most test exploit the special case where simulate_moments just returns parameters.""" + import numpy as np import pandas as pd from estimagic.estimation.estimate_msm import estimate_msm diff --git a/tests/examples/test_logit.py b/tests/examples/test_logit.py index ab3f1050c..168a6fb4d 100644 --- a/tests/examples/test_logit.py +++ b/tests/examples/test_logit.py @@ -1,4 +1,5 @@ """Tests for the logit example.""" + import numpy as np from estimagic.examples.logit import logit_derivative, logit_hessian, logit_loglike from numpy.testing import assert_array_almost_equal as aaae diff --git a/tests/optimization/test_bhhh.py b/tests/optimization/test_bhhh.py index 324c31cc6..732049395 100644 --- a/tests/optimization/test_bhhh.py +++ b/tests/optimization/test_bhhh.py @@ -1,4 +1,5 @@ """Test the internal BHHH algorithm.""" + from functools import partial import numpy as np diff --git a/tests/optimization/test_criterion_versions.py b/tests/optimization/test_criterion_versions.py index 1dd539648..21f7ff05d 100644 --- a/tests/optimization/test_criterion_versions.py +++ b/tests/optimization/test_criterion_versions.py @@ -6,6 +6,7 @@ - Many criterion versions (dict output, pandas output, scalar output) """ + import numpy as np import pandas as pd import pytest diff --git a/tests/optimization/test_derivative_versions.py b/tests/optimization/test_derivative_versions.py index bf7ee6698..e77129d07 100644 --- a/tests/optimization/test_derivative_versions.py +++ b/tests/optimization/test_derivative_versions.py @@ -7,6 +7,7 @@ - Maximize and minimize since this might make a difference """ + import numpy as np import pandas as pd import pytest diff --git a/tests/optimization/test_fides_options.py b/tests/optimization/test_fides_options.py index ee9e3e20f..41401fa62 100644 --- a/tests/optimization/test_fides_options.py +++ b/tests/optimization/test_fides_options.py @@ -1,4 +1,5 @@ """Test the different options of fides.""" + import numpy as np import pytest from estimagic.config import IS_FIDES_INSTALLED diff --git a/tests/optimization/test_ipopt_options.py b/tests/optimization/test_ipopt_options.py index 2e070aff5..fda82b8d8 100644 --- a/tests/optimization/test_ipopt_options.py +++ b/tests/optimization/test_ipopt_options.py @@ -1,4 +1,5 @@ """Test the different options of ipopt.""" + import numpy as np import pytest from estimagic.config import IS_CYIPOPT_INSTALLED diff --git a/tests/optimization/test_linear_subsolvers.py b/tests/optimization/test_linear_subsolvers.py index 10f56ca44..062a0e04a 100644 --- a/tests/optimization/test_linear_subsolvers.py +++ b/tests/optimization/test_linear_subsolvers.py @@ -1,4 +1,5 @@ """Test suite for linear trust-region subsolvers.""" + import math import numpy as np diff --git a/tests/optimization/test_many_algorithms.py b/tests/optimization/test_many_algorithms.py index 1e7bf170c..f00efc111 100644 --- a/tests/optimization/test_many_algorithms.py +++ b/tests/optimization/test_many_algorithms.py @@ -4,6 +4,7 @@ - only numerical derivative """ + import inspect import sys diff --git a/tests/optimization/test_optimization_helpers.py b/tests/optimization/test_optimization_helpers.py index d669e49f9..dab297b90 100644 --- a/tests/optimization/test_optimization_helpers.py +++ b/tests/optimization/test_optimization_helpers.py @@ -1,4 +1,5 @@ """Test optimization helper functions.""" + import numpy as np import pytest from estimagic.optimization.pygmo_optimizers import ( diff --git a/tests/optimization/test_optimizations_with_scaling.py b/tests/optimization/test_optimizations_with_scaling.py index 2d0fe26eb..df4e89218 100644 --- a/tests/optimization/test_optimizations_with_scaling.py +++ b/tests/optimization/test_optimizations_with_scaling.py @@ -1,4 +1,5 @@ """Test a subset of algorithms with different scaling methods on sum of squares.""" + import itertools import numpy as np diff --git a/tests/optimization/test_optimize.py b/tests/optimization/test_optimize.py index f0934ae2e..86af1b7a4 100644 --- a/tests/optimization/test_optimize.py +++ b/tests/optimization/test_optimize.py @@ -1,4 +1,5 @@ """Tests for (almost) algorithm independent properties of maximize and minimize.""" + import numpy as np import pandas as pd import pytest diff --git a/tests/optimization/test_pounders_history.py b/tests/optimization/test_pounders_history.py index fc38905a9..c13566f02 100644 --- a/tests/optimization/test_pounders_history.py +++ b/tests/optimization/test_pounders_history.py @@ -1,4 +1,5 @@ """Test the history class for least-squares optimizers.""" + import numpy as np import pytest from estimagic.optimization.pounders_history import LeastSquaresHistory diff --git a/tests/optimization/test_pounders_integration.py b/tests/optimization/test_pounders_integration.py index dcae6e091..e6e39b5b9 100644 --- a/tests/optimization/test_pounders_integration.py +++ b/tests/optimization/test_pounders_integration.py @@ -1,4 +1,5 @@ """Test suite for the internal pounders interface.""" + import sys from functools import partial diff --git a/tests/optimization/test_pounders_unit.py b/tests/optimization/test_pounders_unit.py index 1c6e51e8d..2291fd378 100644 --- a/tests/optimization/test_pounders_unit.py +++ b/tests/optimization/test_pounders_unit.py @@ -1,4 +1,5 @@ """Test the auxiliary functions of the pounders algorithm.""" + from collections import namedtuple from functools import partial diff --git a/tests/optimization/test_quadratic_subsolvers.py b/tests/optimization/test_quadratic_subsolvers.py index c2d9f1fe2..12d17e960 100644 --- a/tests/optimization/test_quadratic_subsolvers.py +++ b/tests/optimization/test_quadratic_subsolvers.py @@ -1,4 +1,5 @@ """Test various solvers for quadratic trust-region subproblems.""" + import numpy as np import pytest from estimagic.optimization.pounders_auxiliary import MainModel diff --git a/tests/optimization/test_tao_optimizers.py b/tests/optimization/test_tao_optimizers.py index 984bdc350..a5cd31884 100644 --- a/tests/optimization/test_tao_optimizers.py +++ b/tests/optimization/test_tao_optimizers.py @@ -1,4 +1,5 @@ """Test the wrapper around pounders.""" + import functools import numpy as np diff --git a/tests/optimization/test_with_advanced_constraints.py b/tests/optimization/test_with_advanced_constraints.py index f909a794a..57898644c 100644 --- a/tests/optimization/test_with_advanced_constraints.py +++ b/tests/optimization/test_with_advanced_constraints.py @@ -5,6 +5,7 @@ - Only minimize """ + import itertools import numpy as np diff --git a/tests/optimization/test_with_constraints.py b/tests/optimization/test_with_constraints.py index 956bc94b8..5fcf7b010 100644 --- a/tests/optimization/test_with_constraints.py +++ b/tests/optimization/test_with_constraints.py @@ -6,6 +6,7 @@ - closed form and numerical derivatives """ + from copy import deepcopy import numpy as np diff --git a/tests/optimization/test_with_logging.py b/tests/optimization/test_with_logging.py index 1e8fd5460..8a672a802 100644 --- a/tests/optimization/test_with_logging.py +++ b/tests/optimization/test_with_logging.py @@ -6,6 +6,7 @@ - with and without derivatives """ + import numpy as np import pandas as pd import pytest diff --git a/tests/parameters/test_process_constraints.py b/tests/parameters/test_process_constraints.py index bb6388d79..fc4739b0a 100644 --- a/tests/parameters/test_process_constraints.py +++ b/tests/parameters/test_process_constraints.py @@ -1,4 +1,5 @@ """Test the pc processing.""" + import numpy as np import pandas as pd import pytest