Repository: Project-MONAI/MONAI

Issue:
 cg() got an unexpected keyword argument 'tol'
```
======================================================================
ERROR: test_against_official_code_using_cg (tests.test_ultrasound_confidence_map_transform.TestUltrasoundConfidenceMapTransform)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/MONAI/MONAI/tests/test_ultrasound_confidence_map_transform.py", line 699, in test_against_official_code_using_cg
    output = transform(input_img)
  File "/home/runner/work/MONAI/MONAI/monai/transforms/intensity/array.py", line 2878, in __call__
    conf_map: NdarrayOrTensor = self._compute_conf_map(img_np, mask_np)
  File "/home/runner/work/MONAI/MONAI/monai/data/ultrasound_confidence_map.py", line 381, in __call__
    map_: NDArray = self.confidence_estimation(data, seeds, labels, self.beta, self.gamma)
  File "/home/runner/work/MONAI/MONAI/monai/data/ultrasound_confidence_map.py", line 338, in confidence_estimation
    x = self._solve_linear_system(lap, rhs)
  File "/home/runner/work/MONAI/MONAI/monai/data/ultrasound_confidence_map.py", line 288, in _solve_linear_system
    x, _ = cg(lap, rhs, tol=self.cg_tol, maxiter=self.cg_maxiter, M=m)
TypeError: cg() got an unexpected keyword argument 'tol'
```
 cg() got an unexpected keyword argument 'tol'
```
======================================================================
ERROR: test_against_official_code_using_cg (tests.test_ultrasound_confidence_map_transform.TestUltrasoundConfidenceMapTransform)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/MONAI/MONAI/tests/test_ultrasound_confidence_map_transform.py", line 699, in test_against_official_code_using_cg
    output = transform(input_img)
  File "/home/runner/work/MONAI/MONAI/monai/transforms/intensity/array.py", line 2878, in __call__
    conf_map: NdarrayOrTensor = self._compute_conf_map(img_np, mask_np)
  File "/home/runner/work/MONAI/MONAI/monai/data/ultrasound_confidence_map.py", line 381, in __call__
    map_: NDArray = self.confidence_estimation(data, seeds, labels, self.beta, self.gamma)
  File "/home/runner/work/MONAI/MONAI/monai/data/ultrasound_confidence_map.py", line 338, in confidence_estimation
    x = self._solve_linear_system(lap, rhs)
  File "/home/runner/work/MONAI/MONAI/monai/data/ultrasound_confidence_map.py", line 288, in _solve_linear_system
    x, _ = cg(lap, rhs, tol=self.cg_tol, maxiter=self.cg_maxiter, M=m)
TypeError: cg() got an unexpected keyword argument 'tol'
```


Discussion:

Resolving patch:
diff --git a/monai/data/ultrasound_confidence_map.py b/monai/data/ultrasound_confidence_map.py
--- a/monai/data/ultrasound_confidence_map.py
+++ b/monai/data/ultrasound_confidence_map.py
@@ -19,10 +19,10 @@
 __all__ = ["UltrasoundConfidenceMap"]
 
 cv2, _ = optional_import("cv2")
-csc_matrix, _ = optional_import("scipy.sparse", "1.7.1", min_version, "csc_matrix")
-spsolve, _ = optional_import("scipy.sparse.linalg", "1.7.1", min_version, "spsolve")
-cg, _ = optional_import("scipy.sparse.linalg", "1.7.1", min_version, "cg")
-hilbert, _ = optional_import("scipy.signal", "1.7.1", min_version, "hilbert")
+csc_matrix, _ = optional_import("scipy.sparse", "1.12.0", min_version, "csc_matrix")
+spsolve, _ = optional_import("scipy.sparse.linalg", "1.12.0", min_version, "spsolve")
+cg, _ = optional_import("scipy.sparse.linalg", "1.12.0", min_version, "cg")
+hilbert, _ = optional_import("scipy.signal", "1.12.0", min_version, "hilbert")
 ruge_stuben_solver, _ = optional_import("pyamg", "5.0.0", min_version, "ruge_stuben_solver")
 
 
@@ -285,7 +285,7 @@ def _solve_linear_system(self, lap, rhs):
             lap_sparse = lap.tocsr()
             ml = ruge_stuben_solver(lap_sparse, coarse_solver="pinv")
             m = ml.aspreconditioner(cycle="V")
-            x, _ = cg(lap, rhs, tol=self.cg_tol, maxiter=self.cg_maxiter, M=m)
+            x, _ = cg(lap, rhs, rtol=self.cg_tol, maxiter=self.cg_maxiter, M=m)
         else:
             x = spsolve(lap, rhs)
 
diff --git a/monai/optimizers/lr_finder.py b/monai/optimizers/lr_finder.py
--- a/monai/optimizers/lr_finder.py
+++ b/monai/optimizers/lr_finder.py
@@ -524,7 +524,7 @@ def plot(
         # Plot the LR with steepest gradient
         if steepest_lr:
             lr_at_steepest_grad, loss_at_steepest_grad = self.get_steepest_gradient(skip_start, skip_end)
-            if lr_at_steepest_grad is not None:
+            if lr_at_steepest_grad is not None and loss_at_steepest_grad is not None:
                 ax.scatter(
                     lr_at_steepest_grad,
                     loss_at_steepest_grad,


Test patch:
diff --git a/tests/test_ultrasound_confidence_map_transform.py b/tests/test_ultrasound_confidence_map_transform.py
--- a/tests/test_ultrasound_confidence_map_transform.py
+++ b/tests/test_ultrasound_confidence_map_transform.py
@@ -20,8 +20,11 @@
 from PIL import Image
 
 from monai.transforms import UltrasoundConfidenceMapTransform
+from monai.utils import optional_import
 from tests.utils import assert_allclose
 
+_, has_scipy = optional_import("scipy")
+
 TEST_INPUT = np.array(
     [
         [1, 2, 3, 23, 13, 22, 5, 1, 2, 3],
@@ -482,6 +485,7 @@
 )
 
 
+@unittest.skipUnless(has_scipy, "Requires scipy")
 class TestUltrasoundConfidenceMapTransform(unittest.TestCase):
 
     def setUp(self):
diff --git a/tests/utils.py b/tests/utils.py
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -475,7 +475,7 @@ def run_process(self, func, local_rank, args, kwargs, results):
             if self.verbose:
                 os.environ["NCCL_DEBUG"] = "INFO"
                 os.environ["NCCL_DEBUG_SUBSYS"] = "ALL"
-            os.environ["NCCL_BLOCKING_WAIT"] = str(1)
+            os.environ["TORCH_NCCL_BLOCKING_WAIT"] = str(1)
             os.environ["OMP_NUM_THREADS"] = str(1)
             os.environ["WORLD_SIZE"] = str(self.nproc_per_node * self.nnodes)
             os.environ["RANK"] = str(self.nproc_per_node * self.node_rank + local_rank)