code: def add_opts_to_inner_graphs(fgraph, node):
      """Update the `Mode`(s) used to compile the inner-graph of a `Scan` `Op`.
  
      This is how we add the measurable IR rewrites to the "body"
      (i.e. inner-graph) of a `Scan` loop.
      """
  
      if isinstance(node.op, Subtensor):
          node = node.inputs[0].owner
          if not (node and isinstance(node.op, Scan)):
              return None
  
      # TODO: This might not be needed now that we only target relevant nodes
      # Avoid unnecessarily re-applying this rewrite
      if getattr(node.op.mode, "had_logprob_rewrites", False):
          return None
  
      inner_rv_values = {
          out: out.type() for out in node.op.inner_outputs
      }
      ir_rewriter = logprob_rewrites_db.query(
          RewriteDatabaseQuery(include=["basic"])
      )
      inner_fgraph, rv_values, _ = construct_ir_fgraph(
          inner_rv_values, ir_rewriter=ir_rewriter
      )
  
      new_outputs = list(inner_fgraph.outputs)
  
      # TODO FIXME: This is pretty hackish.
      new_mode = copy(node.op.mode)
      new_mode.had_logprob_rewrites = True
  
      op = Scan(
          node.op.inner_inputs, new_outputs, node.op.info, mode=new_mode
      )
      new_node = op.make_node(*node.inputs)
  
      return dict(zip(node.outputs, new_node.outputs))
  
imports: from copy import copy
  from typing import Callable, Dict, Iterable, List, Optional, Tuple, cast
  import numpy
  import pytensor
  import pytensor.tensor
  from pytensor.graph.basic import Variable
  from pytensor.graph.op import compute_test_value
  from pytensor.graph.rewriting.basic import node_rewriter
  from pytensor.graph.rewriting.db import RewriteDatabaseQuery
  from pytensor.scan.op import Scan
  from pytensor.scan.rewriting import scan_eqopt1, scan_eqopt2
  from pytensor.scan.utils import ScanArgs
  from pytensor.tensor.random.type import RandomType
  from pytensor.tensor.subtensor import Subtensor, indices_from_subtensor
  from pytensor.tensor.variable import TensorVariable
  from pytensor.updates import OrderedUpdates
  from pymc.logprob.abstract import MeasurableVariable, _logprob
  from pymc.logprob.basic import conditional_logp
  from pymc.logprob.rewriting import PreserveRVMappings, construct_ir_fgraph, inc_subtensor_ops, logprob_rewrites_db, measurable_ir_rewrites_db
  from pymc.logprob.utils import replace_rvs_by_values
label_desc: Use image node_id 6 for calling a global function with example usage: add_opts_to_inner_graphs(fgraph, node) and returns: dict, None, None