Save variable calculated inside of logp function

Hard to say without seeing the actual implementation you’ve got. I would usually use a class to save state, but the deterministic approach should work. Can you share any more details?