Skip to content

Commit 9a40583

Browse files
[pre-commit.ci] pre-commit autoupdate (#555)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tim Mensinger <[email protected]>
1 parent 15ac4c2 commit 9a40583

21 files changed

+53
-49
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ repos:
8080
- --blank
8181
exclude: src/optimagic/optimization/algo_options.py
8282
- repo: https://github.com/astral-sh/ruff-pre-commit
83-
rev: v0.7.2
83+
rev: v0.9.2
8484
hooks:
8585
# Run the linter.
8686
- id: ruff
@@ -97,7 +97,7 @@ repos:
9797
- pyi
9898
- jupyter
9999
- repo: https://github.com/executablebooks/mdformat
100-
rev: 0.7.18
100+
rev: 0.7.21
101101
hooks:
102102
- id: mdformat
103103
additional_dependencies:
@@ -109,7 +109,7 @@ repos:
109109
- '88'
110110
files: (README\.md)
111111
- repo: https://github.com/executablebooks/mdformat
112-
rev: 0.7.18
112+
rev: 0.7.21
113113
hooks:
114114
- id: mdformat
115115
additional_dependencies:
@@ -121,7 +121,7 @@ repos:
121121
files: (docs/.)
122122
exclude: docs/source/how_to/how_to_specify_algorithm_and_algo_options.md
123123
- repo: https://github.com/kynan/nbstripout
124-
rev: 0.8.0
124+
rev: 0.8.1
125125
hooks:
126126
- id: nbstripout
127127
exclude: |
@@ -132,7 +132,7 @@ repos:
132132
args:
133133
- --drop-empty-cells
134134
- repo: https://github.com/pre-commit/mirrors-mypy
135-
rev: v1.13.0
135+
rev: v1.14.1
136136
hooks:
137137
- id: mypy
138138
files: src|tests

.tools/envs/testenv-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- scipy>=1.2.1 # run, tests
2424
- sqlalchemy # run, tests
2525
- seaborn # dev, tests
26-
- mypy=1.13 # dev, tests
26+
- mypy=1.14.1 # dev, tests
2727
- pyyaml # dev, tests
2828
- jinja2 # dev, tests
2929
- annotated-types # dev, tests

.tools/envs/testenv-numpy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- scipy>=1.2.1 # run, tests
2222
- sqlalchemy # run, tests
2323
- seaborn # dev, tests
24-
- mypy=1.13 # dev, tests
24+
- mypy=1.14.1 # dev, tests
2525
- pyyaml # dev, tests
2626
- jinja2 # dev, tests
2727
- annotated-types # dev, tests

.tools/envs/testenv-others.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- scipy>=1.2.1 # run, tests
2222
- sqlalchemy # run, tests
2323
- seaborn # dev, tests
24-
- mypy=1.13 # dev, tests
24+
- mypy=1.14.1 # dev, tests
2525
- pyyaml # dev, tests
2626
- jinja2 # dev, tests
2727
- annotated-types # dev, tests

.tools/envs/testenv-pandas.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- scipy>=1.2.1 # run, tests
2222
- sqlalchemy # run, tests
2323
- seaborn # dev, tests
24-
- mypy=1.13 # dev, tests
24+
- mypy=1.14.1 # dev, tests
2525
- pyyaml # dev, tests
2626
- jinja2 # dev, tests
2727
- annotated-types # dev, tests

docs/source/development/ep-01-pytrees.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ much complexity by avoiding complex pytrees as inputs and outputs at the same ti
384384
To see this in action, let's look at an example. We repeat the example from the JAX
385385
interface above with the following changes:
386386

387-
1. The 1d numpy array in x\["a"\] is replaced by a DataFrame with `"value"` column
387+
1. The 1d numpy array in x["a"] is replaced by a DataFrame with `"value"` column
388388
1. The "d" entry in the output becomes a Series instead of a 1d numpy array.
389389

390390
```python
@@ -460,7 +460,7 @@ very first jacobian:
460460
+--------+----------+----------+----------+----------+----------+----------+----------+
461461
```
462462

463-
The indices \["j", "k", "l", "m"\] unfortunately never made it into the result because
463+
The indices ["j", "k", "l", "m"] unfortunately never made it into the result because
464464
they were only applied to elements that already came from a 2d array and thus always
465465
have a 3d Jacobian, i.e. the result entry `["c"][b"]` is a reshaped version of the upper
466466
right 2 by 4 array and the result entry `["d"]["b"]` is a reshaped version of the lower

docs/source/how_to/how_to_scaling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ these considerations are typically tighter than for parameters that have a small
9090
on the objective function.
9191

9292
Thus, a natural approach to improve the scaling of the optimization problem is to re-map
93-
all parameters such that the bounds are \[0, 1\] for all parameters. This has the
93+
all parameters such that the bounds are [0, 1] for all parameters. This has the
9494
additional advantage that absolute and relative convergence criteria on parameter
9595
changes become the same.
9696

@@ -164,7 +164,7 @@ to a strictly non-zero number for the `"start_values"` and `"gradient"` approach
164164
`"bounds"` approach avoids division by exact zeros by construction. The
165165
`"clipping_value"` can still be used to avoid extreme upscaling of parameters with very
166166
tight bounds. However, this means that the bounds of the re-scaled problem are not
167-
exactly \[0, 1\] for all parameters.
167+
exactly [0, 1] for all parameters.
168168

169169
(scaling-default-values)=
170170

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies:
3131
- sphinx-panels # docs
3232
- sphinxcontrib-bibtex # docs
3333
- seaborn # dev, tests
34-
- mypy=1.13 # dev, tests
34+
- mypy=1.14.1 # dev, tests
3535
- pyyaml # dev, tests
3636
- jinja2 # dev, tests
3737
- furo # dev, docs

src/optimagic/differentiation/derivatives.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def first_derivative(
328328
f0 = np.array(f0, dtype=np.float64)
329329

330330
# convert the raw evaluations to numpy arrays
331-
raw_evals = _convert_evals_to_numpy(
331+
raw_evals_arr = _convert_evals_to_numpy(
332332
raw_evals=raw_evals,
333333
unpacker=unpacker,
334334
registry=registry,
@@ -337,9 +337,9 @@ def first_derivative(
337337
)
338338

339339
# apply finite difference formulae
340-
evals_data = np.array(raw_evals).reshape(2, n_steps, len(x), -1)
341-
evals_data = np.transpose(evals_data, axes=(0, 1, 3, 2))
342-
evals = Evals(pos=evals_data[0], neg=evals_data[1])
340+
evals_data = np.array(raw_evals_arr).reshape(2, n_steps, len(x), -1)
341+
evals_data_transposed = np.transpose(evals_data, axes=(0, 1, 3, 2))
342+
evals = Evals(pos=evals_data_transposed[0], neg=evals_data_transposed[1])
343343

344344
jac_candidates = {}
345345
for m in ["forward", "backward", "central"]:

src/optimagic/differentiation/generate_steps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def generate_steps(
9090
)
9191
min_steps = base_steps if min_steps is None else min_steps
9292

93-
assert (
94-
bounds.upper - bounds.lower >= 2 * min_steps
95-
).all(), "min_steps is too large to fit into bounds."
93+
assert (bounds.upper - bounds.lower >= 2 * min_steps).all(), (
94+
"min_steps is too large to fit into bounds."
95+
)
9696

9797
upper_step_bounds = bounds.upper - x
9898
lower_step_bounds = bounds.lower - x

src/optimagic/differentiation/richardson_extrapolation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def richardson_extrapolation(sequence, steps, method="central", num_terms=None):
5252
n_steps = steps.shape[0]
5353
num_terms = n_steps if num_terms is None else num_terms
5454

55-
assert (
56-
seq_len == n_steps
57-
), "Length of ``steps`` must coincide with length of ``sequence``."
55+
assert seq_len == n_steps, (
56+
"Length of ``steps`` must coincide with length of ``sequence``."
57+
)
5858
assert num_terms > 0, "``num_terms`` must be greater than zero."
59-
assert (
60-
seq_len - 1 >= num_terms
61-
), "``num_terms`` cannot be greater than ``seq_len`` - 1."
59+
assert seq_len - 1 >= num_terms, (
60+
"``num_terms`` cannot be greater than ``seq_len`` - 1."
61+
)
6262

6363
step_ratio = _compute_step_ratio(steps)
6464
order, exponentiation_step = _get_order_and_exponentiation_step(method)

src/optimagic/examples/criterion_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def rosenbrock_gradient(params: PyTree) -> PyTree:
114114
l4 = np.delete(x, [0])
115115
l4 = np.append(l4, 0)
116116
l5 = np.full((len(x) - 1), 2)
117-
l5 = np.append(l5, 0)
117+
l5 = np.append(l5, 0) # type: ignore[assignment]
118118
flat = 100 * (4 * (l1**3) + 2 * l2 - 2 * (l3**2) - 4 * (l4 * x)) + 2 * l1 - l5
119119
return _unflatten_gradient(flat, params)
120120

src/optimagic/logging/logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ def _build_history_dataframe(self) -> pd.DataFrame:
187187

188188
times = np.array(history["time"])
189189
times -= times[0]
190-
history["time"] = times.tolist()
190+
# For numpy arrays with ndim = 0, tolist() returns a scalar, which violates the
191+
# type hinting list[Any] from above. As history["time"] is always a list, this
192+
# case is safe to ignore.
193+
history["time"] = times.tolist() # type: ignore[assignment]
191194

192195
df = pd.DataFrame(history)
193196
df = df.merge(

src/optimagic/optimization/multistart.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ def run_explorations(
313313
314314
"""
315315
internal_problem = internal_problem.with_step_id(step_id)
316-
x_list = list(sample)
316+
x_list: list[NDArray[np.float64]] = list(sample)
317317

318-
raw_values = np.array(internal_problem.exploration_fun(x_list, n_cores=n_cores))
318+
raw_values = np.asarray(
319+
internal_problem.exploration_fun(x_list, n_cores=n_cores), dtype=np.float64
320+
)
319321

320322
is_valid = np.isfinite(raw_values)
321323

src/optimagic/optimization/optimize_result.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ def __repr__(self) -> str:
173173

174174
if self.start_fun is not None and self.fun is not None:
175175
improvement = (
176-
f"The value of criterion improved from {self.start_fun} to "
177-
f"{self.fun}."
176+
f"The value of criterion improved from {self.start_fun} to {self.fun}."
178177
)
179178
else:
180179
improvement = None

src/optimagic/optimizers/nag_optimizers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,9 @@ def _build_options_dict(user_input, default_options):
10511051
invalid = [x for x in user_input if x not in full_options]
10521052
if len(invalid) > 0:
10531053
raise ValueError(
1054-
f"You specified illegal options {', '.join(invalid)}. Allowed are: "
1055-
", ".join(full_options.keys())
1054+
f"You specified illegal options {', '.join(invalid)}. Allowed are: , ".join(
1055+
full_options.keys()
1056+
)
10561057
)
10571058
full_options.update(user_input)
10581059
return full_options

src/optimagic/optimizers/scipy_optimizers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,7 @@ def _solve_internal_problem(
799799
)
800800
raw_res = scipy.optimize.brute(
801801
func=problem.fun,
802-
ranges=tuple(
803-
map(
804-
tuple, np.column_stack((problem.bounds.lower, problem.bounds.upper))
805-
)
806-
),
802+
ranges=tuple(zip(problem.bounds.lower, problem.bounds.upper, strict=True)),
807803
Ns=self.n_grid_points,
808804
full_output=True,
809805
finish=self.polishing_function,

src/optimagic/parameters/consolidate_constraints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ def _consolidate_fixes_with_equality_constraints(
205205
for eq in equality_constraints:
206206
if np.isfinite(fixed_value[eq["index"]]).any():
207207
valcounts = _unique_values(fixed_value[eq["index"]])
208-
assert (
209-
len(valcounts) == 1
210-
), "Equality constrained parameters cannot be fixed to different values."
208+
assert len(valcounts) == 1, (
209+
"Equality constrained parameters cannot be fixed to different values."
210+
)
211211
fixed_value[eq["index"]] = valcounts[0]
212212

213213
return fixed_value

tests/estimagic/test_bootstrap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@ def test_bootstrap_existing_outcomes(setup):
123123
result = bootstrap(
124124
data=setup["df"],
125125
outcome=_outcome_func,
126-
n_draws=2,
126+
n_draws=3,
127127
)
128-
assert len(result.outcomes) == 2
128+
assert len(result.outcomes) == 3
129129
result = bootstrap(
130130
outcome=_outcome_func,
131131
data=setup["df"],
132132
existing_result=result,
133-
n_draws=1,
133+
n_draws=2,
134134
)
135-
assert len(result.outcomes) == 1
135+
assert len(result.outcomes) == 2
136136

137137

138138
def test_bootstrap_from_outcomes(setup, expected):

tests/estimagic/test_estimation_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def test_get_model_names():
395395
def test_get_default_column_names_and_groups():
396396
model_names = ["a_name", "a_name", "(3)", "(4)", "third_name"]
397397
res_names, res_groups = _get_default_column_names_and_groups(model_names)
398-
exp_names = [f"({i+1})" for i in range(len(model_names))]
398+
exp_names = [f"({i + 1})" for i in range(len(model_names))]
399399
exp_groups = ["a_name", "a_name", "(3)", "(4)", "third_name"]
400400
assert res_names == exp_names
401401
assert res_groups == exp_groups

tests/optimagic/optimization/test_with_constraints.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ def test_three_independent_constraints():
244244
)
245245
expected = np.array([0] * 4 + [4, 5] + [0] + [7.5] * 2 + [0])
246246

247-
aaae(res.params, expected, decimal=4)
247+
# TODO: Increase precision back to decimal=4. The reduced precision is likely due
248+
# to the re-written L-BFGS-B algorithm in SciPy 1.15.
249+
# See https://github.com/optimagic-dev/optimagic/issues/556.
250+
aaae(res.params, expected, decimal=3)
248251

249252

250253
INVALID_CONSTRAINT_COMBIS = [

0 commit comments

Comments
 (0)