hjmjohnson: @Nic-Ma This is a very minor transform to assist with building composite transforms fro testing, or for simulating time delays without actually consuming resources or setting up complicated test environments.


hjmjohnson: @Nic-Ma will work on this in the next few days.  I have consumed too much time on this already this week and need to return to teaching obligations.
Nic-Ma: > @Nic-Ma will work on this in the next few days. I have consumed too much time on this already this week and need to return to teaching obligations.

Sounds good! Really appreciate your contribution!
Thanks.
Nic-Ma: BTW, there are 2 missing parts of this newly added transform:
1. add `SimulateDelayD = SimulateDelayDict = SimulateDelayd` at the end of dictionary.py.
2. add `SimulateDelay` and `SimulateDelayd` to the API [documentations](https://github.com/Project-MONAI/MONAI/blob/master/docs/source/transforms.rst)
(make sure the "~~~" match the string length of transform name)

Could you please help also add them?
Thanks.
hjmjohnson: @Nic-Ma Sorry about the type mismatch.  That was a silly mistake that should not have been overlooked.
hjmjohnson: @wyli Thanks!  Once this is merged, I will rebase the 316-add-persistant-processing-caching so that it can be included as well.  That will allow for my large-scale data processing task to work much more efficiently.
diff --git a/docs/source/transforms.rst b/docs/source/transforms.rst
index 1de2545b..4e32153a 100644
--- a/docs/source/transforms.rst
+++ b/docs/source/transforms.rst
@@ -303,6 +303,12 @@ Vanilla Transforms
     :members:
     :special-members: __call__
 
+`SimulateDelay`
+~~~~~~~~~~~~~~~
+.. autoclass:: SimulateDelay
+    :members:
+    :special-members: __call__
+
 Dictionary-based Transforms
 ----------------------------
 
@@ -549,6 +555,13 @@ Dictionary-based Transforms
     :members:
     :special-members: __call__
 
+
+`SimulateDelayd`
+~~~~~~~~~~~~~~~~
+.. autoclass:: SimulateDelayd
+    :members:
+    :special-members: __call__
+
 Transform Adaptors
 ------------------
 
diff --git a/monai/transforms/utility/array.py b/monai/transforms/utility/array.py
index c436720d..c1c49770 100644
--- a/monai/transforms/utility/array.py
+++ b/monai/transforms/utility/array.py
@@ -12,9 +12,11 @@
 A collection of "vanilla" transforms for utility functions
 https://github.com/Project-MONAI/MONAI/wiki/MONAI_Design
 """
+import time
 
 import numpy as np
 import torch
+
 from monai.transforms.compose import Transform
 
 
@@ -162,3 +164,29 @@ class SqueezeDim(Transform):
             img (ndarray): numpy arrays with required dimension `dim` removed
         """
         return np.squeeze(img, self.dim)
+
+
+class SimulateDelay(Transform):
+    """
+    This is a pass through transform to be used for testing purposes. It allows
+    adding fake behaviors that are useful for testing purposes to simulate
+    how large datasets behave without needing to test on large data sets.
+
+    For example, simulating slow NFS data transfers, or slow network transfers
+    in testing by adding explicit timing delays. Testing of small test data
+    can lead to incomplete understanding of real world issues, and may lead
+    to sub-optimal design choices.
+    """
+
+    def __init__(self, delay_time=0.0):
+        """
+        Args:
+            delay_time(float): The minimum amount of time, in fractions of seconds,
+                to accomplish this delay task.
+        """
+        super().__init__()
+        self.delay_time: float = delay_time
+
+    def __call__(self, img):
+        time.sleep(self.delay_time)
+        return img
diff --git a/monai/transforms/utility/dictionary.py b/monai/transforms/utility/dictionary.py
index da3d123e..35e6a2d1 100644
--- a/monai/transforms/utility/dictionary.py
+++ b/monai/transforms/utility/dictionary.py
@@ -19,7 +19,7 @@ import numpy as np
 
 from monai.transforms.compose import MapTransform
 from monai.transforms.utility.array import AddChannel, AsChannelFirst, ToTensor, \
-    AsChannelLast, CastToType, RepeatChannel, SqueezeDim
+    AsChannelLast, CastToType, RepeatChannel, SqueezeDim, SimulateDelay
 
 
 class AsChannelFirstd(MapTransform):
@@ -193,6 +193,35 @@ class SqueezeDimd(MapTransform):
         return d
 
 
+class SimulateDelayd(MapTransform):
+    """
+    dictionary-based wrapper of :py:class:monai.transforms.utility.array.SimulateDelay.
+    """
+
+    def __init__(self, keys, delay_time=0.0):
+        """
+        Args:
+            keys (hashable items): keys of the corresponding items to be transformed.
+                See also: :py:class:`monai.transforms.compose.MapTransform`
+            delay_time(float or list of float): The minimum amount of time, in fractions of seconds,
+                to accomplish this identity task. If a list is provided, it must be of length equal
+                to the keys representing the delay for each key element.
+        """
+        super().__init__(keys)
+
+        if not isinstance(delay_time, (tuple, list)):
+            delay_time = [delay_time] * len(keys)
+        self.converter_dictionary = dict()
+        for key, keyed_default_delay in zip(self.keys, delay_time):
+            self.converter_dictionary[key] = SimulateDelay(delay_time=keyed_default_delay)
+
+    def __call__(self, data):
+        d = dict(data)
+        for key in self.keys:
+            d[key] = self.converter_dictionary[key](d[key])
+        return d
+
+
 AsChannelFirstD = AsChannelFirstDict = AsChannelFirstd
 AsChannelLastD = AsChannelLastDict = AsChannelLastd
 AddChannelD = AddChannelDict = AddChanneld
@@ -201,3 +230,4 @@ CastToTypeD = CastToTypeDict = CastToTyped
 ToTensorD = ToTensorDict = ToTensord
 DeleteKeysD = DeleteKeysDict = DeleteKeysd
 SqueezeDimD = SqueezeDimDict = SqueezeDimd
+SimulateDelayD = SimulateDelayDict = SimulateDelayd

Add IdentityTransform with configurable delay
Simulating delays in a transform sequence can be useful for simulating delays that may happen
in real data processing scenarios.  For example, a developer may want to simulate network delays by adding an IdentityTransform with a set delay to simulate slow file loading times.

**Describe the solution you'd like**
Add an IdentityTransform with fixed time delay.

**Additional context**
IdentityTransform can be used to simulating behaviors in testing environments.

diff --git a/tests/test_dataset.py b/tests/test_dataset.py
index 489662f4..3b98bcc7 100644
--- a/tests/test_dataset.py
+++ b/tests/test_dataset.py
@@ -17,7 +17,7 @@ import tempfile
 import nibabel as nib
 from parameterized import parameterized
 from monai.data import Dataset
-from monai.transforms import LoadNiftid
+from monai.transforms import Compose, LoadNiftid, SimulateDelayd
 
 TEST_CASE_1 = [
     (128, 128, 128)
@@ -48,7 +48,10 @@ class TestDataset(unittest.TestCase):
                 'extra': os.path.join(tempdir, 'test_extra2.nii.gz')
             }
         ]
-        dataset = Dataset(data=test_data, transform=LoadNiftid(keys=['image', 'label', 'extra']))
+        test_transform = Compose([LoadNiftid(keys=['image', 'label', 'extra']),
+                                  SimulateDelayd(keys=['image', 'label', 'extra'],
+                                                 delay_time=[1e-7, 1e-6, 1e-5])])
+        dataset = Dataset(data=test_data, transform=test_transform)
         data1 = dataset[0]
         data2 = dataset[1]
         shutil.rmtree(tempdir)
diff --git a/tests/test_simulatedelay.py b/tests/test_simulatedelay.py
new file mode 100644
index 00000000..9c7bbbfb
--- /dev/null
+++ b/tests/test_simulatedelay.py
@@ -0,0 +1,33 @@
+# Copyright 2020 MONAI Consortium
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import time
+import numpy as np
+from parameterized import parameterized
+from monai.transforms.utility.array import SimulateDelay
+from tests.utils import NumpyImageTestCase2D
+
+
+class TestSimulateDelay(NumpyImageTestCase2D):
+
+    @parameterized.expand([(0.45,), (1,)])
+    def test_value(self, delay_test_time: float):
+        resize = SimulateDelay(delay_time=delay_test_time)
+        start: float = time.time()
+        result = resize(self.imt[0])
+        stop: float = time.time()
+        measured_approximate: float = stop - start
+        np.testing.assert_array_less(delay_test_time, measured_approximate)
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/test_simulatedelayd.py b/tests/test_simulatedelayd.py
new file mode 100644
index 00000000..af533a6d
--- /dev/null
+++ b/tests/test_simulatedelayd.py
@@ -0,0 +1,33 @@
+# Copyright 2020 MONAI Consortium
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import time
+import numpy as np
+from parameterized import parameterized
+from monai.transforms.utility.dictionary import SimulateDelayd
+from tests.utils import NumpyImageTestCase2D
+
+
+class TestSimulateDelay(NumpyImageTestCase2D):
+
+    @parameterized.expand([(0.45,), (1,)])
+    def test_value(self, delay_test_time: float):
+        resize = SimulateDelayd(keys='imgd', delay_time=delay_test_time)
+        start: float = time.time()
+        _ = resize({'imgd': self.imt[0]})
+        stop: float = time.time()
+        measured_approximate: float = stop - start
+        np.testing.assert_array_less(delay_test_time, measured_approximate)
+
+
+if __name__ == '__main__':
+    unittest.main()

pip install -e .[all]
parse_log_pytest
requirements.txt
pytest black flake8 mypy pytype
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
absl-py==1.4.0
attrs==22.2.0
black==22.8.0
cachetools==4.2.4
certifi==2021.5.30
charset-normalizer==2.0.12
click==8.0.4
coverage==6.2
cycler==0.11.0
dataclasses==0.8
decorator==4.4.2
flake8==5.0.4
google-auth==2.22.0
google-auth-oauthlib==0.4.6
grpcio==1.48.2
idna==3.10
imageio==2.15.0
importlab==0.8.1
importlib-metadata==4.8.3
iniconfig==1.1.1
kiwisolver==1.3.1
libcst==0.4.1
Markdown==3.3.7
matplotlib==3.3.4
mccabe==0.7.0
-e git+https://github.com/Project-MONAI/MONAI.git@47ad3a36c8b38acba272f641920b8d71674b5e56#egg=monai
mypy==0.971
mypy-extensions==1.0.0
networkx==2.5.1
nibabel==3.2.2
ninja==1.11.1.1
numpy==1.19.5
oauthlib==3.2.2
packaging==21.3
parameterized==0.8.1
pathspec==0.9.0
Pillow==8.4.0
platformdirs==2.4.0
pluggy==1.0.0
protobuf==3.19.6
py==1.11.0
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycodestyle==2.9.1
pyflakes==2.5.0
pyparsing==3.1.4
pytest==7.0.1
python-dateutil==2.9.0.post0
pytorch-ignite==0.3.0
pytype==2022.1.5
PyWavelets==1.1.1
PyYAML==6.0.1
requests==2.27.1
requests-oauthlib==2.0.0
rsa==4.9
scikit-image==0.17.2
scipy==1.5.4
six==1.17.0
tabulate==0.8.10
tensorboard==2.10.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tifffile==2020.9.3
toml==0.10.2
tomli==1.2.3
torch==1.10.2
typed-ast==1.5.5
typing-inspect==0.9.0
typing_extensions==4.1.1
urllib3==1.26.20
Werkzeug==2.0.3
zipp==3.6.0

name: MONAI
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - absl-py==1.4.0
      - attrs==22.2.0
      - black==22.8.0
      - cachetools==4.2.4
      - charset-normalizer==2.0.12
      - click==8.0.4
      - coverage==6.2
      - cycler==0.11.0
      - dataclasses==0.8
      - decorator==4.4.2
      - flake8==5.0.4
      - google-auth==2.22.0
      - google-auth-oauthlib==0.4.6
      - grpcio==1.48.2
      - idna==3.10
      - imageio==2.15.0
      - importlab==0.8.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - kiwisolver==1.3.1
      - libcst==0.4.1
      - markdown==3.3.7
      - matplotlib==3.3.4
      - mccabe==0.7.0
      - mypy==0.971
      - mypy-extensions==1.0.0
      - networkx==2.5.1
      - nibabel==3.2.2
      - ninja==1.11.1.1
      - numpy==1.19.5
      - oauthlib==3.2.2
      - packaging==21.3
      - parameterized==0.8.1
      - pathspec==0.9.0
      - pillow==8.4.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - protobuf==3.19.6
      - py==1.11.0
      - pyasn1==0.5.1
      - pyasn1-modules==0.3.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - python-dateutil==2.9.0.post0
      - pytorch-ignite==0.3.0
      - pytype==2022.1.5
      - pywavelets==1.1.1
      - pyyaml==6.0.1
      - requests==2.27.1
      - requests-oauthlib==2.0.0
      - rsa==4.9
      - scikit-image==0.17.2
      - scipy==1.5.4
      - six==1.17.0
      - tabulate==0.8.10
      - tensorboard==2.10.1
      - tensorboard-data-server==0.6.1
      - tensorboard-plugin-wit==1.8.1
      - tifffile==2020.9.3
      - toml==0.10.2
      - tomli==1.2.3
      - torch==1.10.2
      - typed-ast==1.5.5
      - typing-extensions==4.1.1
      - typing-inspect==0.9.0
      - urllib3==1.26.20
      - werkzeug==2.0.3
      - zipp==3.6.0
prefix: /opt/conda/envs/MONAI

tests/test_dataset.py::TestDataset::test_shape_0 tests/test_simulatedelay.py::TestSimulateDelay::test_value_0 tests/test_simulatedelay.py::TestSimulateDelay::test_value_1 tests/test_simulatedelayd.py::TestSimulateDelay::test_value_0 tests/test_simulatedelayd.py::TestSimulateDelay::test_value_1
monai/transforms/utility/dictionary.py monai/transforms/utility/array.py docs/source/transforms.rst
monai/transforms/utility/dictionary.py monai/transforms/utility/array.py docs/source/transforms.rst