Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

optimize.differential_evolution

Finds a global minimum of a bounded multivariate function using stochastic, derivative-free differential evolution. It evolves a population of candidates and can optionally polish the best candidate.

How it works

The function maintains a population of candidate points, creates trial points by combining population members, and retains improvements across generations. It is stochastic and derivative-free, so it can explore broad bounded domains but may use more objective evaluations than gradient-based local methods.

Syntax

scipy.optimize.differential_evolution(func, bounds, args=(), strategy='best1bin', maxiter=1000, popsize=15, tol=0.01, mutation=(0.5, 1), recombination=0.7, rng=None, callback=None, disp=False, polish=True, init='latinhypercube', atol=0, updating='immediate', workers=1, constraints=(), x0=None, *, integrality=None, vectorized=False, seed=None)

Parameters

NameTypeDescription
funccallableObjective callable to minimize; it receives a candidate vector and may use extra positional arguments from args.
boundssequence or BoundsBounds for every optimization variable, supplied as (min, max) pairs or a Bounds object.
argstuple, optionalAdditional positional arguments passed to func.
strategystr, optionalEvolution strategy used to generate trial vectors.
maxiterint, optionalMaximum number of generations.
popsizeint, optionalPopulation-size multiplier.
tolfloat, optionalRelative convergence tolerance.
mutationfloat or tuple, optionalMutation constant, or a range from which it is sampled.
recombinationfloat, optionalCrossover probability.
rngGenerator or seed-like, optionalRandom-number generator or compatible seed specification.
callbackcallable, optionalCallback invoked during optimization.
dispbool, optionalWhether to print progress.

Returns

OptimizeResult containing the best solution, objective value, convergence information, and evaluation/status fields described on the documentation page.

Key points

  • Use it to seek a global minimum of a multivariate objective.
  • The method is derivative-free and does not require gradients.
  • It is suited to broad search domains where local gradient methods may be insufficient.
  • Each generation mutates population members to produce trial candidates.
  • Mutation combines existing candidates rather than constructing trials from one point alone.
  • Because the method is stochastic, reproducibility requires controlling its random-number generator.

Common mistakes

  • Expect a potentially high objective-evaluation cost compared with gradient-based optimization.

Example: Bounded global minimization

import numpy as np
from scipy.optimize import differential_evolution

def objective(x):
    return (x[0] - 1.5)**2 + (x[1] + 2.0)**2

result = differential_evolution(objective, [(-5, 5), (-5, 5)], rng=np.random.default_rng(7))
print(result.x)
print(result.fun)

Minimizes a two-variable quadratic over the supplied box bounds.

When to use it

Derivative-free parameter fitting

Optimize a simulation, calibration loss, or engineering objective without reliable derivatives.

Global exploration

Search a bounded, multimodal objective where a local starting point may be misleading.

Constrained design

Optimize objectives with nonlinear or linear constraints.

Parallel population evaluation

Evaluate expensive objectives concurrently across candidate points.

Interview questions

QHow does differential evolution search?

It is a stochastic, population-based global optimizer that does not require gradients. Each generation mutates candidates by mixing them with other population members, then evaluates trial candidates and retains improvements.

Follow-up: How would you make parallel evaluation possible? Use workers greater than one, which requires deferred updating; vectorized evaluation is another supported route when the objective accepts a population of points.

QWhat are the essential inputs and outputs?

Bounds define the candidate domain, and the objective callable receives a candidate vector. The result is an OptimizeResult containing the best solution and its objective value, along with solver status information.

Follow-up: What should be supplied for constrained problems? Pass constraint objects through constraints; integer-valued variables can additionally be specified with integrality.

QHow can convergence and final refinement be controlled?

The stopping test compares population energy spread with a tolerance-based threshold involving the mean energy and atol. Increasing maxiter or population size generally permits more search, while polish can refine the final candidate with a local method.

Follow-up: When might polishing be undesirable? Disable it when the extra local optimization cost is not wanted or when the final candidate should remain the raw evolutionary result.

  • scipy.optimize.Bounds
  • scipy.optimize.LinearConstraint
  • scipy.optimize.NonlinearConstraint
  • scipy.optimize.OptimizeResult
  • scipy.optimize.minimize

Source: differential_evolution. Checked 2026-10-15.