Repository: simpeg/simpeg
Pull request #1653 (2025-04-24 15:56:21)

Raise NotImplementedError on getJ for NSEM 1D simulations
#### Summary

Overwrite the `getJ` method of the NSEM 1D finite volume simulations so they raise a `NotImplementedError`. Add tests for the new errors.

#### 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/latest/content/getting_started/contributing/code-style.html).
* [ ] Added [tests](https://docs.simpeg.xyz/latest/content/getting_started/contributing/testing.html) to verify changes to the code.
* [ ] Added necessary documentation to any new functions/classes following the
      expect [style](https://docs.simpeg.xyz/latest/content/getting_started/contributing/documentation.html).
* [ ] 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

First step towards addressing #1541.

#### 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/1653?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 86.01%. Comparing base [(`8f5fe30`)](https://app.codecov.io/gh/simpeg/simpeg/commit/8f5fe300f79f924c2b7b6562aa61060e6a4dd079?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=simpeg) to head [(`b4e40f6`)](https://app.codecov.io/gh/simpeg/simpeg/commit/b4e40f660da46f490a3b3e544f1797186ab9482b?dropdown=coverage&el=desc&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    #1653   +/-   ##
=======================================
  Coverage   86.00%   86.01%           
=======================================
  Files         410      411    +1     
  Lines       54217    54250   +33     
  Branches     5106     5106           
=======================================
+ Hits        46630    46661   +31     
- Misses       6170     6171    +1     
- Partials     1417     1418    +1     
```

</details>

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

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>

Patch:
diff --git a/simpeg/electromagnetics/natural_source/simulation.py b/simpeg/electromagnetics/natural_source/simulation.py
index 651a34795..a7cf938a2 100644
--- a/simpeg/electromagnetics/natural_source/simulation.py
+++ b/simpeg/electromagnetics/natural_source/simulation.py
@@ -110,6 +110,23 @@ class Simulation1DElectricField(BaseFDEMSimulation):
             freq, u, v, adjoint
         )
 
+    def getJ(self, m, f=None):
+        r"""Generate the full sensitivity matrix.
+
+        .. important::
+
+            This method hasn't been implemented yet for this class.
+
+        Raises
+        -------
+        NotImplementedError
+        """
+        msg = (
+            "The getJ method hasn't been implemented for the "
+            f"{type(self).__name__} yet."
+        )
+        raise NotImplementedError(msg)
+
 
 class Simulation1DMagneticField(BaseFDEMSimulation):
     """
@@ -172,6 +189,23 @@ class Simulation1DMagneticField(BaseFDEMSimulation):
             freq, u, v, adjoint
         )
 
+    def getJ(self, m, f=None):
+        r"""Generate the full sensitivity matrix.
+
+        .. important::
+
+            This method hasn't been implemented yet for this class.
+
+        Raises
+        -------
+        NotImplementedError
+        """
+        msg = (
+            "The getJ method hasn't been implemented for the "
+            f"{type(self).__name__} yet."
+        )
+        raise NotImplementedError(msg)
+
 
 class Simulation1DPrimarySecondary(Simulation1DElectricField):
     r"""


Test patch:
diff --git a/tests/em/nsem/forward/test_getJ_not_implemented.py b/tests/em/nsem/forward/test_getJ_not_implemented.py
new file mode 100644
index 000000000..0da2a3ee9
--- /dev/null
+++ b/tests/em/nsem/forward/test_getJ_not_implemented.py
@@ -0,0 +1,50 @@
+"""
+Test NotImplementedError on getJ for NSEM 1D finite volume simulations.
+"""
+
+import pytest
+import numpy as np
+import discretize
+from simpeg import maps
+from simpeg.electromagnetics import natural_source as nsem
+
+
+@pytest.fixture
+def mesh():
+    csz = 100
+    nc = 300
+    npad = 30
+    pf = 1.2
+    mesh = discretize.TensorMesh([[(csz, npad, -pf), (csz, nc), (csz, npad)]], "N")
+    mesh.x0 = np.r_[-mesh.h[0][:-npad].sum()]
+    return mesh
+
+
+@pytest.fixture
+def survey():
+    frequencies = np.logspace(-2, 1, 30)
+    receiver = nsem.receivers.Impedance(
+        [[0]], orientation="xy", component="apparent_resistivity"
+    )
+    sources = [nsem.sources.Planewave([receiver], frequency=f) for f in frequencies]
+    survey = nsem.survey.Survey(sources)
+    return survey
+
+
+@pytest.mark.parametrize(
+    "simulation_class", [nsem.Simulation1DElectricField, nsem.Simulation1DMagneticField]
+)
+def test_getJ_not_implemented(mesh, survey, simulation_class):
+    """
+    Test NotImplementedError on getJ for NSEM 1D simulations.
+    """
+    mapping = maps.IdentityMap()
+    simulation = simulation_class(
+        mesh=mesh,
+        survey=survey,
+        sigmaMap=mapping,
+    )
+    model = np.ones(survey.nD)
+    msg = "The getJ method hasn't been implemented"
+    with pytest.raises(NotImplementedError, match=msg):
+        simulation.getJ(model)