process_simulator misreads batched simulators with one output per simulation, and hides their errors

Open
#2,292 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@JayBhadoria11 is already working on this.

Since Dec 2, 2026.

  • #2296 by @JayBhadoria11 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python, pytorch

Research direction

Start by reading ensure_batched_simulator in sbi/utils/user_input_checks.py and the simulate_for_sbi handling of one-dimensional outputs. Check the probe at both batch sizes and how it handles simulator exceptions. Done means one output per simulation is accepted with a feature dimension, while unrelated simulator errors reach the user; an open pull request already addresses this issue.

Written by the indexing model from the issue text.

Description

process_simulator treats a batched simulator that returns one number per simulation as non-batched, so simulation then fails with a confusing error.

import torch
from sbi.inference import simulate_for_sbi
from sbi.utils import BoxUniform
from sbi.utils.user_input_checks import process_prior, process_simulator

prior, _, prior_returns_numpy = process_prior(BoxUniform(torch.zeros(3), torch.ones(3)))
simulator = process_simulator(lambda theta: theta.sum(dim=1), prior, prior_returns_numpy)
simulate_for_sbi(simulator, prior, 5)
# IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

ensure_batched_simulator counts a simulator as batched only if its output has at least two dimensions. An output of shape (batch_size,) fails that check, so the simulator gets wrapped in the loop that passes one parameter vector at a time, and theta.sum(dim=1) then fails on a 1D input.

Returning shape (batch_size, 1), for example with keepdim=True, works around it.

The same probe catches every exception, so a real error of a batched simulator also turns into an unrelated error from the loop. For example, lambda theta: torch.fft.fft(theta, dim=1) should raise the TypeError for complex outputs that PR #2224 adds, but raises an IndexError instead.

The fix should accept an output of shape (batch_size,) at both probe sizes as batched, and give it a feature dimension, as simulate_for_sbi already does for 1D outputs. Errors that are not about the batch shape should reach the user.

Dominant language
Python
Stars
894
Forks
306
Avg merge
5d 21h
Merged PRs (30d)
61

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sbi-dev/sbi

All issues in sbi-dev/sbi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.