diff --git a/simpeg_drivers/components/factories/misfit_factory.py b/simpeg_drivers/components/factories/misfit_factory.py index 0b7c8d59..0930af60 100644 --- a/simpeg_drivers/components/factories/misfit_factory.py +++ b/simpeg_drivers/components/factories/misfit_factory.py @@ -16,9 +16,10 @@ 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 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( @@ -143,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(attributes[0], Future): ordering = [] for future in self.client.gather(attributes): ordering += future 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) 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