def populate_from_model(mdl,
                        gap=0.1,
                        pool_intensity=4,
                        pool_capacity=None,
                        eps_diff=1e-7,
                        verbose=False):
    """ Runs populate on a model instance.

    :param mdl: a model instance.
    :param gap: MIP gap to use for the populate phase (default is 10%)
    :param pool_intensity: the value for the paramater mip.pool.intensity (defaut is 4)
    :param pool_capacity: the pool capacity (if any)
    :param eps_diff: precision to use for testing variable difference
    :param verbose: optional flag to print results.

    :return: the solution pool as returned by `docplex.mp.Model.populate()`
    """
    print(f"* running populate on model: '{mdl.name}', gap={gap}, intensity={pool_intensity}, capacity={pool_capacity}")
    # set the solution pool relative gap parameter to obtain solutions
    # of objective value within 10% of the optimal
    mdl.parameters.mip.pool.relgap = gap
    if pool_intensity is not None:
        assert 0 <= pool_intensity <= 4, f"Pool intensity must be in [0..4], {pool_intensity} was passed"
        mdl.parameters.mip.pool.intensity = pool_intensity
    if pool_capacity is not None:
        assert pool_capacity >= 1
        mdl.parameters.mip.pool.capacity = pool_capacity

    try:
        solnpool = mdl.populate_solution_pool(log_output=verbose)
    except Exception as ex:
        print("Exception raised during populate: {0}".format(str(ex)))
        return

    if not solnpool:
        print("! Model {0} fails to solve, no pool generated".format(mdl.name))

    print()
    print("* Solve status = '{0}'".format(mdl.solve_details.status))
    # Print information about the incumbent
    print()
    print("-- Objective value of the incumbent  = {0}".format(mdl.objective_value))
    sol = mdl.solution
    assert sol is not None

    # Print information about other solutions
    print()
    nb_pool_sols = solnpool.size
    print("-- The solution pool contains {0} solutions.".format(nb_pool_sols))

    numsolreplaced = solnpool.num_replaced
    print("-- %d solutions were removed due to the solution pool "
          "relative gap parameter." % numsolreplaced)

    print("* Pool objective statistics")
    solnpool.describe_objectives()

    print()
    print("#solution       objective       #var diff.")
    numcols = mdl.number_of_variables
    for s, sol_i in enumerate(solnpool, start=1):
        objval_i = sol_i.objective_value

        # compute the number of variables that differ in solution i and in the incumbent
        numdiff = 0
        for dv in mdl.iter_variables():
            dvv_i = sol_i[dv]
            dvv = sol[dv]
            if abs(dvv_i - dvv) >= eps_diff:
                numdiff += 1
        print("%-15s %-10g      %02d / %d" %
              (s, objval_i, numdiff, numcols))
    return solnpool