Repository: simpeg/simpeg
Pull request #1370 (2024-03-06 00:03:50)

Remove the debug argument from InversionDirective
#### Summary
<!-- Add a summary of this Pull Request -->

Remove the `debug` argument and property from `InversionDirective`, add new test to check if it raises an error when passing it as argument. Update directive class using the `debug` property.

#### 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 for https://github.com/simpeg/simpeg/issues/1302

#### What does this implement/fix?
<!--Please explain your changes.-->

#### Additional information
<!--Any additional information you think is important.-->

Most of these changes were cherry-picked from https://github.com/simpeg/simpeg/pull/1306

<!--
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/1370?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) Report
Attention: Patch coverage is `50.00000%` with `2 lines` in your changes are missing coverage. Please review.
> Project coverage is 21.00%. Comparing base [(`bae455a`)](https://app.codecov.io/gh/simpeg/simpeg/commit/bae455a9b10aba6fd32074c60e96d32410495fbe?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) to head [(`8400e46`)](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg).

| [Files](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) | Patch % | Lines |
|---|---|---|
| [SimPEG/directives/directives.py](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg#diff-U2ltUEVHL2RpcmVjdGl2ZXMvZGlyZWN0aXZlcy5weQ==) | 66.66% | [1 Missing :warning: ](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) |
| [SimPEG/directives/sim\_directives.py](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg#diff-U2ltUEVHL2RpcmVjdGl2ZXMvc2ltX2RpcmVjdGl2ZXMucHk=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) |

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


```diff
@@             Coverage Diff             @@
##             main    #1370       +/-   ##
===========================================
- Coverage   82.31%   21.00%   -61.32%     
===========================================
  Files         165      165               
  Lines       25251    25250        -1     
===========================================
- Hits        20785     5303    -15482     
- Misses       4466    19947    +15481     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/simpeg/simpeg/pull/1370?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).

jcapriot: The random number generator in the tests is rather annoying, I feel like we really need to get support for numpy's generator objects in to all of the tests soon, just so we don't keep having this problem...
santisoler: It is annoying: #1289

Patch:
diff --git a/SimPEG/directives/directives.py b/SimPEG/directives/directives.py
index 23addd789..1f0f3e41e 100644
--- a/SimPEG/directives/directives.py
+++ b/SimPEG/directives/directives.py
@@ -64,14 +64,13 @@ class InversionDirective:
     _dmisfitPair = [BaseDataMisfit, ComboObjectiveFunction]
 
     def __init__(self, inversion=None, dmisfit=None, reg=None, verbose=False, **kwargs):
+        # Raise error on deprecated arguments
+        if (key := "debug") in kwargs.keys():
+            raise TypeError(f"'{key}' property has been removed. Please use 'verbose'.")
         self.inversion = inversion
         self.dmisfit = dmisfit
         self.reg = reg
-        debug = kwargs.pop("debug", None)
-        if debug is not None:
-            self.debug = debug
-        else:
-            self.verbose = verbose
+        self.verbose = verbose
         set_kwargs(self, **kwargs)
 
     @property
@@ -89,7 +88,7 @@ class InversionDirective:
         self._verbose = validate_type("verbose", value, bool)
 
     debug = deprecate_property(
-        verbose, "debug", "verbose", removal_version="0.19.0", future_warn=True
+        verbose, "debug", "verbose", removal_version="0.19.0", error=True
     )
 
     @property
diff --git a/SimPEG/directives/sim_directives.py b/SimPEG/directives/sim_directives.py
index 718fac26c..0a3464717 100644
--- a/SimPEG/directives/sim_directives.py
+++ b/SimPEG/directives/sim_directives.py
@@ -248,7 +248,7 @@ class PairedBetaEstimate_ByEig(InversionDirective):
         if self.seed is not None:
             np.random.seed(self.seed)
 
-        if self.debug:
+        if self.verbose:
             print("Calculating the beta0 parameter.")
 
         m = self.invProb.model


Test patch:
diff --git a/tests/base/test_directives.py b/tests/base/test_directives.py
index e4857d08f..0d2f2f105 100644
--- a/tests/base/test_directives.py
+++ b/tests/base/test_directives.py
@@ -294,6 +294,20 @@ def test_save_output_dict(RegClass):
         assert "x SparseSmoothness.norm" in out_dict
 
 
+class TestDeprecatedArguments:
+    """
+    Test if directives raise errors after passing deprecated arguments.
+    """
+
+    def test_debug(self):
+        """
+        Test if InversionDirective raises error after passing 'debug'.
+        """
+        msg = "'debug' property has been removed. Please use 'verbose'."
+        with pytest.raises(TypeError, match=msg):
+            directives.InversionDirective(debug=True)
+
+
 class TestUpdateSensitivityWeightsRemovedArgs:
     """
     Test if `UpdateSensitivityWeights` raises errors after passing removed arguments.