From d185c603072827267c2d5a81d774b95ec9f8b065 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Fri, 24 Oct 2025 14:37:17 -0700 Subject: [PATCH 1/5] Adjust missing volume from inactive cells (cherry picked from commit 43f4df1b7fd99dbcf5ec9565b4f69d739e8f4be0) --- simpeg_drivers/utils/regularization.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/simpeg_drivers/utils/regularization.py b/simpeg_drivers/utils/regularization.py index 506b30c8..5d06a3ef 100644 --- a/simpeg_drivers/utils/regularization.py +++ b/simpeg_drivers/utils/regularization.py @@ -510,9 +510,13 @@ def set_rotated_operators( ) grad_op_active = mesh.Pac.T @ (unit_grad_op @ mesh.Pac) + + # Remove extra partial volume from missing neighbors + row_sum = np.asarray(grad_op_active.sum(axis=1)).ravel() + grad_op_active -= sdiag(row_sum) + vol_avg_op = mesh.Pac.T @ (vol_avg_op @ mesh.Pac) - active_faces = np.isclose(grad_op_active @ np.ones(mesh.n_cells), 0) - active_faces &= grad_op_active.max(axis=1).toarray().ravel() != 0 + active_faces = grad_op_active.max(axis=1).toarray().ravel() != 0 vol_avg_op = vol_avg_op[active_faces, :] vol_avg_op = sdiag(np.asarray(vol_avg_op.sum(axis=1)).ravel() ** -1) @ vol_avg_op From 7a317f8a201c76e83e41af9d3355285594cca1ea Mon Sep 17 00:00:00 2001 From: dominiquef Date: Fri, 24 Oct 2025 14:40:41 -0700 Subject: [PATCH 2/5] Use vector for bounds (cherry picked from commit 1b2bd4f763c0004983fdf286cc193b4baf511760) --- simpeg_drivers/components/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/simpeg_drivers/components/models.py b/simpeg_drivers/components/models.py index be91a6f4..0650807e 100644 --- a/simpeg_drivers/components/models.py +++ b/simpeg_drivers/components/models.py @@ -276,9 +276,9 @@ def lower_bound(self) -> np.ndarray | None: bound_model = -self._upper_bound.model if bound_model is None: - return -np.inf - - lbound = bound_model.copy() + lbound = np.full(self.n_active, -np.inf) + else: + lbound = bound_model.copy() if self.is_sigma: is_finite = np.isfinite(lbound) @@ -304,9 +304,9 @@ def upper_bound(self) -> np.ndarray | None: bound_model = self._upper_bound.model if bound_model is None: - return np.inf - - ubound = bound_model.copy() + ubound = np.full(self.n_active, np.inf) + else: + ubound = bound_model.copy() if self.is_sigma: is_finite = np.isfinite(ubound) From 2eb73e0fbe051fccda80e557821a2b5d96a94e5b Mon Sep 17 00:00:00 2001 From: dominiquef Date: Fri, 24 Oct 2025 15:15:14 -0700 Subject: [PATCH 3/5] Only parallel compute the misfits for 1D --- simpeg_drivers/components/factories/misfit_factory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/simpeg_drivers/components/factories/misfit_factory.py b/simpeg_drivers/components/factories/misfit_factory.py index 0b7c8d59..1adf0911 100644 --- a/simpeg_drivers/components/factories/misfit_factory.py +++ b/simpeg_drivers/components/factories/misfit_factory.py @@ -19,6 +19,7 @@ from dask.distributed import wait from simpeg import objective_function from simpeg.dask import objective_function as dask_objective_function +from simpeg.electromagnetics.base_1d import BaseEM1DSimulation from simpeg.objective_function import ComboObjectiveFunction from simpeg_drivers.components.factories.simpeg_factory import SimPEGFactory @@ -56,7 +57,7 @@ def assemble_arguments( # pylint: disable=arguments-differ else: channels = [None] - use_futures = self.client + use_futures = self.client and isinstance(self.simulation, BaseEM1DSimulation) # Pickle the simulation to the temporary file with open( From 3cff52d790b72fa4da4acc9e9425d75539c9200c Mon Sep 17 00:00:00 2001 From: dominiquef Date: Fri, 24 Oct 2025 15:23:12 -0700 Subject: [PATCH 4/5] Fix miss use of client --- simpeg_drivers/components/factories/misfit_factory.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simpeg_drivers/components/factories/misfit_factory.py b/simpeg_drivers/components/factories/misfit_factory.py index 1adf0911..f9e73598 100644 --- a/simpeg_drivers/components/factories/misfit_factory.py +++ b/simpeg_drivers/components/factories/misfit_factory.py @@ -16,7 +16,7 @@ from typing import TYPE_CHECKING import numpy as np -from dask.distributed import wait +from dask.distributed import Future, wait from simpeg import objective_function from simpeg.dask import objective_function as dask_objective_function from simpeg.electromagnetics.base_1d import BaseEM1DSimulation @@ -144,12 +144,12 @@ def collect_ordering_from_misfits(self, misfits): """ attributes = [] for misfit in misfits: - if self.client: + if isinstance(misfit, Future): attributes.append(self.client.submit(_get_ordering, misfit)) else: attributes += _get_ordering(misfit) - if self.client: + if isinstance(next(attributes), Future): ordering = [] for future in self.client.gather(attributes): ordering += future From 06f8d23a0d860f2d54b1ad8cc96f38096f4c7039 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Fri, 24 Oct 2025 15:24:08 -0700 Subject: [PATCH 5/5] Use index --- simpeg_drivers/components/factories/misfit_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpeg_drivers/components/factories/misfit_factory.py b/simpeg_drivers/components/factories/misfit_factory.py index f9e73598..0930af60 100644 --- a/simpeg_drivers/components/factories/misfit_factory.py +++ b/simpeg_drivers/components/factories/misfit_factory.py @@ -149,7 +149,7 @@ def collect_ordering_from_misfits(self, misfits): else: attributes += _get_ordering(misfit) - if isinstance(next(attributes), Future): + if isinstance(attributes[0], Future): ordering = [] for future in self.client.gather(attributes): ordering += future