Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove deprecated x_shape where not needed. #1271

Merged
merged 1 commit into from
Sep 11, 2024
Merged

Conversation

janfb
Copy link
Contributor

@janfb janfb commented Sep 6, 2024

x_shape as argument to posteriors is deprecated. We still have for backwards compatibility in some posteriors.

However, we don't need it in the new posteriors. We can also remove it in some internal uses - which is done in this PR.

@janfb janfb requested a review from gmoss13 September 6, 2024 05:20
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.27%. Comparing base (8afd985) to head (3c6d680).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1271      +/-   ##
==========================================
- Coverage   86.05%   78.27%   -7.79%     
==========================================
  Files         118      119       +1     
  Lines        8672     8695      +23     
==========================================
- Hits         7463     6806     -657     
- Misses       1209     1889     +680     
Flag Coverage Δ
unittests 78.27% <ø> (-7.79%) ⬇️

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

Files with missing lines Coverage Δ
sbi/inference/posteriors/ensemble_posterior.py 50.00% <ø> (-37.97%) ⬇️
sbi/inference/trainers/fmpe/fmpe.py 94.28% <ø> (-0.06%) ⬇️
sbi/inference/trainers/npse/npse.py 96.45% <ø> (-0.03%) ⬇️
sbi/inference/trainers/nre/nre_base.py 94.44% <ø> (-0.06%) ⬇️

... and 29 files with indirect coverage changes

Copy link
Contributor

@gmoss13 gmoss13 left a comment

Choose a reason for hiding this comment

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

Thanks @janfb! I think it's a good idea, but was hoping you could clarify why we remove the x_shape argument from, e.g. NRE or ensemble_posterior, which are not new?

@janfb
Copy link
Contributor Author

janfb commented Sep 9, 2024

Thanks @janfb! I think it's a good idea, but was hoping you could clarify why we remove the x_shape argument from, e.g. NRE or ensemble_posterior, which are not new?

I agree, we should not remove it from the ensemble posterior init.

I think it's fine to remove from NRE because it is used there only internally, i.e., it is set but then not used.

@@ -96,7 +96,6 @@ def __init__(
potential_fn=potential_fn,
theta_transform=theta_transform,
device=device,
x_shape=None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is passed as None explicitly here, i.e., the x_shape argument was not added to the user-facing constructor in the first place.
Thus I think it's fine to remove it here.

@@ -203,7 +202,6 @@ def train(
theta[self.train_indices].to("cpu"),
x[self.train_indices].to("cpu"),
)
self._x_shape = x_shape_from_simulation(x.to("cpu"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

self._x_shape is not used internally anymore, so it's safe to remove it here.

Copy link
Contributor Author

@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.

@gmoss13 I added explanations in comments. What do you think?

@gmoss13 gmoss13 self-requested a review September 11, 2024 15:45
Copy link
Contributor

@gmoss13 gmoss13 left a comment

Choose a reason for hiding this comment

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

Okay, thanks for clarifying! I agree with your comments

@janfb janfb merged commit 299854e into main Sep 11, 2024
6 checks passed
@janfb janfb deleted the remove-x-shape branch September 11, 2024 15:49
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.

None yet

2 participants