Repository: microsoft/nni
File: nni/experiment/config/experiment_config.py (Python)

Code before:

     2. Use kwargs directly

     .. code-block:: python

        config = ExperimentConfig(
            search_space = {...},
            tuner = AlgorithmConfig(name='random'),
            training_service = LocalConfig(
                use_active_gpu = True
            )
        )

    .. _reference: https://nni.readthedocs.io/en/stable/reference/experiment_config.html
    """
    # TODO:
    # The behavior described below is expected but does not work,
    # because some fields are consumed by TrialDispatcher outside environment service.
    # Add the lines to docstr when we fix this issue.

    # Fields commented as "training service field" acts like shortcut for all training services.
    # Users can either specify them here or inside training service config.
    # In latter case hybrid training services can have different settings.

    experiment_name: Optional[str] = None
    experiment_type: str = 'hpo'
    search_space_file: Optional[utils.PathLike] = None
    search_space: Any = None
    trial_command: Optional[str] = None  # training service field
    trial_code_directory: utils.PathLike = '.'  # training service field
    trial_concurrency: int
    trial_gpu_number: Optional[int] = None  # training service field
    max_experiment_duration: Union[str, int, None] = None
    max_trial_number: Optional[int] = None
    max_trial_duration: Union[str, int, None] = None
    nni_manager_ip: Optional[str] = None  # training service field
    use_annotation: bool = False
    debug: bool = False
    log_level: Optional[str] = None
    experiment_working_directory: utils.PathLike = '~/nni-experiments'
    tuner_gpu_indices: Union[List[int], int, str, None] = None
    tuner: Optional[_AlgorithmConfig] = None
    assessor: Optional[_AlgorithmConfig] = None
    advisor: Optional[_AlgorithmConfig] = None
    training_service: Union[TrainingServiceConfig, List[TrainingServiceConfig]]
    shared_storage: Optional[SharedStorageConfig] = None

    def __init__(self, training_service_platform=None, **kwargs):
        super().__init__(**kwargs)
        if training_service_platform is not None:
            # the user chose to init with `config = ExperimentConfig('local')` and set fields later

Review comment (suggestion):
The type hint should be `Literal['hpo']` (from typing_extensions import).

Code after:
        config.training_service.use_active_gpu = True

     2. Use kwargs directly

     .. code-block:: python

        config = ExperimentConfig(
            search_space = {...},
            tuner = AlgorithmConfig(name='random'),
            training_service = LocalConfig(
                use_active_gpu = True
            )
        )

    .. _reference: https://nni.readthedocs.io/en/stable/reference/experiment_config.html
    """
    # TODO:
    # The behavior described below is expected but does not work,
    # because some fields are consumed by TrialDispatcher outside environment service.
    # Add the lines to docstr when we fix this issue.

    # Fields commented as "training service field" acts like shortcut for all training services.
    # Users can either specify them here or inside training service config.
    # In latter case hybrid training services can have different settings.

    experiment_name: Optional[str] = None
    experiment_type: Literal['hpo'] = 'hpo'
    search_space_file: Optional[utils.PathLike] = None
    search_space: Any = None
    trial_command: Optional[str] = None  # training service field
    trial_code_directory: utils.PathLike = '.'  # training service field
    trial_concurrency: int
    trial_gpu_number: Optional[int] = None  # training service field
    max_experiment_duration: Union[str, int, None] = None
    max_trial_number: Optional[int] = None
    max_trial_duration: Union[str, int, None] = None
    nni_manager_ip: Optional[str] = None  # training service field
    use_annotation: bool = False
    debug: bool = False
    log_level: Optional[str] = None
    experiment_working_directory: utils.PathLike = '~/nni-experiments'
    tuner_gpu_indices: Union[List[int], int, str, None] = None
    tuner: Optional[_AlgorithmConfig] = None
    assessor: Optional[_AlgorithmConfig] = None
    advisor: Optional[_AlgorithmConfig] = None
    training_service: Union[TrainingServiceConfig, List[TrainingServiceConfig]]
    shared_storage: Optional[SharedStorageConfig] = None

    def __init__(self, training_service_platform=None, **kwargs):
        super().__init__(**kwargs)
        if training_service_platform is not None: