|
21 | 21 | from optimagic.parameters.block_trees import hessian_to_block_tree, matrix_to_block_tree |
22 | 22 | from optimagic.parameters.bounds import Bounds, get_internal_bounds, pre_process_bounds |
23 | 23 | from optimagic.parameters.tree_registry import ( |
24 | | - extended, |
25 | 24 | tree_flatten, |
26 | 25 | tree_just_flatten, |
27 | 26 | tree_unflatten, |
28 | 27 | ) |
29 | 28 | from optimagic.parameters.tree_registry import tree_just_flatten as tree_leaves |
30 | | -from optimagic.typing import BatchEvaluatorLiteral, PyTree |
| 29 | +from optimagic.typing import BatchEvaluatorLiteral, PyTree, value_namespace |
31 | 30 |
|
32 | 31 |
|
33 | 32 | @dataclass(frozen=True) |
@@ -222,19 +221,23 @@ def first_derivative( |
222 | 221 | is_fast_path = _is_1d_array(params) |
223 | 222 |
|
224 | 223 | if not is_fast_path: |
225 | | - x, params_treedef = tree_flatten(params, namespace=extended) |
| 224 | + x, params_treedef = tree_flatten(params, namespace=value_namespace) |
226 | 225 | x = np.array(x, dtype=np.float64) |
227 | 226 |
|
228 | 227 | if scaling_factor is not None and not np.isscalar(scaling_factor): |
229 | 228 | scaling_factor = np.array( |
230 | | - tree_just_flatten(scaling_factor, namespace=extended) |
| 229 | + tree_just_flatten(scaling_factor, namespace=value_namespace) |
231 | 230 | ) |
232 | 231 |
|
233 | 232 | if min_steps is not None and not np.isscalar(min_steps): |
234 | | - min_steps = np.array(tree_just_flatten(min_steps, namespace=extended)) |
| 233 | + min_steps = np.array( |
| 234 | + tree_just_flatten(min_steps, namespace=value_namespace) |
| 235 | + ) |
235 | 236 |
|
236 | 237 | if step_size is not None and not np.isscalar(step_size): |
237 | | - step_size = np.array(tree_just_flatten(step_size, namespace=extended)) |
| 238 | + step_size = np.array( |
| 239 | + tree_just_flatten(step_size, namespace=value_namespace) |
| 240 | + ) |
238 | 241 | else: |
239 | 242 | x = params.astype(np.float64) |
240 | 243 |
|
@@ -288,7 +291,7 @@ def first_derivative( |
288 | 291 | if not is_fast_path: |
289 | 292 | evaluation_points = [ |
290 | 293 | # entries are either a numpy.ndarray or np.nan |
291 | | - _unflatten_if_not_nan(p, params_treedef, extended) |
| 294 | + _unflatten_if_not_nan(p, params_treedef, value_namespace) |
292 | 295 | for p in evaluation_points |
293 | 296 | ] |
294 | 297 |
|
@@ -327,14 +330,14 @@ def first_derivative( |
327 | 330 | elif vector_out: |
328 | 331 | f0 = f0_tree.astype(float) |
329 | 332 | else: |
330 | | - f0 = tree_leaves(f0_tree, namespace=extended) |
| 333 | + f0 = tree_leaves(f0_tree, namespace=value_namespace) |
331 | 334 | f0 = np.array(f0, dtype=np.float64) |
332 | 335 |
|
333 | 336 | # convert the raw evaluations to numpy arrays |
334 | 337 | raw_evals_arr = _convert_evals_to_numpy( |
335 | 338 | raw_evals=raw_evals, |
336 | 339 | unpacker=unpacker, |
337 | | - namespace=extended, |
| 340 | + namespace=value_namespace, |
338 | 341 | is_scalar_out=scalar_out, |
339 | 342 | is_vector_out=vector_out, |
340 | 343 | ) |
@@ -536,19 +539,23 @@ def second_derivative( |
536 | 539 | is_fast_path = _is_1d_array(params) |
537 | 540 |
|
538 | 541 | if not is_fast_path: |
539 | | - x, params_treedef = tree_flatten(params, namespace=extended) |
| 542 | + x, params_treedef = tree_flatten(params, namespace=value_namespace) |
540 | 543 | x = np.array(x, dtype=np.float64) |
541 | 544 |
|
542 | 545 | if scaling_factor is not None and not np.isscalar(scaling_factor): |
543 | 546 | scaling_factor = np.array( |
544 | | - tree_just_flatten(scaling_factor, namespace=extended) |
| 547 | + tree_just_flatten(scaling_factor, namespace=value_namespace) |
545 | 548 | ) |
546 | 549 |
|
547 | 550 | if min_steps is not None and not np.isscalar(min_steps): |
548 | | - min_steps = np.array(tree_just_flatten(min_steps, namespace=extended)) |
| 551 | + min_steps = np.array( |
| 552 | + tree_just_flatten(min_steps, namespace=value_namespace) |
| 553 | + ) |
549 | 554 |
|
550 | 555 | if step_size is not None and not np.isscalar(step_size): |
551 | | - step_size = np.array(tree_just_flatten(step_size, namespace=extended)) |
| 556 | + step_size = np.array( |
| 557 | + tree_just_flatten(step_size, namespace=value_namespace) |
| 558 | + ) |
552 | 559 | else: |
553 | 560 | x = params.astype(np.float64) |
554 | 561 |
|
@@ -624,7 +631,8 @@ def second_derivative( |
624 | 631 | evaluation_points = { |
625 | 632 | # entries are either a numpy.ndarray or np.nan, we unflatten only |
626 | 633 | step_type: [ |
627 | | - _unflatten_if_not_nan(p, params_treedef, extended) for p in points |
| 634 | + _unflatten_if_not_nan(p, params_treedef, value_namespace) |
| 635 | + for p in points |
628 | 636 | ] |
629 | 637 | for step_type, points in evaluation_points.items() |
630 | 638 | } |
@@ -663,13 +671,13 @@ def second_derivative( |
663 | 671 | func_value = f0 |
664 | 672 |
|
665 | 673 | f0_tree = unpacker(f0) |
666 | | - f0 = tree_leaves(f0_tree, namespace=extended) |
| 674 | + f0 = tree_leaves(f0_tree, namespace=value_namespace) |
667 | 675 | f0 = np.array(f0, dtype=np.float64) |
668 | 676 |
|
669 | 677 | # convert the raw evaluations to numpy arrays |
670 | 678 | raw_evals = { |
671 | 679 | step_type: _convert_evals_to_numpy( |
672 | | - raw_evals=evals, unpacker=unpacker, namespace=extended |
| 680 | + raw_evals=evals, unpacker=unpacker, namespace=value_namespace |
673 | 681 | ) |
674 | 682 | for step_type, evals in raw_evals.items() |
675 | 683 | } |
|
0 commit comments