Skip to content

Commit

Permalink
Add deterministic support for RandSimulateLowResolutiond (#8057)
Browse files Browse the repository at this point in the history
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
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [ ] 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>
  • Loading branch information
25benjaminli and KumoLiu authored Sep 2, 2024
1 parent 6a0e1b0 commit c9b8bdb
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions monai/transforms/spatial/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit c9b8bdb

Please sign in to comment.