From c9b8bdb93b8a5e5fd4e9a72c34dba760f9c66a04 Mon Sep 17 00:00:00 2001 From: BenjaminLi <76795078+25benjaminli@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:06:34 -0400 Subject: [PATCH] Add deterministic support for RandSimulateLowResolutiond (#8057) Fixes #7911, which describes how the RandSimulateLowResolutiond dictionary transform produces non-deterministic outputs, yet the typical array transform RandSimulateLowResolution produces deterministic ones. ### Description Inside of `RandSimulateLowResolutiond`, added the line `self.sim_lowres_tfm.set_random_state(seed, state)` in `set_random_state` to ensure the helper function `sim_lowres_tfm` is seeded and the transform can be performed deterministically. Note: I also sifted through the other dictionary transforms with helper functions and did not find anything that looked problematic similar to this. ### Types of changes - [ ] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [x] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] 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: BenjaminLi <25benjaminli@gmail.com> Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/spatial/dictionary.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monai/transforms/spatial/dictionary.py b/monai/transforms/spatial/dictionary.py index 82dee15c7c..2b80034a07 100644 --- a/monai/transforms/spatial/dictionary.py +++ b/monai/transforms/spatial/dictionary.py @@ -2588,6 +2588,7 @@ def set_random_state( self, seed: int | None = None, state: np.random.RandomState | None = None ) -> RandSimulateLowResolutiond: super().set_random_state(seed, state) + self.sim_lowres_tfm.set_random_state(seed, state) return self def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, NdarrayOrTensor]: