Convert list of phases or groups into a new PhaseGroup if not already.

def convert_if_not(cls, phases_or_groups):
    """Convert list of phases or groups into a new PhaseGroup if not already."""
    if isinstance(phases_or_groups, PhaseGroup):
      return mutablerecords.CopyRecord(phases_or_groups)

    flattened = flatten_phases_and_groups(phases_or_groups)
    return cls(main=flattened)