<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _populate(cls, as_of=None, delete=False):
 """Populate the table with billing cycles starting from `as_of` Args: as_of (date):
 The date at which to begin the populating delete (bool):
 Should future billing cycles be deleted? """

        billing_cycle_helper = get_billing_cycle()
        billing_cycles_exist = BillingCycle.objects.exists()

        try:
            current_billing_cycle = BillingCycle.objects.as_of(date=as_of)
        except BillingCycle.DoesNotExist:
            current_billing_cycle = None

        # If no cycles exist then disable the deletion logic
        if not billing_cycles_exist:
            delete = False

        # Cycles exist, but a date has been specified outside of them
        if billing_cycles_exist and not current_billing_cycle:
            raise CannotPopulateForDateOutsideExistingCycles()

        # Omit the current billing cycle if we are deleting (as
        # deleting the current billing cycle will be a Bad Idea)
        omit_current = (current_billing_cycle and delete)

        stop_date = as_of + relativedelta(years=settings.SWIFTWIND_BILLING_CYCLE_YEARS)
        date_ranges = billing_cycle_helper.generate_date_ranges(as_of, stop_date=stop_date, omit_current=omit_current)
        date_ranges = list(date_ranges)

        beginning_date = date_ranges[0][0]

        with db_transaction.atomic():

            if delete:
                # Delete all the future unused transactions
                cls.objects.filter(start_date__gte=beginning_date).delete()

            for start_date, end_date in date_ranges:
                exists = BillingCycle.objects.filter(date_range=(start_date, end_date)).exists()
                if exists:
                    if delete:
                        raise Exception(
                            'It should not be possible to get here as future billing cycles have just been deleted'
                        )
                    else:
                        # We're updating, so we can just ignore cycles that already exist
                        pass
                else:
                    BillingCycle.objects.create(
                        date_range=(start_date, end_date),
                    )