code: def streamline(
      fgraph: FunctionGraph,
      thunks: Sequence[Callable[[], None]],
      order: Sequence[Apply],
      post_thunk_old_storage: Optional[list["StorageCellType"]] = None,
      no_recycling: Optional[list["StorageCellType"]] = None,
      nice_errors: bool = True,
  ) -> "BasicThunkType":
      """Construct a single thunk that runs a list of thunks.
  
      Parameters
      ----------
      fgraph
      thunks
          The list of program instructions.
      order
          The list of apply instances that gave rise to the thunks
          (same order as thunks).
      post_thunk_old_storage
          A list (corresponding to thunks, order) whose elements are lists of
          storage cells, that should be cleared after running thecorresponding
          thunk. A value of None disables this functionality.
      no_recycling
          Storage elements that cannot be 'recycled' by repeatedly executing the
          program. These storage elements are cleared before re-running.
      nice_errors
          Run in such a way that the double-traceback is printed. This costs a
          bit of performance in the inner python loop.
  
      """
      if no_recycling is None:
          no_recycling = []
  
      if len(thunks) != len(order):
          raise ValueError(
              "Length of thunks and order must match",
              (len(thunks), len(order)),
          )
  
      if post_thunk_old_storage:
          if len(thunks) != len(post_thunk_old_storage):
              raise ValueError(
                  "Length of thunks and post_thunk_old_storage must match",
                  (len(thunks), len(post_thunk_old_storage)),
              )
  
          def streamline_default_f():
              for x in no_recycling:
                  x[0] = None
              try:
                  for thunk, node, old_storage in zip(
                      thunks, order, post_thunk_old_storage
                  ):
                      thunk()
                      for old_s in old_storage:
                          old_s[0] = None
              except Exception:
                  raise_with_op(fgraph, node, thunk)
  
          f = streamline_default_f
      elif nice_errors:
  
          def streamline_nice_errors_f():
              for x in no_recycling:
                  x[0] = None
              try:
                  for thunk, node in zip(thunks, order):
                      thunk()
              except Exception:
                  raise_with_op(fgraph, node, thunk)
  
          f = streamline_nice_errors_f
      else:
          # don't worry about raise_with_op, just go a little faster.
          # there is a mix of python and c thunks
          def streamline_fast_f():
              for x in no_recycling:
                  x[0] = None
              for thunk in thunks:
                  thunk()
  
          f = streamline_fast_f
      return f
  
imports: import builtins
  import io
  import re
  import sys
  import traceback
  import warnings
  from collections import Counter, defaultdict
  from collections.abc import Iterable, Sequence
  from keyword import iskeyword
  from operator import itemgetter
  from tempfile import NamedTemporaryFile
  from textwrap import dedent, indent
  from typing import TYPE_CHECKING, Any, Callable, NoReturn, Optional, TextIO, TypeVar, Union, cast
  import numpy
  from pytensor import config, utils
  from pytensor.graph.basic import Apply, Constant, Variable
  from pytensor.graph.fg import FunctionGraph
label_desc: Use image node_id 2 for calling a global function with example usage: streamline(fgraph, thunks, order, post_thunk_old_storage, no_recycling, nice_errors) and returns: f