Minipyro trace does not look correct

I am using the cool minipyro.py standalone script to learn about pyro internals. I was assuming it is a working standalone thus I was following it line by line to understand. However when I got to the code for the trace effect handler what I saw did not make any sense to me.

‘’’
class trace(Messenger):
def enter(self):
super().enter()
self.trace = OrderedDict()
return self.trace

# trace illustrates why we need postprocess_message in addition to process_message:
# We only want to record a value after all other effects have been applied
def postprocess_message(self, msg):
    assert (
        msg["type"] != "sample" or msg["name"] not in self.trace
    ), "sample sites must have unique names"
    self.trace[msg["name"]] = msg.copy()

def get_trace(self, *args, **kwargs):
    self(*args, **kwargs)
    return self.trace

‘’’

It looks like it is missing the part that is adding enties to the OrderedDict.

Or am I missing something?

I think it happens on this line where msg dictionary contains all the info about the primitive site.

Ok thanks, but then I do not see where this postprocess message method is triggered…

Ah maybe I see now, it will be eventually triggered by the pyro sample statement

1 Like

If you are interested in how effect handlers (such as trace) work there is a Poutine: A Guide to Programming with Effect Handlers in Pyro tutorial about this topic.