class_docstr: Abstract base class for optimizer closures in Lightning.
  
  Formally, a closure is binding variables from an external scope to a function that does a computation on these
  variables without taking them explicitly as input. This has the benefit that a closure can be passed to an object
  which later can call it like a function but without requiring to pass in any arguments.
  
  This class provides a simple abstraction making the instance of this class callable like a function while capturing
  the closure result and caching it.
class_docstr_tok: ["Abstract","base","class","for","optimizer","closures","in","Lightning",".","Formally",",","a","closure","is","binding","variables","from","an","external","scope","to","a","function","that","does","a","computation","on","these","variables","without","taking","them","explicitly","as","input",".","This","has","the","benefit","that","a","closure","can","be","passed","to","an","object","which","later","can","call","it","like","a","function","but","without","requiring","to","pass","in","any","arguments",".","This","class","provides","a","simple","abstraction","making","the","instance","of","this","class","callable","like","a","function","while","capturing","the","closure","result","and","caching","it","."]
docstr: The cached result from the last time the closure was called.
  
  Once accessed, the internal reference gets reset and the consumer will have to hold on to the reference as long
  as necessary.
docstr_tok: ["The","cached","result","from","the","last","time","the","closure","was","called",".","Once","accessed",",","the","internal","reference","gets","reset","and","the","consumer","will","have","to","hold","on","to","the","reference","as","long","as","necessary","."]
code: def consume_result(self) -> T:
      """The cached result from the last time the closure was called.
  
      Once accessed, the internal reference gets reset and the consumer will have to hold on to the reference as long
      as necessary.
  
      """
      if self._result is None:
          raise MisconfigurationException(
              "The closure hasn't been executed."
              " HINT: did you call `optimizer_closure()` in your `optimizer_step` hook? It could also happen because"
              " the `optimizer.step(optimizer_closure)` call did not execute it internally."
          )
      result, self._result = self._result, None  # free memory
      return result
  
file_path: pytorch-lightning/src/lightning/pytorch/loops/optimization/closure.py
imports: from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Any, Dict, Generic, Optional, TypeVar
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
label_desc: Use image node_id 2 for calling the AbstractClosure obj's underlying member method code with example usage: obj.consume_result() and returns: result