code: def optimize(
      model: str,
      dataset: str,
      loss: str,
      sampler: str,
      storage: Optional[str],
      n_trials: Optional[int],
      timeout: Optional[int],
      output: str,
  ):
      """Optimize hyper-parameters for a KGE model.
  
      For example, use pykeen optimize TransE Nations --loss MarginRankingLoss
  
      # noqa: DAR101
      """
      if n_trials is None and timeout is None:
          click.secho(
              "Must specify either --n-trials or --timeout", fg="red"
          )
          sys.exit(1)
  
      hpo_pipeline_result = hpo_pipeline(
          model=model,
          dataset=dataset,
          loss=loss,
          n_trials=n_trials,
          timeout=timeout,
          storage=storage,
          sampler=sampler,
      )
      hpo_pipeline_result.save_to_directory(output)
  
imports: import sys
  from typing import Optional
  import click
  from class_resolver.contrib.optuna import sampler_resolver
  from .hpo import hpo_pipeline
  from ..losses import loss_resolver
label_desc: Use image node_id 1 for calling a global function with example usage: optimize(model, dataset, loss, sampler, storage, n_trials, timeout, output) without return types