Skip to content

Conversation

@gigony
Copy link
Collaborator

@gigony gigony commented Sep 13, 2021

  • Verify the data type of Operator input/output by using [typeguard](.
  • Fix existing IO type errors in DICOMDataLoaderOperator and DICOMSeriesSelectorOperator\

Resolves #59

The cyclic graph seems to be handled by default when using NetworkX (but may need to check explicitly in the future).

     79             # Set source input for a label if op is a root node and (<data type>, <storage type>) == (DataPath, IOType.DISK)
     80             is_root = g.is_root(op)
---> 81             if is_root:
     82                 input_op_info = op.op_info
     83                 input_labels = input_op_info.get_labels(IO.INPUT)

~/miniconda3/envs/monai/lib/python3.6/site-packages/networkx/algorithms/dag.py in topological_sort(G)
    195     if indegree_map:
    196         raise nx.NetworkXUnfeasible(
--> 197             "Graph contains a cycle or graph changed " "during iteration"
    198         )
    199 

NetworkXUnfeasible: Graph contains a cycle or graph changed during iteration

Signed-off-by: Gigon Bae <gbae@nvidia.com>
@gigony gigony added the architectural story Work related to architecture label Sep 13, 2021
@gigony gigony added this to the v0.1.0 milestone Sep 13, 2021
@gigony gigony self-assigned this Sep 13, 2021
Copy link
Collaborator

@MMelQin MMelQin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing example apps that showcases DICOM input parsing all use the DICOM Loader and the Series Selector in tandem, so the change from Study to List[Study] does not impact existing sample in the repo.

@gigony
Copy link
Collaborator Author

gigony commented Sep 13, 2021

Existing example apps that showcases DICOM input parsing all use the DICOM Loader and the Series Selector in tandem, so the change from Study to List[Study] does not impact existing sample in the repo.

Thanks Ming!

With this PR, it actually checks types in runtime so without changing Data type to correct type, it caused runtime error.

E.g.,

 @input("dicom_files", DataPath, IOType.DISK)
-@output("dicom_study_list", List[DICOMStudy], IOType.IN_MEMORY)
+@output("dicom_study_list", DICOMStudy, IOType.IN_MEMORY)
 @env(pip_packages=["pydicom >= 1.4.2"])
 class DICOMDataLoaderOperator(Operator):
$ python examples/apps/ai_spleen_seg_app/app.py -i dcm/ -o output -m model.pt

Traceback (most recent call last):
  File "examples/apps/ai_spleen_seg_app/app.py", line 79, in <module>
    app_instance.run()
  File "examples/apps/ai_spleen_seg_app/app.py", line 43, in run
    super().run()
  File "/home/gbae/miniconda3/envs/monai/lib/python3.6/site-packages/monai/deploy/core/application.py", line 322, in run
    executor.run()
  File "/home/gbae/miniconda3/envs/monai/lib/python3.6/site-packages/monai/deploy/core/executors/single_process_executor.py", line 120, in run
    op.compute(op_exec_context.input_context, op_exec_context.output_context, op_exec_context)
  File "/home/gbae/miniconda3/envs/monai/lib/python3.6/site-packages/monai/deploy/operators/dicom_data_loader_operator.py", line 56, in compute
    output.set(dicom_study_list)
  File "/home/gbae/miniconda3/envs/monai/lib/python3.6/site-packages/monai/deploy/core/io_context.py", line 115, in set
    f"The data type of '{label}' in the {self._io_kind} of '{self._op}' is {data_type}, but the value"
monai.deploy.exceptions.IOMappingError: The data type of 'dicom_study_list' in the output of '<monai.deploy.operators.dicom_data_loader_operator.DICOMDataLoaderOperator object at 0x7f31929ae7b8>' is <class 'monai.deploy.core.domain.dicom_study.DICOMStudy'>, but the value to set is the data type of <class 'list'>.

@gigony gigony merged commit d0aea57 into main Sep 13, 2021
@MMelQin MMelQin deleted the verify_io_types branch November 5, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

architectural story Work related to architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify flows and IO data types among operators

3 participants