Skip to content

Commit

Permalink
Fix deprecated argument in 'scipy.sparse.linalg.cg' (#7897)
Browse files Browse the repository at this point in the history
Fixes #7896 

### Description

- 'scipy.sparse.linalg.cg' keyword argument `tol` is deprecated in favor
of `rtol` and will be removed in SciPy v1.14.0. Until then, if set, it
will override `rtol`. So update to use `rtol` in `cg`.

- Drop python 3.8 test in packaging and premerge-gpu-test.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
KumoLiu and pre-commit-ci[bot] committed Jul 6, 2024
1 parent 3b9683c commit 64ea76d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
opt: ["codeformat", "pytype", "mypy"]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.9'
- name: cache weekly timestamp
id: pip-cache
run: |
Expand All @@ -45,6 +45,7 @@ jobs:
key: ${{ runner.os }}-pip-${{ steps.pip-cache.outputs.datew }}
- name: Install dependencies
run: |
find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \;
python -m pip install --upgrade pip wheel
python -m pip install -r requirements-dev.txt
- name: Lint and type check
Expand Down Expand Up @@ -130,10 +131,10 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.9'
- name: cache weekly timestamp
id: pip-cache
run: |
Expand Down Expand Up @@ -211,10 +212,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.9'
- name: cache weekly timestamp
id: pip-cache
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ itk>=5.2
nibabel
parameterized
scikit-image>=0.19.0
scipy>=1.7.1
scipy>=1.12.0; python_version >= '3.9'
tensorboard
commonmark==0.9.1
recommonmark==0.6.0
Expand Down
10 changes: 5 additions & 5 deletions monai/data/ultrasound_confidence_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion monai/optimizers/lr_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-r requirements-min.txt
pytorch-ignite==0.4.11
gdown>=4.7.3
scipy>=1.7.1
scipy>=1.12.0; python_version >= '3.9'
itk>=5.2
nibabel
pillow!=8.3.0 # https://github.com/python-pillow/Pillow/issues/5571
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
torch>=1.9
numpy>=1.20,<2.0
numpy>=1.20,<=1.26.0
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ all =
nibabel
ninja
scikit-image>=0.14.2
scipy>=1.7.1
scipy>=1.12.0; python_version >= '3.9'
pillow
tensorboard
gdown>=4.7.3
Expand Down Expand Up @@ -92,7 +92,7 @@ ninja =
skimage =
scikit-image>=0.14.2
scipy =
scipy>=1.7.1
scipy>=1.12.0; python_version >= '3.9'
pillow =
pillow!=8.3.0
tensorboard =
Expand Down
4 changes: 4 additions & 0 deletions tests/test_ultrasound_confidence_map_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -482,6 +485,7 @@
)


@unittest.skipUnless(has_scipy, "Requires scipy")
class TestUltrasoundConfidenceMapTransform(unittest.TestCase):

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64ea76d

Please sign in to comment.