Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HierarchicalAmiciCalculator.__call__ missing 'hess' in returned dict upon simulation failure #1160

Closed
dweindl opened this issue Oct 30, 2023 · 0 comments · Fixed by #1161
Closed
Assignees
Labels
bug Something isn't working fixed but not released hierarchical Related to hierarchical optimization

Comments

@dweindl
Copy link
Member

dweindl commented Oct 30, 2023

I finally got to the bottom of #1147

The problem is that in case of simulation failures HierarchicalAmiciCalculator.__call__ does not set inner_result[HESS] here, although the Hessian was requested:

# if any amici simulation failed, it's unlikely we can compute
# meaningful inner parameters, so we better just fail early.
if any(rdata.status != amici.AMICI_SUCCESS for rdata in inner_rdatas):
# if the gradient was requested, we need to provide some value
# for it
if 1 in sensi_orders:
inner_result[GRAD] = np.full(
shape=len(x_ids), fill_value=np.nan
)
return inner_result

This results in the following error:

  File "pypesto/optimize/task.py", line 59, in execute
    optimizer_result = self.optimizer.minimize(
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "pypesto/optimize/optimizer.py", line 167, in wrapped_minimize
    result = minimize(
             ^^^^^^^^^
  File "pypesto/optimize/optimizer.py", line 136, in wrapped_minimize
    result = minimize(
             ^^^^^^^^^
  File "pypesto/optimize/optimizer.py", line 83, in wrapped_minimize
    result = minimize(
             ^^^^^^^^^
  File "pypesto/optimize/optimizer.py", line 1342, in minimize
    opt.minimize(x0)
  File "fides/minimize.py", line 333, in minimize
    funout_new = self.fevaler(x_new)
                 ^^^^^^^^^^^^^^^^^^^
  File "fides/minimize.py", line 40, in __call__
    ret = self.fun(x, **self.funargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pypesto/objective/amici/amici.py", line 395, in __call__
    return super().__call__(x, sensi_orders, mode, return_dict, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pypesto/objective/base.py", line 197, in __call__
    result = ObjectiveBase.output_to_tuple(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pypesto/objective/base.py", line 334, in output_to_tuple
    output += (kwargs[HESS],)
               ~~~~~~^^^^^^
KeyError: 'hess'
@dweindl dweindl added the bug Something isn't working label Oct 30, 2023
@dweindl dweindl self-assigned this Oct 30, 2023
dweindl added a commit that referenced this issue Oct 30, 2023
…t upon simulation failure

`HierarchicalAmiciCalculator.__call__` needs to set `'hess'` in the result dict, also in case of simulation failures.

Closes #1160
@dweindl dweindl added the hierarchical Related to hierarchical optimization label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed but not released hierarchical Related to hierarchical optimization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants