process_simulator misreads batched simulators with one output per simulation, and hides their errors
Maintainers usually reply within 6 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Domain
- machine-learning
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sbi-dev/sbi
-
simulate_for_sbi(num_simulations=0) returns 1D empty theta/x tensors and breaks append_simulationsOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sbi-dev/sbi#2310 · 3 comments ·
Maintainers usually reply within 6 days
-
bug: RestrictionEstimator.train(subsample_invalid_sims="auto") raises TypeErrorPossibly taken @Nitesh780 claimed this 2 days ago. Openbug
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
sbi-dev/sbi#2309 · 1 comment ·
Maintainers usually reply within 6 days
-
TARP reference sampling fails when a parameter coordinate is fixedPossibly taken @Jayant-kernel claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
sbi-dev/sbi#2264 · 2 comments ·
Maintainers usually reply within 6 days
-
fix: broadcast UniformNormalConvolution batch shapePossibly taken @studentarijitpaul claimed this 32 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
sbi-dev/sbi#2151 · 2 comments ·
Maintainers usually reply within 6 days
-
bug
sbi-dev/sbi#2321 · 1 comment ·
Maintainers usually reply within 6 days
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day