Repository navigation
Set the model when calling getJ in DC and SIP simulations - #1361
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1361 +/- ##
==========================================
+ Coverage 86.01% 86.03% +0.02%
==========================================
Files 411 412 +1
Lines 54250 54356 +106
Branches 5106 5106
==========================================
+ Hits 46661 46765 +104
+ Misses 6171 6170 -1
- Partials 1418 1421 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@simpeg/simpeg-developers: this is ready for review! |
There was a problem hiding this comment.
Thanks for tackling this @lheagy.
The fixes are very straightforward, but since this is a bugfix, I would suggest adding some tests that would fail without them, so we can be sure we are not facing them again in the future.
Something like this:
import pytest
import numpy as np
from discretize import TensorMesh
from SimPEG import utils
from SimPEG.maps import IdentityMap
from SimPEG.electromagnetics import resistivity as dc
@pytest.fixture
def mesh():
"""Sample mesh."""
cs = 0.5
npad = 11
hx = [(cs, npad, -1.5), (cs, 15), (cs, npad, 1.5)]
hy = [(cs, npad, -1.5), (cs, 15), (cs, npad, 1.5)]
hz = [(cs, npad, -1.5), (cs, 15), (cs, npad, 1.5)]
mesh = TensorMesh([hx, hy, hz], x0="CCC")
return mesh
@pytest.fixture
def survey(mesh):
"""Sample survey."""
# Set up survey parameters for numeric solution
x = mesh.nodes_x[(mesh.nodes_x > -75.0) & (mesh.nodes_x < 75.0)]
y = mesh.nodes_y[(mesh.nodes_y > -75.0) & (mesh.nodes_y < 75.0)]
Aloc = np.r_[1.25, 0.0, 0.0]
Bloc = np.r_[-1.25, 0.0, 0.0]
M = utils.ndgrid(x - 25.0, y, np.r_[0.0])
N = utils.ndgrid(x + 25.0, y, np.r_[0.0])
rx = dc.receivers.Dipole(M, N)
src = dc.sources.Dipole([rx], Aloc, Bloc)
survey = dc.survey.Survey([src])
return survey
def test_getj_model_assignment(mesh, survey):
"""
Test model assignment when calling the Simulation3DNodal.getJ method
"""
simulation = dc.simulation.Simulation3DNodal(
mesh=mesh, survey=survey, sigmaMap=IdentityMap(mesh)
)
model_1 = np.ones(mesh.nC) * 1e-2
model_2 = np.ones(mesh.nC) * 1e-1
j_1 = simulation.getJ(model_1)
j_2 = simulation.getJ(model_2)
# Check if the two Js are different
assert not np.allclose(j_1, j_2)Tests like this should be included for each class that has been modified.
|
Many thanks @santisoler! These are great suggestions for the tests. If you have the time to add those, that would be awesome. I know it is a small thing, but I won't be able to get back to this for a bit. If not, no worries, I can try to find some time later in the week. |
|
@lheagy, I've just pushed some tests for the DC simulations, plus one test for the SIP simulation. The DC tests are all passing, and they fail if we run them on The test for SIP is falling into an error, but because I'm doing something wrong. Here I copy the traceback of the test failure: Would you take a look at it and see why is this failing? After that we would just need to write tests for the 2D SIP simulations. With that I think we should be able to merge this PR. |
|
It looks like |
getJ in DC and SIP simulations
|
I'm merging this. The tests for the SIP are currently failing, but decorated with |
) Make sure we set the model when calling getJ. This will ensure that if the model is changed, the sensitivity matrix is cleared (for nonlinear problems) and the sensitivity recomputed. This will close simpeg#1358 --------- Co-authored-by: Santiago Soler <[email protected]>
Summary
make sure we set the model when calling getJ. This will ensure that if the model is changed, the sensitivity matrix is cleared (for nonlinear problems) and the sensitivity recomputed. This will close #1358
PR Checklist
expect style.
to a Pull Request
@simpeg/simpeg-developerswhen ready for review.Reference issue
Closes #1358