code: def test_convert_outer_out_to_in_mit_sot():
      """Test a single replacement with `convert_outer_out_to_in`.
  
      This should be a single MIT-SOT replacement.
      """
  
      rng_state = np.random.default_rng(1234)
      rng_tt = pytensor.shared(rng_state, name="rng", borrow=True)
      rng_tt.tag.is_rng = True
      rng_tt.default_update = rng_tt
  
      #
      # This is a very simple model with only one output, but multiple
      # taps/lags.
      #
      def input_step_fn(y_tm1, y_tm2, rng):
          y_tm1.name = "y_tm1"
          y_tm2.name = "y_tm2"
          return pt.random.normal(
              y_tm1 + y_tm2, 1.0, rng=rng, name="Y_t"
          )
  
      Y_rv, _ = pytensor.scan(
          fn=input_step_fn,
          outputs_info=[
              {
                  "initial": pt.as_tensor_variable(np.r_[-1.0, 0.0]),
                  "taps": [-1, -2],
              },
          ],
          non_sequences=[rng_tt],
          n_steps=10,
      )
  
      Y_rv.name = "Y_rv"
      Y_all = Y_rv.owner.inputs[0]
      Y_all.name = "Y_all"
  
      Y_obs = pt.as_tensor_variable(Y_rv.eval())
      Y_obs.name = "Y_obs"
  
      input_scan_args = ScanArgs.from_node(Y_rv.owner.inputs[0].owner)
  
      # TODO FIXME: Everything below needs to be replaced with explicit asserts
      # on the values in `input_scan_args`
  
      #
      # The corresponding log-likelihood
      #
      def output_step_fn(y_t, y_tm1, y_tm2):
          y_t.name = "y_t"
          y_tm1.name = "y_tm1"
          y_tm2.name = "y_tm2"
          logp = _logprob_helper(
              pt.random.normal(y_tm1 + y_tm2, 1.0), y_t
          )
          logp.name = "logp(y_t)"
          return logp
  
      Y_logp, _ = pytensor.scan(
          fn=output_step_fn,
          sequences=[{"input": Y_obs, "taps": [0, -1, -2]}],
          outputs_info=[{}],
      )
  
      #
      # Get the model output variable that corresponds to the response
      # `RandomVariable`
      #
      oo_idx, oo_var, io_var = get_random_outer_outputs(
          input_scan_args
      )[0]
  
      #
      # Convert the original model `Scan` into another `Scan` that's equivalent
      # to the log-likelihood `Scan` given above.
      # In other words, automatically construct the log-likelihood `Scan` based
      # on the model `Scan`.
  
      value_map = {Y_all: Y_obs}
      test_scan_args = convert_outer_out_to_in(
          input_scan_args,
          [oo_var],
          value_map,
          inner_out_fn=create_inner_out_logp,
      )
  
      scan_out, updates = construct_scan(test_scan_args)
  
      #
      # Evaluate the manually and automatically constructed log-likelihoods and
      # compare.
      #
      res = scan_out[oo_idx].eval()
      exp_res = Y_logp.eval()
  
      assert np.array_equal(res, exp_res)
  
imports: import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  from pytensor import Mode
  from pytensor.raise_op import assert_op
  from pytensor.scan.utils import ScanArgs
  from scipy import stats
  from pymc.logprob.abstract import _logprob_helper
  from pymc.logprob.basic import conditional_logp, logp
  from pymc.logprob.scan import construct_scan, convert_outer_out_to_in, get_random_outer_outputs
  from pymc.testing import assert_no_rvs
label_desc: Use image node_id 3 for calling a global function with example usage: test_convert_outer_out_to_in_mit_sot() and returns: pt, logp