Skip to content

Keep ensemble defaults unchanged when a component rejects an observation #2198

Closed

Description

@coderabbitai

Summary

On main, EnsemblePosterior.set_default_x() in sbi/inference/posteriors/ensemble_posterior.py can partially update the ensemble when a later component rejects the new observation. The ensemble validates using the first component's event shape, assigns its own default, and then updates each component in order. A successful component update also clears its cached MAP.

Example

Use an ensemble whose first component has an unknown observation event shape and whose later direct component expects event shape (1, 2). Set a valid default with shape (1, 1, 2), then try to set a tensor with shape (2, 2). The ensemble and first component accept the new tensor, but the later component rejects its shape. The ensemble and earlier component retain the rejected default, and later calls without an explicit x can fail.

Required change

Validate the proposed default for every component before changing any default or invalidating caches. Preserve the existing defaults and caches if any component rejects the observation.

Acceptance criteria

  • Add a regression test for a later component rejecting an observation that the ensemble and an earlier component accept.
  • After the rejection, assert that the ensemble and all component defaults and existing caches remain unchanged.
  • Confirm that a valid observation still updates all defaults and performs the appropriate cache invalidation.

Reported during pull request #2193: #2193
Review comment: #2193 (comment)
Requested by @BHARATH0153.

Activity

  1. janfb commented on Nov 19, 2026

    @janfb
    Contributor

    @BHARATH0153 thanks, I can confirm this on main: after a rejected set_default_x(), the ensemble and its first component keep the new x, and later calls without x fail.

    The cause is the same as in issue #2199: the ensemble checks x against the shape of its first component only. Checking the shapes of all components when the ensemble is built fixes both issues, see my comment there.

    Please add the fix to PR #2193. We will review it next week.

    thanks, Jan

  2. BHARATH0153 commented on Nov 19, 2026

    @BHARATH0153
    Contributor

    done in PR #2193 EnsemblePosterior.set_default_x() now validates the proposed observation with every component via _process_x() before mutating any default or clearing a MAP cache, so a rejection leaves the ensemble and all components unchanged. A valid observation still updates all defaults and clears the caches. The shared build-time shape resolution from #2199 prevents this mismatch at the ensemble boundary. Added fast regression tests for the rejected default, unchanged defaults/caches, and the valid update.

  3. BHARATH0153 commented on Nov 20, 2026

    @BHARATH0153
    Contributor

    fixed in #2193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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