Repository: simpeg/simpeg
Pull request #1400 (2024-03-28 17:43:05)

Remove mref property of PGI regularization
<!--
Thanks for contributing a pull request to SimPEG!
Remember to use a personal fork of SimPEG to propose changes.

Check out the stages of a pull request at
https://docs.simpeg.xyz/content/getting_started/contributing/pull-requests.html

Note that we are a team of volunteers and we appreciate your
patience during the review process.

Again, thanks for contributing!

Feel free to remove lines from this template that do not apply to you pull request.
-->

#### Summary
<!-- Add a summary of this Pull Request -->

Remove the deprecated `mref` property in the PGI regularization class and add test function checking that error is raised when trying to access it.

#### PR Checklist
* [ ] If this is a work in progress PR, set as a Draft PR
* [ ] Linted my code according to the [style guides](https://docs.simpeg.xyz/content/getting_started/contributing/code-style.html).
* [ ] Added [tests](https://docs.simpeg.xyz/content/getting_started/practices.html#testing) to verify changes to the code.
* [ ] Added necessary documentation to any new functions/classes following the
      expect [style](https://docs.simpeg.xyz/content/getting_started/practices.html#documentation).
* [ ] Marked as ready for review (if this is was a draft PR), and converted
      to a Pull Request
* [ ] Tagged ``@simpeg/simpeg-developers`` when ready for review.

#### Reference issue
<!--Example: write "Closes #NNNN" to automatically close that issue on merge.-->

Part of the solution to #1302

#### What does this implement/fix?
<!--Please explain your changes.-->

#### Additional information
<!--Any additional information you think is important.-->


<!--
Once all tests pass and the code has been reviewed and approved, it will be merged into main
-->


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/simpeg/simpeg/pull/1400?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 46.12%. Comparing base [(`6b9c6ba`)](https://app.codecov.io/gh/simpeg/simpeg/commit/6b9c6baeadc8f35e58f6eb101efd155ba279d402?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) to head [(`9f1650d`)](https://app.codecov.io/gh/simpeg/simpeg/pull/1400?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg).
> Report is 1 commits behind head on main.


<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##             main    #1400       +/-   ##
===========================================
- Coverage   82.31%   46.12%   -36.20%     
===========================================
  Files         165      165               
  Lines       25261    25261               
===========================================
- Hits        20794    11651     -9143     
- Misses       4467    13610     +9143     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/simpeg/simpeg/pull/1400?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg).


Patch:
diff --git a/SimPEG/regularization/pgi.py b/SimPEG/regularization/pgi.py
index 2c98c321f..0a7a371f9 100644
--- a/SimPEG/regularization/pgi.py
+++ b/SimPEG/regularization/pgi.py
@@ -1393,6 +1393,5 @@ class PGI(ComboObjectiveFunction):
         "mref",
         "reference_model",
         "0.19.0",
-        future_warn=True,
-        error=False,
+        error=True,
     )


Test patch:
diff --git a/tests/base/regularizations/test_pgi_regularization.py b/tests/base/regularizations/test_pgi_regularization.py
index 440e50a49..cc0ce5ac9 100644
--- a/tests/base/regularizations/test_pgi_regularization.py
+++ b/tests/base/regularizations/test_pgi_regularization.py
@@ -1,3 +1,4 @@
+import pytest
 import unittest
 
 import discretize
@@ -469,5 +470,19 @@ class TestPGI(unittest.TestCase):
             plt.show()
 
 
+def test_removed_mref():
+    """Test if PGI raises error when accessing removed mref property."""
+    h = [[(2, 2)], [(2, 2)], [(2, 2)]]
+    mesh = discretize.TensorMesh(h)
+    n_components = 1
+    gmm = WeightedGaussianMixture(mesh=mesh, n_components=n_components)
+    samples = np.random.default_rng(seed=42).normal(size=(mesh.n_cells, 2))
+    gmm.fit(samples)
+    pgi = regularization.PGI(mesh=mesh, gmmref=gmm)
+    message = "mref has been removed, please use reference_model."
+    with pytest.raises(NotImplementedError, match=message):
+        pgi.mref
+
+
 if __name__ == "__main__":
     unittest.main()