def bayesdb_generator_population(bdb, generator_id):
    """Return id of population of the generator with given `generator_id`."""
    sql = 'SELECT population_id FROM bayesdb_generator WHERE id = ?'
    cursor = bdb.sql_execute(sql, (generator_id,))
    try:
        row = cursor.next()
    except StopIteration:
        raise ValueError('No such generator: %s' % (repr(generator_id),))
    else:
        assert len(row) == 1
        return row[0]