class_docstr: Model space that keeps the original model and does no conversion of model format
  (in contrast to :class:`SimplifiedModelSpace` or :class:`~nni.nas.space.GraphModelSpace`).
  
  It's possible that strategies directly operate on this format of model space,
  but it will be very slow (since dealing with deep learning models directly) and inflexible.
  
  Therefore, this is almost only useful when strategies need to fuse the model space and evaluator,
  which requires source-code-level access to those two components.
  One typical use case is one-shot strategy.
  
  In the current version, :class:`RawFormatModelSpace` can't be serialized and sent to remote machines.
  
  Examples
  --------
  A simple example of using :class:`RawFormatModelSpace` is as follows::
  
      from nni.nas.nn.pytorch import ModelSpace
      class MyModelSpace(ModelSpace):
          ...
  
      evaluator = FunctionEvaluator(evaluate_fn, learning_rate=nni.choice('lr', [0.1, 1.0]))
      model_space = RawFormatModelSpace(MyModelSpace(), evaluator)
  
  The space can then be simplified and freezed::
  
      frozen_model = model_space.freeze({'layer1': 0, 'lr': 0.1})
  
  The frozen model can be instantiated and executed::
  
      model = frozen_model.executable_model()
      evaluator.evaluate(model)
class_docstr_tok: ["Model","space","that","keeps","the","original","model","and","does","no","conversion","of","model","format","(","in","contrast","to",":","class",":","`","SimplifiedModelSpace","`","or",":","class",":","`","~nni.nas.space.GraphModelSpace","`",")",".","It","'s","possible","that","strategies","directly","operate","on","this","format","of","model","space",",","but","it","will","be","very","slow","(","since","dealing","with","deep","learning","models","directly",")","and","inflexible",".","Therefore",",","this","is","almost","only","useful","when","strategies","need","to","fuse","the","model","space","and","evaluator",",","which","requires","source-code-level","access","to","those","two","components",".","One","typical","use","case","is","one-shot","strategy",".","In","the","current","version",",",":","class",":","`","RawFormatModelSpace","`","ca","n't","be","serialized","and","sent","to","remote","machines",".","Examples","--","--","--","--","A","simple","example","of","using",":","class",":","`","RawFormatModelSpace","`","is","as","follows",":",":","from","nni.nas.nn.pytorch","import","ModelSpace","class","MyModelSpace","(","ModelSpace",")",":","...","evaluator","=","FunctionEvaluator","(","evaluate_fn",",","learning_rate=nni.choice","(","'lr","'",",","[","0.1",",","1.0","]",")",")","model_space","=","RawFormatModelSpace","(","MyModelSpace","(",")",",","evaluator",")","The","space","can","then","be","simplified","and","freezed",":",":","frozen_model","=","model_space.freeze","(","{","'layer1","'",":","0",",","'lr","'",":","0.1","}",")","The","frozen","model","can","be","instantiated","and","executed",":",":","model","=","frozen_model.executable_model","(",")","evaluator.evaluate","(","model",")"]
docstr: Serialization of a :class:`RawFormatModelSpace` is not supported.
  
  Notes
  -----
  The potential issues with serialization are in two folds:
  
  1. The model space could be a deep learning model, and have been arbitrarily mutated by the strategy (e.g., one-shot).
     For example, one submodule is replaced by another, or a layer is removed.
     In this case, we surely cannot use the init arguments to recover the model.
  2. The model space could contain parameters (weights), that are meant to be part of the model space.
     (That's why we have :class:`RawFormatModelSpace` other than :class:`SimplifiedModelSpace`).
     In this case, we need to dump all the parameters, which could be potentially large and slow.
  
  One potential solution to this problem might be introducing an advanced version of ``nni.trace``,
  that allows users / strategies to define a function that recreates the current instance from scratch.
  This function must be runnable in a completely new isolated process.
  
  Another potential solution might be introducing several flags to evaluator to specific needs like one-shot.
  But I don't think it's a good idea, because I want to make the evaluator semantically simple.
docstr_tok: ["Serialization","of","a",":","class",":","`","RawFormatModelSpace","`","is","not","supported",".","Notes","--","--","-","The","potential","issues","with","serialization","are","in","two","folds",":","1",".","The","model","space","could","be","a","deep","learning","model",",","and","have","been","arbitrarily","mutated","by","the","strategy","(","e.g.",",","one-shot",")",".","For","example",",","one","submodule","is","replaced","by","another",",","or","a","layer","is","removed",".","In","this","case",",","we","surely","can","not","use","the","init","arguments","to","recover","the","model",".","2",".","The","model","space","could","contain","parameters","(","weights",")",",","that","are","meant","to","be","part","of","the","model","space",".","(","That","'s","why","we","have",":","class",":","`","RawFormatModelSpace","`","other","than",":","class",":","`","SimplifiedModelSpace","`",")",".","In","this","case",",","we","need","to","dump","all","the","parameters",",","which","could","be","potentially","large","and","slow",".","One","potential","solution","to","this","problem","might","be","introducing","an","advanced","version","of","``","nni.trace","``",",","that","allows","users","\/","strategies","to","define","a","function","that","recreates","the","current","instance","from","scratch",".","This","function","must","be","runnable","in","a","completely","new","isolated","process",".","Another","potential","solution","might","be","introducing","several","flags","to","evaluator","to","specific","needs","like","one-shot",".","But","I","do","n't","think","it","'s","a","good","idea",",","because","I","want","to","make","the","evaluator","semantically","simple","."]
code: def _dump(self) -> NoReturn:
      """Serialization of a :class:`RawFormatModelSpace` is not supported.
  
      Notes
      -----
      The potential issues with serialization are in two folds:
  
      1. The model space could be a deep learning model, and have been arbitrarily mutated by the strategy (e.g., one-shot).
         For example, one submodule is replaced by another, or a layer is removed.
         In this case, we surely cannot use the init arguments to recover the model.
      2. The model space could contain parameters (weights), that are meant to be part of the model space.
         (That's why we have :class:`RawFormatModelSpace` other than :class:`SimplifiedModelSpace`).
         In this case, we need to dump all the parameters, which could be potentially large and slow.
  
      One potential solution to this problem might be introducing an advanced version of ``nni.trace``,
      that allows users / strategies to define a function that recreates the current instance from scratch.
      This function must be runnable in a completely new isolated process.
  
      Another potential solution might be introducing several flags to evaluator to specific needs like one-shot.
      But I don't think it's a good idea, because I want to make the evaluator semantically simple.
      """
      raise NotImplementedError(
          "`_dump` is not implemented for {}".format(
              self.__class__.__name__
          )
      )
  
imports: from __future__ import annotations
  import weakref
  from copy import deepcopy
  from enum import Enum
  from typing import NoReturn, Any, Callable, Iterable
  from nni.common.serializer import is_traceable, SerializableObject
  from nni.nas.evaluator import Evaluator
  from nni.mutable import Mutable, Sample, MutableDict, LabeledMutable, SampleValidationError, frozen_factory
  from nni.typehint import TrialMetric
  from .frozen import model_context
  from .metrics import Metrics
label_desc: Use image node_id 9 for calling the RawFormatModelSpace obj's underlying member method code with example usage: obj._dump() without return types