class_docstr: Keeps track of random variables and their respective value variables during
  graph rewrites in `rv_values`
  
  When a random variable is replaced in a rewrite, this `Feature` automatically
  updates the `rv_values` mapping, so that the new variable is linked to the
  original value variable.
  
  In addition this `Feature` provides functionality to manually update a random
  and/or value variable. A mapping from the transformed value variables to the
  the original value variables is kept in `original_values`.
  
  Likewise, a `measurable_conversions` map is maintained, which holds
  information about un-valued and un-measurable variables that were replaced
  with measurable variables.  This information can be used to revert these
  rewrites.
docstr: Whenever a node is replaced during rewrite, we check if it had a value
  variable associated with it and map it to the new node.
docstr_tok: ["Whenever","a","node","is","replaced","during","rewrite",",","we","check","if","it","had","a","value","variable","associated","with","it","and","map","it","to","the","new","node","."]
code: def on_change_input(self, fgraph, node, i, r, new_r, reason=None):
      """
      Whenever a node is replaced during rewrite, we check if it had a value
      variable associated with it and map it to the new node.
      """
      r_value_var = self.rv_values.pop(r, None)
      if r_value_var is not None:
          self.rv_values[new_r] = r_value_var
          self.needs_measuring.add(new_r)
          if new_r.name is None:
              new_r.name = r.name
  
imports: import warnings
  from collections import deque
  from typing import Dict, List, Optional, Sequence, Tuple
  import pytensor.tensor
  from pytensor import config
  from pytensor.compile.mode import optdb
  from pytensor.graph.basic import Constant, Variable, ancestors, io_toposort, truncated_graph_inputs
  from pytensor.graph.features import Feature
  from pytensor.graph.fg import FunctionGraph
  from pytensor.graph.replace import clone_replace
  from pytensor.graph.rewriting.basic import ChangeTracker, EquilibriumGraphRewriter, GraphRewriter, node_rewriter, out2in
  from pytensor.graph.rewriting.db import LocalGroupDB, RewriteDatabase, RewriteDatabaseQuery, SequenceDB, TopoDB
  from pytensor.tensor.basic import Alloc
  from pytensor.tensor.elemwise import DimShuffle, Elemwise
  from pytensor.tensor.random.rewriting import local_subtensor_rv_lift
  from pytensor.tensor.rewriting.basic import register_canonicalize
  from pytensor.tensor.rewriting.math import local_exp_over_1_plus_exp
  from pytensor.tensor.rewriting.shape import ShapeFeature
  from pytensor.tensor.rewriting.uncanonicalize import local_max_and_argmax
  from pytensor.tensor.subtensor import AdvancedIncSubtensor, AdvancedIncSubtensor1, AdvancedSubtensor, AdvancedSubtensor1, IncSubtensor, Subtensor
  from pytensor.tensor.variable import TensorVariable
  from pymc.logprob.abstract import MeasurableVariable
  from pymc.logprob.utils import DiracDelta, indices_from_subtensor
label_desc: Use image node_id 4 for calling the PreserveRVMappings obj's underlying member method code with example usage: obj.on_change_input(fgraph, node, i, r, new_r, reason) without return types