Skip to content

Make ensemble observation shape independent of component order #2199

Closed

Description

@coderabbitai

Problem

On main, EnsemblePotential.x_event_shape in sbi/inference/posteriors/ensemble_posterior.py uses only the first component potential's event shape. This makes observation processing depend on component order.

For example, put a custom potential whose x_event_shape is None first and a direct posterior whose condition shape is (2, 3) second. process_x() leaves one (2, 3) observation two-dimensional, and EnsemblePosterior.sample() interprets its leading dimension as two observations and rejects it. Reversing the components gives the ensemble a known event shape, so process_x() adds a batch dimension and the ensemble's observation-count check accepts it.

Requested change

Resolve the ensemble event shape from all declared component event shapes. Use the agreed known shape when other components have an unknown shape, and report an explicit error when known shapes conflict. Preserve the existing unknown-shape behavior when no component declares a shape.

Acceptance criteria

  • A single (2, 3) observation is treated as one observation regardless of whether the component with unknown shape comes first or second.
  • Conflicting known component event shapes produce an explicit error.
  • Add regression tests for both component orders, conflicting known shapes, and all-unknown shapes.

This is a follow-up to review of PR #2193, not a change requested in that PR. Requested by @BHARATH0153.

PR: #2193
Review comment: #2193 (comment)

Activity

  1. BHARATH0153 commented on Nov 19, 2026

    @BHARATH0153
    Contributor

    @coderabbitai please close it for now

  2. coderabbitai commented on Nov 19, 2026

    @coderabbitai
    Author
    Analysis chain

    Script executed:

    #!/bin/bash
    set -euo pipefail
    
    repo="sbi-dev/sbi"
    number="2199"
    requester="BHARATH0153"
    
    echo "Checking issue:"
    issue=$(gh api "repos/$repo/issues/$number")
    printf '%s\n' "$issue" | jq '{number, state, state_reason, html_url, is_pull_request: has("pull_request")}'
    if [ "$(printf '%s\n' "$issue" | jq -r 'has("pull_request")')" = "true" ]; then
      echo "Target is a pull request, not an issue; no action taken."
      exit 1
    fi
    if [ "$(printf '%s\n' "$issue" | jq -r '.state')" = "closed" ]; then
      echo "Issue is already closed; no action needed."
      exit 0
    fi
    
    echo "Checking requester repository permission:"
    permission=$(gh api "repos/$repo/collaborators/$requester/permission")
    printf '%s\n' "$permission" | jq '{permission, role_name, user: .user.login}'
    level=$(printf '%s\n' "$permission" | jq -r '.permission')
    role=$(printf '%s\n' "$permission" | jq -r '.role_name // ""')
    if [[ "$level" != "admin" && "$level" != "write" && "$level" != "maintain" && "$role" != "admin" && "$role" != "write" && "$role" != "maintain" ]]; then
      echo "Requester write permission could not be established; no action taken."
      exit 1
    fi
    
    gh issue close "$number" --repo "$repo"
    gh api "repos/$repo/issues/$number" --jq '{number, state, state_reason, html_url}'

    Length of output: 1909


    @BHARATH0153 Your repository permission is read-only, so I could not close #2199. A repository member with write access can close it.

    You are interacting with an AI system.

  3. janfb commented on Nov 19, 2026

    @janfb
    Contributor

    @BHARATH0153 thanks, I can confirm this on main: with a custom potential first, a single (2, 3) observation is rejected as two observations; with the direct posterior first, it passes.

    An ensemble should have exactly one observation shape. So please check the shapes when the ensemble is built: take the shape its components declare, skip components with an unknown shape, and raise if two known shapes differ. Batching then stays in the existing x processing.

    This also fixes issue #2198: no component can then reject an x that the ensemble accepted.

    Please add the fix for both issues to PR #2193 instead of opening a new PR. Small fast tests are enough: both component orders, conflicting shapes, and a rejected x that leaves the old default in place.

    We will review PR #2193 next week.

    thanks, Jan

  4. BHARATH0153 commented on Nov 19, 2026

    @BHARATH0153
    Contributor

    done in PR #2193 (commit 7e10777), superseding my earlier no-need comment. EnsemblePotential now resolves x_event_shape from all components at build time: components with an unknown shape are skipped, known shapes must agree, and conflicting known shapes raise a ValueError. When no component declares a shape, the previous unknown-shape behavior is preserved. Batching stays in the existing x processing. Added fast tests for both component orders, conflicting shapes, and all-unknown shapes. The set_default_x() atomicity fix for #2198 is in the same PR.

  5. BHARATH0153 commented on Nov 20, 2026

    @BHARATH0153
    Contributor

    #2193 fixed in

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