Test set x deprecation - #1946
Conversation
- Add bind() method to BasePotential (abstract) and CustomPotentialWrapper - Add bind() to LikelihoodBasedPotential, PosteriorBasedPotential, RatioBasedPotential - Add bind() to VectorFieldBasedPotential with full parameter support - Add bind() to EnsemblePotential in ensemble_posterior.py - Add bind() to ConditionedPotential in conditional_density_utils.py - Fix _base_recursor to use local variable _active_holder to avoid Python scoping issues with the _active parameter - Update posteriors to use bind() instead of set_x() for immutability - Fix PytorchReturnTypeWrapper, MultipleIndependent, OneDimPriorWrapper init order and add __deepcopy__ methods for proper deepcopy support - Update error messages to reference bind() instead of set_x() - Add bind() to test FakePotential and TractablePotential classes
- Add bind() method to BasePotential (abstract) and CustomPotentialWrapper - Add bind() to LikelihoodBasedPotential, PosteriorBasedPotential, RatioBasedPotential - Add bind() to VectorFieldBasedPotential with full parameter support - Add bind() to EnsemblePotential in ensemble_posterior.py - Add bind() to ConditionedPotential in conditional_density_utils.py - Fix _base_recursor to use local variable _active_holder to avoid Python scoping issues with the _active parameter - Update posteriors to use bind() instead of set_x() for immutability - Fix PytorchReturnTypeWrapper, MultipleIndependent, OneDimPriorWrapper init order and add __deepcopy__ methods for proper deepcopy support - Update error messages to reference bind() instead of set_x() - Add bind() to test FakePotential and TractablePotential classes - Replace remaining set_x calls in VectorFieldPosterior with bind
…d set_x inside vi_divergence; remove set_x usage inside bind()
…ibute 'guidance_method'
…ull version of it
|
Great this all works now :) Next I will move over the tests that use set_x to bind so deleting set_x will not break any tests. |
Resolved conflicts: - potentials: keep HEAD (direct attribute set in bind) - conditional_density_utils.py: keep HEAD (deprecation in set_x) + upstream (_x_is_iid fix) - test files: keep HEAD (direct attribute set in bind) Fixed duplicate bind() methods in vector_field_potential.py and ensemble_posterior.py
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## gsoc-2026 #1946 +/- ##
=============================================
- Coverage 87.99% 87.83% -0.17%
=============================================
Files 144 144
Lines 13499 13759 +260
=============================================
+ Hits 11879 12085 +206
- Misses 1620 1674 +54
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
|
||
| DEPRECATED: Use bind() instead. This method delegates to bind() internally. | ||
| """ | ||
| import warnings |
| import warnings | ||
|
|
||
| warnings.warn( | ||
| "set_x() is deprecated, use bind() instead", |
There was a problem hiding this comment.
check other deprecation statements in the toolbox. Probably we want to add something saying that it will be removed in the future.
|
|
||
| def bind(self, x_o: Tensor, x_is_iid: bool = False) -> "PosteriorBasedPotential": | ||
| """Create new potential with x bound, without mutable state.""" | ||
| from sbi.utils.user_input_checks import process_x |
| import warnings | ||
|
|
||
| warnings.warn( | ||
| "set_x() is deprecated, use bind() instead", |
There was a problem hiding this comment.
same comments as on the last PR. Please merge first
|
|
||
| def bind(self, x_o: torch.Tensor, x_is_iid: bool = True) -> "FakePotential": | ||
| """Create new potential with x bound, without mutable state.""" | ||
| from sbi.utils.user_input_checks import process_x |
| self, x_o: torch.Tensor, x_is_iid: bool = True | ||
| ) -> "TractablePotential": | ||
| """Create new potential with x bound, without mutable state.""" | ||
| from sbi.utils.user_input_checks import process_x |
…_method for VectorFieldBasedPotential;
| DEPRECATED: Use bind() instead. This method delegates to bind() internally. | ||
| It will be removed in a future release. | ||
| """ | ||
| import warnings |
There was a problem hiding this comment.
Not yet addressed. If you decide against it, please let me know why or resolve the comment
There was a problem hiding this comment.
ah sorry, I overlooked that.
| self.flow = self.rebuild_flow(**ode_kwargs) | ||
| elif self._x_o is not None: | ||
| self.flows = self.rebuild_flows_for_batch(**ode_kwargs) | ||
| import warnings |
| self.prior = prior | ||
| self.device = None | ||
| self.return_type = return_type |
There was a problem hiding this comment.
Why was that moved from like 10 lines lower?
There was a problem hiding this comment.
the line super().init(...) below had strange side effects with the new bind definition. Moving it before that fixed it.
This PR continue #1945 it was about making bind independent of set_x. This one prepares deprecation of set_x by 'flipping its role with bind'. By that I mean the following: in #1943 I used set_x inside bind, to build a stateless version of set_x. In #1945 I made them independent and here I will write set_x in a way that it uses bind internally. This way deleting set_x will be trivially safe.