code: def add_transition(self, transition: Transition) -> None:
      if len(self) == 0:
          # remember which optional fields should be filled
          for f in self.optional_field_exist:
              val = getattr(transition, f, None)
              if val is not None:
                  self.optional_field_exist[f] = True
  
      # check that later additions also fill the same optional fields
      for f, should_exist in self.optional_field_exist.items():
          val = getattr(transition, f, None)
          if (val is not None) != should_exist:
              raise ValueError(
                  f"Field {f} given val {val} whereas should_exist is {should_exist}."
              )
  
      self.transitions.append(transition)
  
imports: from abc import ABC, abstractmethod
  from dataclasses import asdict, dataclass, field, fields
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import reagent.core.types
  import torch
  import torch.nn.functional
label_desc: Use image node_id 3 for calling the Trajectory obj's underlying member method code with example usage: obj.add_transition(transition) without return types