class_docstr: PyTorch ONNX Export diagnostic engine.
  
  The only purpose of creating this class instead of using `DiagnosticContext` directly
  is to provide a background context for `diagnose` calls inside exporter.
  
  By design, one `torch.onnx.export` call should initialize one diagnostic context.
  All `diagnose` calls inside exporter should be made in the context of that export.
  However, since diagnostic context is currently being accessed via a global variable,
  there is no guarantee that the context is properly initialized. Therefore, we need
  to provide a default background context to fallback to, otherwise any invocation of
  exporter internals, e.g. unit tests, will fail due to missing diagnostic context.
  This can be removed once the pipeline for context to flow through the exporter is
  established.
class_docstr_tok: ["PyTorch","ONNX","Export","diagnostic","engine",".","The","only","purpose","of","creating","this","class","instead","of","using","`","DiagnosticContext","`","directly","is","to","provide","a","background","context","for","`","diagnose","`","calls","inside","exporter",".","By","design",",","one","`","torch.onnx.export","`","call","should","initialize","one","diagnostic","context",".","All","`","diagnose","`","calls","inside","exporter","should","be","made","in","the","context","of","that","export",".","However",",","since","diagnostic","context","is","currently","being","accessed","via","a","global","variable",",","there","is","no","guarantee","that","the","context","is","properly","initialized",".","Therefore",",","we","need","to","provide","a","default","background","context","to","fallback","to",",","otherwise","any","invocation","of","exporter","internals",",","e.g",".","unit","tests",",","will","fail","due","to","missing","diagnostic","context",".","This","can","be","removed","once","the","pipeline","for","context","to","flow","through","the","exporter","is","established","."]
code: def to_json(self) -> str:
      return formatter.sarif_to_json(self.sarif_log())
  
imports: from __future__ import annotations
  import contextlib
  import gzip
  from collections.abc import Generator
  from typing import List, Optional
  import torch
  from torch.onnx._internal.diagnostics import infra
  from torch.onnx._internal.diagnostics.infra import formatter, sarif
  from torch.onnx._internal.diagnostics.infra.sarif import version
  from torch.utils import cpp_backtrace
label_desc: Use image node_id 5 for calling the ExportDiagnosticEngine obj's underlying member method code with example usage: obj.to_json() and returns: formatter