nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: simpeg/simpeg
Pull request #1207 (2023-04-05 23:19:15)

Fix length scale getters
Fix for #1198.


Patch:
diff --git a/SimPEG/regularization/base.py b/SimPEG/regularization/base.py
index 263fc64f8..0979c8dcd 100644
--- a/SimPEG/regularization/base.py
+++ b/SimPEG/regularization/base.py
@@ -935,7 +935,7 @@ class WeightedLeastSquares(ComboObjectiveFunction):
     @property
     def length_scale_x(self):
         """Constant multiplier of the base length scale on model gradients along x."""
-        return np.sqrt(self.alpha_x / self.regularization_mesh.base_length)
+        return np.sqrt(self.alpha_x) / self.regularization_mesh.base_length
 
     @length_scale_x.setter
     def length_scale_x(self, value: float):
@@ -952,7 +952,7 @@ class WeightedLeastSquares(ComboObjectiveFunction):
     @property
     def length_scale_y(self):
         """Constant multiplier of the base length scale on model gradients along y."""
-        return np.sqrt(self.alpha_y / self.regularization_mesh.base_length)
+        return np.sqrt(self.alpha_y) / self.regularization_mesh.base_length
 
     @length_scale_y.setter
     def length_scale_y(self, value: float):
@@ -969,7 +969,7 @@ class WeightedLeastSquares(ComboObjectiveFunction):
     @property
     def length_scale_z(self):
         """Constant multiplier of the base length scale on model gradients along z."""
-        return np.sqrt(self.alpha_z / self.regularization_mesh.base_length)
+        return np.sqrt(self.alpha_z) / self.regularization_mesh.base_length
 
     @length_scale_z.setter
     def length_scale_z(self, value: float):


Test patch:
diff --git a/tests/base/test_regularization.py b/tests/base/test_regularization.py
index cc4f4a00a..ce8b51111 100644
--- a/tests/base/test_regularization.py
+++ b/tests/base/test_regularization.py
@@ -550,5 +550,20 @@ class RegularizationTests(unittest.TestCase):
             assert reg.gradient_type == "total"  # Check default
 
 
+def test_WeightedLeastSquares():
+    mesh = discretize.TensorMesh([3, 4, 5])
+
+    reg = regularization.WeightedLeastSquares(mesh)
+
+    reg.length_scale_x = 0.5
+    np.testing.assert_allclose(reg.length_scale_x, 0.5)
+
+    reg.length_scale_y = 0.3
+    np.testing.assert_allclose(reg.length_scale_y, 0.3)
+
+    reg.length_scale_z = 0.8
+    np.testing.assert_allclose(reg.length_scale_z, 0.8)
+
+
 if __name__ == "__main__":
     unittest.main()