code: def is_same_graph_with_merge(var1, var2, givens=None):
      """
      Merge-based implementation of `pytensor.graph.basic.is_same_graph`.
  
      See help on `pytensor.graph.basic.is_same_graph` for additional documentation.
  
      """
      from pytensor.graph.rewriting.basic import MergeOptimizer
  
      if givens is None:
          givens = {}
      # Copy variables since the MergeOptimizer will modify them.
      copied = copy.deepcopy([var1, var2, givens])
      vars = copied[0:2]
      givens = copied[2]
      # Create FunctionGraph.
      inputs = list(graph_inputs(vars))
      # The clone isn't needed as we did a deepcopy and we cloning will
      # break the mapping in givens.
      fgraph = pytensor.graph.fg.FunctionGraph(
          inputs, vars, clone=False
      )
      # Perform Variable substitution.
      for to_replace, replace_by in givens.items():
          fgraph.replace(to_replace, replace_by)
      # Perform merge optimization.
      MergeOptimizer().rewrite(fgraph)
      # When two variables perform the same computations, they will have the same
      # owner in the rewritten graph.
      # We need to be careful with the special case where the owner is None,
      # which happens when the graph is made of a single Variable.
      # We also need to make sure we replace a Variable if it is present in
      # `givens`.
      vars_replaced = [givens.get(v, v) for v in fgraph.outputs]
      o1, o2 = (v.owner for v in vars_replaced)
      if o1 is None and o2 is None:
          # Comparing two single-Variable graphs: they are equal if they are
          # the same Variable.
          return vars_replaced[0] == vars_replaced[1]
      else:
          return o1 is o2
  
file_path: pytensor/pytensor/graph/rewriting/utils.py
imports: import copy
  from collections.abc import Generator, Sequence
  from typing import TYPE_CHECKING, Optional, Union, cast
  import pytensor
  from pytensor.graph.basic import Apply, Variable, equal_computations, graph_inputs, vars_between
  from pytensor.graph.fg import FunctionGraph
  from pytensor.graph.rewriting.db import RewriteDatabaseQuery
label_desc: Use image node_id 2 for calling a global function with example usage: is_same_graph_with_merge(var1, var2, givens) and returns: unknown, unknown