code: def test_plated_einsum_adjoint(
      einsum_impl, equation, plates, backend
  ):
      (
          inputs,
          outputs,
          sizes,
          operands,
          funsor_operands,
      ) = make_einsum_example(equation)
      sum_op, prod_op = BACKEND_ADJOINT_OPS[backend]
  
      with AdjointTape() as tape:
          fwd_expr = einsum_impl(
              equation, *funsor_operands, plates=plates, backend=backend
          )
      actuals = tape.adjoint(sum_op, prod_op, fwd_expr, funsor_operands)
  
      for operand in operands:
          pyro_require_backward(operand)
      expected_out = pyro_einsum(
          equation,
          *operands,
          modulo_total=False,
          plates=plates,
          backend=backend,
      )[0]
      expected_out._pyro_backward()
  
      for i, (inp, tv, fv) in enumerate(
          zip(inputs, operands, funsor_operands)
      ):
          actual = prod_op(actuals[fv], fv).reduce(
              sum_op, actuals[fv].input_vars - fv.input_vars
          )
          expected = tv._pyro_backward_result
          if inp:
              actual = actual.align(tuple(inp))
          assert isinstance(actual, funsor.Tensor)
          assert expected.shape == actual.data.shape
          assert torch.allclose(expected, actual.data, atol=1e-7)
  
file_path: funsor/test/test_adjoint.py
imports: from collections import OrderedDict
  import pytest
  import funsor
  import funsor.ops
  from funsor.adjoint import AdjointTape
  from funsor.domains import Bint
  from funsor.einsum import BACKEND_ADJOINT_OPS, einsum, naive_einsum, naive_plated_einsum
  from funsor.optimizer import apply_optimizer
  from funsor.sum_product import MarkovProduct, naive_sequential_sum_product, sequential_sum_product, sum_product
  from funsor.terms import Variable, reflect
  from funsor.testing import assert_close, make_einsum_example, make_plated_hmm_einsum, random_gaussian, random_tensor, xfail_param
  from funsor.util import get_backend
label_desc: Use image node_id 2 for calling a global function with example usage: test_plated_einsum_adjoint(einsum_impl, equation, plates, backend) without return types