Skip to content

stack_scan_sensitivities: numpy.stack raises 'all input arrays must have the same shape' on a parameter_scan, aborting the gradient fit #525

Description

@wshlavacek

A gradient (trf) fit of a job containing a type: parameter_scan experiment aborts while combining the per-dose sensitivity arrays:

File "pybnf/bngsim_model/net_model.py", line 447,  in execute
File "pybnf/bngsim_model/net_model.py", line 661,  in _execute_actions
File "pybnf/bngsim_model/net_model.py", line 1192, in _run_parameter_scan
File "pybnf/data.py",                    line 86,  in stack_scan_sensitivities
File "numpy/_core/shape_base.py",        line 458, in stack
    raise ValueError('all input arrays must have the same shape')

pybnf.printing.PybnfError: Model egfr_simpull: simulation failed while computing
forward output sensitivities for gradient-based fitting. The model may use
discrete events or otherwise non-differentiable constructs.

The failure is entirely inside PyBNF: bngsim returned the per-point tensors and stack_scan_sensitivities could not combine them. numpy.stack requires exact shape agreement, so some dose in the scan produced a sensitivity array of a different shape from the others.

Reproducer

Salazar-Cavazos-2019/egfr_simpull from the PyBNF jobs collection, with the committed config switched to the gradient path:

job_type = trf
n_starts = 10
bngl_backend = bngsim

The job has two experiments — one type: parameter_scan, t_end: 300 and one plain time course:

experiment: dose_resp, type: parameter_scan, t_end: 300, data: dose_resp.exp
experiment: egf25nm, data: EGF_25nM.exp

Fails after ~11 s, before completing a single start.

Note on the wrapper message

The PybnfError blames "discrete events or otherwise non-differentiable constructs", which sent me looking at the model first. This model has no events — the cause is a shape mismatch in PyBNF's own stacking. Worth either narrowing that message or letting a ValueError from stack_scan_sensitivities surface with its own explanation, since the current text points at the wrong layer.

Suggested direction

Whatever stack_scan_sensitivities receives, the per-dose arrays are not uniform — most likely differing timepoint counts across scan points, or a mismatch between the scan experiment's grid and the plain time-course experiment's. Reporting the offending shapes (dose index, expected vs actual) before stacking would make this diagnosable from the log rather than from a numpy traceback.

Environment

PyBNF 1.6.0, bngsim 0.11.35 (v0.11.35-77-g32395e4), Python 3.12, macOS 15.

Related: this is one of two gradient-path failures I hit on parameter_scan experiments; the other is lanl/bngsim#81 (a scored scan after a pre-equilibration is refused outright).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions