Skip to content

Conversation

@satwiksps
Copy link
Contributor

Issue Reference

Summary

This PR updates a misleading assertion message in the NPE training workflow. When train() is called a second time with resume_training=False and force_first_round_loss=False, the current message incorrectly states that append_simulations() was called again after training, even when no new simulations were appended. The updated message now reflects the two valid user stories:

  1. No new simulations appended (round 0):
    Users should set resume_training=True to continue training the same neural network.

  2. New simulations appended (multi-round):
    Users must either pass a proposal when calling append_simulations(), or explicitly set force_first_round_loss=True for simulations drawn from the prior.

Changes

  • Updated the assertion message in sbi/inference/trainers/npe/npe_base.py within _get_start_index().
  • No changes were made to the underlying training logic or behavior.

Reproduced Output After Fix

Click to view traceback screenshot Screenshot 2025-11-19 145352

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@2c216c2). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1706   +/-   ##
=======================================
  Coverage        ?   84.65%           
=======================================
  Files           ?      137           
  Lines           ?    11487           
  Branches        ?        0           
=======================================
  Hits            ?     9724           
  Misses          ?     1763           
  Partials        ?        0           
Flag Coverage Δ
unittests 84.65% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sbi/inference/trainers/npe/npe_base.py 93.54% <100.00%> (ø)

Copy link
Contributor

@janfb janfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @satwiksps ! Made one suggestion for the error message and a proposal to change to ValueError.

Comment on lines 615 to 616
"in append_simulations(), or set force_first_round_loss=True for "
"simulations drawn from the prior."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"in append_simulations(), or set force_first_round_loss=True for "
"simulations drawn from the prior."
"in append_simulations(), or set force_first_round_loss=True for "
"simulations drawn from the prior."
"Warning: Setting force_first_round_loss=True with simulations not drawn "
"from the prior will produce the proposal posterior instead of the true "
"posterior, which is typically more narrow."

self._round = max(self._data_round_index)

if self._round == 0 and self._neural_net is not None:
assert context.force_first_round_loss or context.resume_training, (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please exchange this assertion with a boolean check followed by a ValueError with the message below?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect AssertionError message in NPE.train()

2 participants