+++
title = "lmfit minimizer"
weight = 40
+++

## lmfit minimizer

This example demonstrates how to run a typical fitting task in BornAgain
using the [lmfit](https://lmfit.github.io/lmfit-py/) package.

```python
import lmfit

params = lmfit.Parameters()
params.add('radius', value=7*nm, min=5*nm, max=8*nm)
params.add('length', value=10*nm, min=8*nm, max=14*nm)

fit_objective = ba.FitObjective()
fit_objective.addFitPair(run_simulation, exp_data)
fit_objective.initPrint(10)

result = lmfit.minimize(fit_objective.evaluate_residuals, params)
print(lmfit.fit_report(result))
```

The complete script is shown below.

{{< show-ex file="fit/scatter2d/lmfit_basics.py" >}}
