code: def test_nesting():
      def testing():
          with pyro.markov():
              v1 = pyro.to_data(
                  Tensor(
                      torch.ones(2),
                      OrderedDict([(str(1), funsor.Bint[2])]),
                      "real",
                  )
              )
              print(1, v1.shape)  # shapes should alternate
              assert v1.shape == (2,)
  
              with pyro.markov():
                  v2 = pyro.to_data(
                      Tensor(
                          torch.ones(2),
                          OrderedDict([(str(2), funsor.Bint[2])]),
                          "real",
                      )
                  )
                  print(2, v2.shape)  # shapes should alternate
                  assert v2.shape == (2, 1)
  
                  with pyro.markov():
                      v3 = pyro.to_data(
                          Tensor(
                              torch.ones(2),
                              OrderedDict([(str(3), funsor.Bint[2])]),
                              "real",
                          )
                      )
                      print(3, v3.shape)  # shapes should alternate
                      assert v3.shape == (2,)
  
                      with pyro.markov():
                          v4 = pyro.to_data(
                              Tensor(
                                  torch.ones(2),
                                  OrderedDict(
                                      [(str(4), funsor.Bint[2])]
                                  ),
                                  "real",
                              )
                          )
                          print(4, v4.shape)  # shapes should alternate
  
                          assert v4.shape == (2, 1)
  
      with pyro_backend("contrib.funsor"), NamedMessenger(
          first_available_dim=-1
      ):
          testing()
  
file_path: pyro/tests/contrib/funsor/test_named_handlers.py
imports: import logging
  from collections import OrderedDict
  import pytest
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: test_nesting() without return types