class_docstr: Base class for NAS strategies.
  
  To explore a space with a strategy, use::
  
      strategy = MyStrategy()
      strategy(model_space, engine)
  
  The strategy has a :meth:`run` method, that defines the process of exploring a NAS space.
  
  Strategy is stateful. It might store information of the current :meth:`initialize` and :meth:`run` as member attributes.
  We do not allow :meth:`run` a strategy twice with same, or different model spaces.
  
  Subclass should override :meth:`_initialize` and :meth:`_run`,
  as well as :meth:`state_dict` and :meth:`load_state_dict` for checkpointing.
class_docstr_tok: ["Base","class","for","NAS","strategies",".","To","explore","a","space","with","a","strategy",",","use",":",":","strategy","=","MyStrategy","(",")","strategy","(","model_space",",","engine",")","The","strategy","has","a",":","meth",":","`","run","`","method",",","that","defines","the","process","of","exploring","a","NAS","space",".","Strategy","is","stateful",".","It","might","store","information","of","the","current",":","meth",":","`","initialize","`","and",":","meth",":","`","run","`","as","member","attributes",".","We","do","not","allow",":","meth",":","`","run","`","a","strategy","twice","with","same",",","or","different","model","spaces",".","Subclass","should","override",":","meth",":","`","_initialize","`","and",":","meth",":","`","_run","`",",","as","well","as",":","meth",":","`","state_dict","`","and",":","meth",":","`","load_state_dict","`","for","checkpointing","."]
docstr: List all the models that is ever searched by the engine.
  
  A typical use case of this is to get the top-performing models produced during :meth:`run`.
  
  The default implementation uses :meth:`~nni.nas.execution.ExecutionEngine.list_models` to
  retrieve a list of models from the execution engine.
  
  Parameters
  ----------
  sort
      Whether to sort the models by their metric (in descending order).
      If sorted is true, only models with "Trained" status and non-``None`` metric are returned.
  limit
      Limit the number of models to return.
  
  Returns
  -------
  An iterator of models.
docstr_tok: ["List","all","the","models","that","is","ever","searched","by","the","engine",".","A","typical","use","case","of","this","is","to","get","the","top-performing","models","produced","during",":","meth",":","`","run","`",".","The","default","implementation","uses",":","meth",":","`","~nni.nas.execution.ExecutionEngine.list_models","`","to","retrieve","a","list","of","models","from","the","execution","engine",".","Parameters","--","--","--","--","--","sort","Whether","to","sort","the","models","by","their","metric","(","in","descending","order",")",".","If","sorted","is","true",",","only","models","with","``","Trained","''","status","and","non-","``","None","``","metric","are","returned",".","limit","Limit","the","number","of","models","to","return",".","Returns","--","--","--","-","An","iterator","of","models","."]
code: def list_models(
      self, sort: bool = True, limit: int | None = None
  ) -> Iterator[ExecutableModelSpace]:
      """List all the models that is ever searched by the engine.
  
      A typical use case of this is to get the top-performing models produced during :meth:`run`.
  
      The default implementation uses :meth:`~nni.nas.execution.ExecutionEngine.list_models` to
      retrieve a list of models from the execution engine.
  
      Parameters
      ----------
      sort
          Whether to sort the models by their metric (in descending order).
          If sorted is true, only models with "Trained" status and non-``None`` metric are returned.
      limit
          Limit the number of models to return.
  
      Returns
      -------
      An iterator of models.
      """
      if self._status in (
          StrategyStatus.INITIALIZED,
          StrategyStatus.EMPTY,
      ):
          raise RuntimeError("Strategy has not been run.")
  
      if sort:
          models = [
              model
              for model in self.engine.list_models(
                  status=ModelStatus.Trained
              )
              if model.metric is not None
          ]
          if limit is not None and limit > len(models):
              _logger.warning(
                  "Only %d models are trained, but %d top models are requested.",
                  len(models),
                  limit,
              )
          yield from sorted(
              models,
              key=lambda m: cast(TrialMetric, m.metric),
              reverse=True,
          )[:limit]
  
      else:
          for i, model in enumerate(self.engine.list_models()):
              if limit is not None and i >= limit:
                  break
              yield model
  
imports: from __future__ import annotations
  import logging
  import time
  from enum import Enum
  from typing import Iterator, cast
  from nni.nas.execution import ExecutionEngine
  from nni.nas.space import ExecutableModelSpace, ModelStatus
  from nni.typehint import TrialMetric
label_desc: Use image node_id 13 for calling the Strategy obj's underlying member method code with example usage: obj.list_models(sort, limit) without return types