class_docstr: Context manager to set a sample into context.
  Then the sample will be retrievable from an arbitrary level of function calls via :func:`current_frozen_context`.
  
  There are two use cases:
  
  1. Setting a global sample so that some modules can directly create the frozen version, rather than first-create-and-freeze.
  2. Sharing default / dry-run samples when the search space is dynamically created.
  
  The implementation is basically adding another layer of empty dict on top of a global stack.
  When retrieved, all dicts in the stack will be merged, from the bottom to the top.
  When updated, only the dict on the top will be updated.
  
  Parameters
  ----------
  sample
      The sample to be set into context.
  
  Returns
  -------
  Context manager that provides a frozen context.
  
  Examples
  --------
  ::
      def some_func():
          print(frozen_context.current()['learning_rate'])  # 0.1
  
      with frozen_context({'learning_rate': 0.1}):
          some_func()
class_docstr_tok: ["Context","manager","to","set","a","sample","into","context",".","Then","the","sample","will","be","retrievable","from","an","arbitrary","level","of","function","calls","via",":","func",":","`","current_frozen_context","`",".","There","are","two","use","cases",":","1",".","Setting","a","global","sample","so","that","some","modules","can","directly","create","the","frozen","version",",","rather","than","first-create-and-freeze",".","2",".","Sharing","default","\/","dry-run","samples","when","the","search","space","is","dynamically","created",".","The","implementation","is","basically","adding","another","layer","of","empty","dict","on","top","of","a","global","stack",".","When","retrieved",",","all","dicts","in","the","stack","will","be","merged",",","from","the","bottom","to","the","top",".","When","updated",",","only","the","dict","on","the","top","will","be","updated",".","Parameters","--","--","--","--","--","sample","The","sample","to","be","set","into","context",".","Returns","--","--","--","-","Context","manager","that","provides","a","frozen","context",".","Examples","--","--","--","--",":",":","def","some_func","(",")",":","print","(","frozen_context.current","(",")","[","'learning_rate","'","]",")","#","0.1","with","frozen_context","(","{","'learning_rate","'",":","0.1","}",")",":","some_func","(",")"]
docstr: Update the current dry run context.
  Only the topmost context will be updated.
  
  Parameters
  ----------
  sample
      The sample to be updated into context.
docstr_tok: ["Update","the","current","dry","run","context",".","Only","the","topmost","context","will","be","updated",".","Parameters","--","--","--","--","--","sample","The","sample","to","be","updated","into","context","."]
code: def update(sample: Sample) -> None:
      """
      Update the current dry run context.
      Only the topmost context will be updated.
  
      Parameters
      ----------
      sample
          The sample to be updated into context.
      """
      try:
          ctx = ContextStack.top(_FROZEN_CONTEXT_KEY)
          assert isinstance(ctx, dict)
          ctx.update(sample)
      except NoContextError:
          raise RuntimeError(
              "No frozen context is found. Please use frozen_context() to create one."
          )
  
file_path: nni/nni/mutable/frozen.py
imports: from __future__ import annotations
  import logging
  from contextlib import contextmanager
  from typing import Any, Callable
  from .mutable import Mutable, Sample
  from .utils import NoContextError, ContextStack
label_desc: Use image node_id 4 for calling the frozen_context obj's underlying member method code with example usage: obj.update(sample) without return types