Repository: Project-MONAI/MONAI
File: monai/handlers/clearml_handlers.py (Python)

Code before:
            self.clearml_task = Task.current_task()
        else:
            self.clearml_task = Task.init(
                project_name=project_name,
                task_name=task_name,
                output_uri=output_uri,
                tags=tags,
                reuse_last_task_id=reuse_last_task_id,
                continue_last_task=continue_last_task,
                auto_connect_frameworks=auto_connect_frameworks,
            )


class ClearMLStatsHandler(ClearMLHandler, TensorBoardStatsHandler):
    """

    Class to write tensorboard stats by inheriting TensorBoardStatsHandler class.
    Everything from Tensorboard is logged automatically to ClearML WebUI.

    """

    def __init__(
        self,
        project_name: str | None = "MONAI",
        task_name: str | None = "Default Task",
        output_uri: str = True,
        tags: Optional[Sequence[str]] | None = None,
        reuse_last_task_id: bool = True,
        continue_last_task: bool = False,
        auto_connect_frameworks: Union[bool, Mapping[str, Union[bool, str, list]]] | bool = True,
        *args,
        **kwargs,
    ):
        """
        Args:
            project_name:               ClearML project name.
            task_name:                  ClearML task name.
            output_uri:                 The default location for output models and other artifacts.
            tags:                       A list of tags (str) to the created Task.
            reuse_last_task_id:         Force a new Task (experiment) with a previously used Task ID.
            continue_last_task:         Continue the execution of a previously executed Task (experiment).
            auto_connect_frameworks:    Automatically connect frameworks.
        """

        ClearMLHandler.__init__(
            self,
            project_name=project_name,
            task_name=task_name,
            output_uri=output_uri,
            tags=tags,
            reuse_last_task_id=reuse_last_task_id,

Review comment (suggestion):
Should this type hint be `output_uri: str | bool`?

Thanks,
Bin

Code after:
        if TYPE_CHECKING:
            import clearml
        else:
            clearml, _ = optional_import("clearml")

        # Always check if the user didn't already add a `task.init`` in before
        # if so, use that task, otherwise create a new one.
        if clearml.Task.current_task():
            self.clearml_task = clearml.Task.current_task()
        else:
            self.clearml_task = clearml.Task.init(
                project_name=project_name,
                task_name=task_name,
                output_uri=output_uri,
                tags=tags,
                reuse_last_task_id=reuse_last_task_id,
                continue_last_task=continue_last_task,
                auto_connect_frameworks=auto_connect_frameworks,
                auto_connect_arg_parser=auto_connect_arg_parser,
            )


class ClearMLStatsHandler(ClearMLHandler, TensorBoardStatsHandler):
    """

    Class to write tensorboard stats by inheriting TensorBoardStatsHandler class.
    Everything from Tensorboard is logged automatically to ClearML.

    Usage example is available in the tutorial:
    https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/unet_segmentation_3d_ignite.ipynb.

    """

    def __init__(
        self,
        project_name: str | None = "MONAI",
        task_name: str | None = "monai_experiment",
        output_uri: str | bool = True,
        tags: Sequence[str] | None = None,
        reuse_last_task_id: bool = True,
        continue_last_task: bool = False,
        auto_connect_frameworks: bool | Mapping[str, bool | str | list] = True,
        auto_connect_arg_parser: bool | Mapping[str, bool] = True,
        *args: Any,
        **kwargs: Any,
    ) -> None:
        """
        Args:
            project_name: ClearML project name, default to 'MONAI'.
            task_name: ClearML task name, default to 'monai_experiment'.
            output_uri: The default location for output models and other artifacts, default to 'True'.