class_docstr: The tests in this section import code from the quantization docs and check that
  they actually run without errors. In cases where objects are undefined in the code snippet,
  they must be provided in the test. The imports seem to behave a bit inconsistently,
  they can be imported either in the test file or passed as a global input
class_docstr_tok: ["The","tests","in","this","section","import","code","from","the","quantization","docs","and","check","that","they","actually","run","without","errors",".","In","cases","where","objects","are","undefined","in","the","code","snippet",",","they","must","be","provided","in","the","test",".","The","imports","seem","to","behave","a","bit","inconsistently",",","they","can","be","imported","either","in","the","test","file","or","passed","as","a","global","input"]
docstr: This function reads in the code from the docs given a unique identifier.
  Most code snippets have a 2 space indentation, for other indentation levels,
  change the offset `arg`. the `short_snippet` arg can be set to allow for testing
  of smaller snippets, the check that this arg controls is used to make sure that
  we are not accidentally only importing a blank line or something.
docstr_tok: ["This","function","reads","in","the","code","from","the","docs","given","a","unique","identifier",".","Most","code","snippets","have","a","2","space","indentation",",","for","other","indentation","levels",",","change","the","offset","`","arg","`",".","the","`","short_snippet","`","arg","can","be","set","to","allow","for","testing","of","smaller","snippets",",","the","check","that","this","arg","controls","is","used","to","make","sure","that","we","are","not","accidentally","only","importing","a","blank","line","or","something","."]
code: def _get_code(
      self,
      path_from_pytorch,
      unique_identifier,
      offset=2,
      short_snippet=False,
  ):
      r"""
      This function reads in the code from the docs given a unique identifier.
      Most code snippets have a 2 space indentation, for other indentation levels,
      change the offset `arg`. the `short_snippet` arg can be set to allow for testing
      of smaller snippets, the check that this arg controls is used to make sure that
      we are not accidentally only importing a blank line or something.
      """
  
      def get_correct_path(path_from_pytorch):
          r"""
          Current working directory when CI is running test seems to vary, this function
          looks for docs relative to this test file.
          """
          core_dir = Path(__file__).parent
          assert core_dir.match("test/quantization/core/"), (
              "test_docs.py is in an unexpected location. If you've been "
              "moving files around, ensure that the test and build files have "
              "been updated to have the correct relative path between "
              "test_docs.py and the docs."
          )
          pytorch_root = core_dir.parent.parent.parent
          return pytorch_root / path_from_pytorch
  
      path_to_file = get_correct_path(path_from_pytorch)
      if path_to_file:
          file = open(path_to_file)
          content = file.readlines()
  
          # it will register as having a newline at the end in python
          if "\n" not in unique_identifier:
              unique_identifier += "\n"
  
          assert (
              unique_identifier in content
          ), f"could not find {unique_identifier} in {path_to_file}"
  
          # get index of first line of code
          line_num_start = content.index(unique_identifier) + 1
  
          # next find where the code chunk ends.
          # this regex will match lines that don't start
          # with a \n or "  " with number of spaces=offset
          r = r = re.compile("^[^\n," + " " * offset + "]")
          # this will return the line of first line that matches regex
          line_after_code = next(
              filter(r.match, content[line_num_start:])
          )
          last_line_num = content.index(line_after_code)
  
          # remove the first `offset` chars of each line and gather it all together
          code = "".join(
              [
                  x[offset:]
                  for x in content[line_num_start + 1 : last_line_num]
              ]
          )
  
          # want to make sure we are actually getting some code,
          assert last_line_num - line_num_start > 3 or short_snippet, (
              f"The code in {path_to_file} identified by {unique_identifier} seems suspiciously short:"
              f"\n\n###code-start####\n{code}###code-end####"
          )
          return code
  
      return None
  
file_path: pytorch/test/quantization/core/test_docs.py
imports: import re
  import contextlib
  from pathlib import Path
  import torch
  from torch.testing._internal.common_quantization import QuantizationTestCase, SingleLayerLinearModel
  from torch.testing._internal.common_quantized import override_quantized_engine
  from torch.testing._internal.common_utils import IS_ARM64
label_desc: Use image node_id 2 for calling the TestQuantizationDocs obj's underlying member method code with example usage: obj._get_code(path_from_pytorch, unique_identifier, offset, short_snippet) and returns: None, unknown, code