code: def param(
      name,
      init_value=None,
      constraint=torch.distributions.constraints.real,
      event_dim=None,
  ):
      if event_dim is not None:
          raise NotImplementedError(
              "minipyro.plate does not support the event_dim arg"
          )
  
      def fn(init_value, constraint):
          if name in PARAM_STORE:
              unconstrained_value, constraint = PARAM_STORE[name]
          else:
              # Initialize with a constrained value.
              assert init_value is not None
              with torch.no_grad():
                  constrained_value = init_value.detach()
                  unconstrained_value = (
                      torch.distributions.transform_to(constraint).inv(
                          constrained_value
                      )
                  )
              unconstrained_value.requires_grad_()
              PARAM_STORE[name] = unconstrained_value, constraint
  
          # Transform from unconstrained space to constrained space.
          constrained_value = torch.distributions.transform_to(
              constraint
          )(unconstrained_value)
          constrained_value.unconstrained = weakref.ref(
              unconstrained_value
          )
          return constrained_value
  
      # if there are no active Messengers, we just draw a sample and return it as expected:
      if not PYRO_STACK:
          return fn(init_value, constraint)
  
      # Otherwise, we initialize a message...
      initial_msg = {
          "type": "param",
          "name": name,
          "fn": fn,
          "args": (init_value, constraint),
          "value": None,
      }
  
      # ...and use apply_stack to send it to the Messengers
      msg = apply_stack(initial_msg)
      return msg["value"]
  
imports: import random
  import warnings
  import weakref
  from collections import OrderedDict
  import numpy
  import torch
  from pyro.distributions import validation_enabled
label_desc: Use image node_id 4 for calling a global function with example usage: param(name, init_value, constraint, event_dim) and returns: msg, constrained_value, fn