class_docstr: The execution engine will submit every model onto training service.
  
  Resource management is implemented in this class.
  
  This engine doesn't include any optimization across graphs.
  
  NOTE: Due to the design of `nni.experiment`,
  the execution engine resorts to NasExperiment to submit trials as well as waiting for results.
  This is not ideal, because this engine might be one of the very few engines which need the training service.
  Ideally, the training service should be a part of the execution engine, not the experiment.
  
  Ideally, this class should not have any states. Its save and load methods should be empty.
  
  Parameters
  ----------
  nodejs_binding
      The nodejs binding of the experiment.
  fetch_intermediates
      Whether to fetch intermediate results from the training service when list models.
      Setting it to false for large-scale experiments can improve performance.
class_docstr_tok: ["The","execution","engine","will","submit","every","model","onto","training","service",".","Resource","management","is","implemented","in","this","class",".","This","engine","does","n't","include","any","optimization","across","graphs",".","NOTE",":","Due","to","the","design","of","`","nni.experiment","`",",","the","execution","engine","resorts","to","NasExperiment","to","submit","trials","as","well","as","waiting","for","results",".","This","is","not","ideal",",","because","this","engine","might","be","one","of","the","very","few","engines","which","need","the","training","service",".","Ideally",",","the","training","service","should","be","a","part","of","the","execution","engine",",","not","the","experiment",".","Ideally",",","this","class","should","not","have","any","states",".","Its","save","and","load","methods","should","be","empty",".","Parameters","--","--","--","--","--","nodejs_binding","The","nodejs","binding","of","the","experiment",".","fetch_intermediates","Whether","to","fetch","intermediate","results","from","the","training","service","when","list","models",".","Setting","it","to","false","for","large-scale","experiments","can","improve","performance","."]
docstr: Retrieve models previously submitted.
  
  To support a large-scale experiments with thousands of trials,
  this method will retrieve the models from the nodejs binding (i.e., from the database).
  The model instances will be re-created on the fly based on the data from database.
  Although they are the same models semantically, they might not be the same instances.
  Exceptions are those still used by the strategy.
  Their weak references are kept in the engine and thus the exact same instances are returned.
  
  Parameters
  ----------
  status
      The status of the models to be retrieved.
      If None, all models will be retrieved.
  include_intermediates
      Whether to include intermediate models.
docstr_tok: ["Retrieve","models","previously","submitted",".","To","support","a","large-scale","experiments","with","thousands","of","trials",",","this","method","will","retrieve","the","models","from","the","nodejs","binding","(","i.e.",",","from","the","database",")",".","The","model","instances","will","be","re-created","on","the","fly","based","on","the","data","from","database",".","Although","they","are","the","same","models","semantically",",","they","might","not","be","the","same","instances",".","Exceptions","are","those","still","used","by","the","strategy",".","Their","weak","references","are","kept","in","the","engine","and","thus","the","exact","same","instances","are","returned",".","Parameters","--","--","--","--","--","status","The","status","of","the","models","to","be","retrieved",".","If","None",",","all","models","will","be","retrieved",".","include_intermediates","Whether","to","include","intermediate","models","."]
code: def list_models(
      self, status: ModelStatus | None = None
  ) -> Iterable[ExecutableModelSpace]:
      """Retrieve models previously submitted.
  
      To support a large-scale experiments with thousands of trials,
      this method will retrieve the models from the nodejs binding (i.e., from the database).
      The model instances will be re-created on the fly based on the data from database.
      Although they are the same models semantically, they might not be the same instances.
      Exceptions are those still used by the strategy.
      Their weak references are kept in the engine and thus the exact same instances are returned.
  
      Parameters
      ----------
      status
          The status of the models to be retrieved.
          If None, all models will be retrieved.
      include_intermediates
          Whether to include intermediate models.
      """
      self._check_running()
  
      for trial in self.nodejs_binding.list_trial_jobs():
          if len(trial.hyperParameters) != 1:
              # This trial is not submitted by the engine.
              _logger.warning(
                  'Found trial "%s" with unexpected number of parameters. '
                  "It may not be submitted by the engine. Skip.",
                  trial.trialJobId,
              )
              continue
  
          param = trial.hyperParameters[0]
          parameter_id = param.parameter_id
          model = self._find_reference_model(parameter_id)  # type: ignore
  
          # Check model status first to avoid loading the unneeded models.
          if model is not None:
              model_status = model.status
          else:
              model_status = self._interpret_trial_job_status(
                  trial.status
              )
          if status is not None and model_status != status:
              continue
  
          if model is None:
              # The model has been garbage-collected.
              # Load it from trial parameters.
  
              # The hyper-parameter is incorrectly loaded at NNI manager.
              # Dump and reload it here will turn it into a model.
              model: ExecutableModelSpace = nni.load(
                  nni.dump(param.parameters)
              )
              if not isinstance(model, ExecutableModelSpace):
                  _logger.error(
                      'The parameter of trial "%s" is not a model. Skip.',
                      trial.trialJobId,
                  )
                  continue
  
              model.status = model_status
              if trial.finalMetricData:
                  if len(trial.finalMetricData) != 1:
                      _logger.warning(
                          'The final metric data of trial "%s" is not a single value. Taking the last one.',
                          trial.trialJobId,
                      )
                  # The data has already been unpacked at the binding.
                  model.metrics.final = cast(
                      TrialMetric, trial.finalMetricData[-1].data
                  )
  
              if self.fetch_intermediates:
                  metrics = self.nodejs_binding.get_job_metrics(
                      trial.trialJobId
                  )
                  for metric_data in metrics.get(trial.trialJobId, []):
                      if metric_data.type == "PERIODICAL":
                          model.metrics.add_intermediate(
                              metric_data.data
                          )
  
          yield model
  
      # Yield models still in the cache, but not in the database.
      # This is to support the case where users call `list_models` instantly after submit models.
      # Models might take seconds to show up in the database.
      for model in self._submitted_cache.values():
          if status is None or model.status == status:
              yield model
  
imports: from __future__ import annotations
  import logging
  import sys
  import time
  import weakref
  from threading import Event, Thread
  from typing import Iterable, TYPE_CHECKING, Any, cast
  import nni
  from nni.runtime.tuner_command_channel import command_type, TunerCommandChannel
  from nni.typehint import TrialMetric
  from nni.utils import MetricType
  from nni.nas.space import ExecutableModelSpace, ModelStatus, GraphModelSpace
  from .engine import ExecutionEngine
  from .event import FinalMetricEvent, IntermediateMetricEvent, TrainingEndEvent
label_desc: Use image node_id 4 for calling the TrainingServiceExecutionEngine obj's underlying member method code with example usage: obj.list_models(status) without return types