To do this, both pilots must have a role to play in operation of the aircraft, agreed before the flight
Maybe I'm being slightly pedantic

BUT the second pilot must be REQUIRED to log P1.
In the case of Instrument training, the second safety pilot IS required. Not to say that he can log P1 for the entire duration of the flight, only the time the other pilot it under the hood (i.e. the SP is required). Typically this means that for a 1hr instrument training flight, the safety pilot can only log 0.7 P1 .
If I go flying with my buddy, and we agree that he does the radios before the flight, and I fly, then strictly speaking he is not entitled to log any time at all, as he is not required crew member. This all changes with multi pilot aircraft of course....