From b047cd27f0d0ea98ccae5356df84db42543c6a7b Mon Sep 17 00:00:00 2001 From: dominiquef Date: Wed, 14 May 2025 12:13:51 -0700 Subject: [PATCH 1/3] Better check for floating actives --- simpeg_drivers/utils/regularization.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simpeg_drivers/utils/regularization.py b/simpeg_drivers/utils/regularization.py index 943760cb..82a5ffa3 100644 --- a/simpeg_drivers/utils/regularization.py +++ b/simpeg_drivers/utils/regularization.py @@ -418,7 +418,9 @@ def set_rotated_operators( grad_op_active = function.regularization_mesh.Pac.T @ ( grad_op @ function.regularization_mesh.Pac ) - active_faces = grad_op_active.max(axis=1).toarray().ravel() > 0 + active_faces = np.isclose( + grad_op_active @ np.ones(function.regularization_mesh.n_cells), 0 + ) setattr( function.regularization_mesh, From 0cec36572add723856adff2c80b603e17bb16f2f Mon Sep 17 00:00:00 2001 From: dominiquef Date: Wed, 14 May 2025 12:20:28 -0700 Subject: [PATCH 2/3] Update unit test --- tests/run_tests/driver_rotated_gradients_test.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/run_tests/driver_rotated_gradients_test.py b/tests/run_tests/driver_rotated_gradients_test.py index 63234d53..159fa64f 100644 --- a/tests/run_tests/driver_rotated_gradients_test.py +++ b/tests/run_tests/driver_rotated_gradients_test.py @@ -35,7 +35,7 @@ # To test the full run and validate the inversion. # Move this file out of the test directory and run. -target_run = {"data_norm": 0.006830937520353864, "phi_d": 0.0276, "phi_m": 0.0288} +target_run = {"data_norm": 0.006830937520353864, "phi_d": 0.0309, "phi_m": 0.028} def test_gravity_rotated_grad_fwr_run( @@ -142,13 +142,20 @@ def test_rotated_grad_run( inactive_ind = run_ws.get_entity("active_cells")[0].values == 0 assert np.all(nan_ind == inactive_ind) + # Smooth functions should be zero for uniform model + for obj in driver.regularization.objfcts: + for smooth in obj.objfcts[1:]: + np.testing.assert_allclose( + smooth(np.ones(driver.models.n_active)), 0, atol=1e-6 + ) + if __name__ == "__main__": # Full run test_gravity_rotated_grad_fwr_run( Path("./"), n_grid_points=10, - refinement=(4, 8), + refinement=(6, 8), ) test_rotated_grad_run( From 6c44ade4ec443c0ab9449b505ba654ff8e7395f8 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Wed, 14 May 2025 13:08:34 -0700 Subject: [PATCH 3/3] Update mvi test target after grad operator change --- simpeg_drivers/utils/regularization.py | 1 + tests/run_tests/driver_mvi_test.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/simpeg_drivers/utils/regularization.py b/simpeg_drivers/utils/regularization.py index 82a5ffa3..f6c6ab9c 100644 --- a/simpeg_drivers/utils/regularization.py +++ b/simpeg_drivers/utils/regularization.py @@ -421,6 +421,7 @@ def set_rotated_operators( active_faces = np.isclose( grad_op_active @ np.ones(function.regularization_mesh.n_cells), 0 ) + active_faces &= grad_op_active.max(axis=1).toarray().ravel() != 0 setattr( function.regularization_mesh, diff --git a/tests/run_tests/driver_mvi_test.py b/tests/run_tests/driver_mvi_test.py index c90abf65..80d9304f 100644 --- a/tests/run_tests/driver_mvi_test.py +++ b/tests/run_tests/driver_mvi_test.py @@ -36,7 +36,7 @@ # To test the full run and validate the inversion. # Move this file out of the test directory and run. -target_mvi_run = {"data_norm": 6.3559205278626525, "phi_d": 0.0091, "phi_m": 0.00603} +target_mvi_run = {"data_norm": 6.3559205278626525, "phi_d": 0.00933, "phi_m": 0.00401} def test_magnetic_vector_fwr_run(