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

SciPy · Function

optimize.dual_annealing

Finds a global minimum of a bounded objective with dual annealing, optionally followed by local refinement. It returns an OptimizeResult describing the best point and termination state.

How it works

dual_annealing explores a bounded objective with a temperature-controlled stochastic search, periodically reheating when the temperature falls to a specified fraction. It can optionally refine promising points with a local minimizer and accepts fixed extra arguments through args.

Syntax

scipy.optimize.dual_annealing(func, bounds, args=(), maxiter=1000, minimizer_kwargs=None, initial_temp=5230.0, restart_temp_ratio=2e-5, visit=2.62, accept=-5.0, maxfun=10000000.0, rng=None, no_local_search=False, callback=None, x0=None, *, seed=None)

Parameters

NameTypeDescription
funccallableObjective callable accepting x as a one-dimensional array and optional fixed arguments.
boundssequence or BoundsFinite variable bounds, supplied as Bounds or (min, max) pairs.
argstuple, optionalExtra fixed arguments passed to func.
maxiterint, optionalMaximum number of global-search iterations.
minimizer_kwargsdict, optionalOptions forwarded to the local minimizer.
initial_tempfloat, optionalStarting temperature for the annealing schedule.
restart_temp_ratiofloat, optionalTemperature ratio that triggers reannealing.
visitfloat, optionalVisiting-distribution parameter.
acceptfloat, optionalAcceptance-probability parameter.
maxfunint, optionalMaximum objective-function evaluations.
rngint, Generator, optionalRandom-number generator or seed control.
no_local_searchbool, optionalDisable local minimization when true.

Returns

OptimizeResult containing the best solution, objective value, termination status, message, evaluation count, and iteration count.

Key points

  • Use dual_annealing when the objective may contain multiple local minima and a bounded global search is desired.
  • Define the objective with a one-dimensional variable array; pass fixed model data separately through args.
  • Bounds may be supplied as one lower-upper pair per decision variable.
  • Increasing initial_temp broadens early exploration and helps the algorithm escape local minima.
  • restart_temp_ratio determines when the cooling schedule is restarted.
  • A larger visit value produces more distant trial jumps, increasing exploratory reach.

Common mistakes

  • Setting no_local_search=True disables the local refinement stage, which can change the final result and convergence behavior.

Example: Bounded global minimization

import numpy as np
from scipy.optimize import dual_annealing

def objective(x):
    return np.sum(x**2) + 0.2 * np.sin(5 * x[0])

result = dual_annealing(objective, [(-5, 5), (-5, 5)], seed=0)
print(result.x)
print(result.fun)

Minimizes a bounded two-variable objective and prints the best point and objective value.

When to use it

Global search over nonconvex functions

The objective is multimodal and derivative-free optimization is needed.

Hybrid global-local optimization

A good global candidate should be polished with a local method.

Constrained parameter tuning

The model has bounded physical or design variables.

Interview questions

QWhat problem does dual_annealing solve?

The function performs global minimization using dual annealing over finite bounds. It combines stochastic exploration with optional local minimization of promising points.

Follow-up: How would you increase exploration? Raise initial_temp or visit, while recognizing that higher exploration can require more evaluations.

QWhat are the required inputs?

func receives a one-dimensional array x and any fixed parameters supplied through args. bounds can be a Bounds object or a sequence of lower-upper pairs.

Follow-up: Why must bounds be finite? They define the constrained search region and the number of variables.

QHow do the main exploration controls work?

The temperature decreases during annealing, and reannealing starts when it reaches initial_temp multiplied by restart_temp_ratio. The visit parameter controls the visiting distribution, while accept controls acceptance probability.

Follow-up: How can local refinement be customized? Supply minimizer_kwargs for the local minimizer and leave no_local_search false.

  • scipy.optimize.minimize
  • scipy.optimize.Bounds
  • scipy.optimize.OptimizeResult

Source: dual_annealing — SciPy v1.18.0 Manual. Checked 2026-10-15.