Downloading and Installation¶
Prerequisites¶
Lmfit works with Python versions 3.8 and higher. Version 0.9.15 is the final version to support Python 2.7.
- Lmfit requires the following Python packages, with versions given:
NumPy version 1.23 or higher.
SciPy version 1.8 or higher.
asteval version 1.0 or higher.
uncertainties version 3.2.2 or higher.
dill version 0.3.4 or higher.
All of these are readily available on PyPI, and are installed
automatically if installing with pip install lmfit
.
In order to run the test suite, the pytest, pytest-cov, and flaky packages are required. Some functionality requires the emcee (version 3+), corner, pandas, Jupyter, matplotlib, or numdifftools packages. These are not installed automatically, but we highly recommend each of them.
For building the documentation and generating the examples gallery, matplotlib, emcee (version 3+), corner, Sphinx, sphinx-gallery, jupyter_sphinx, ipykernel, Pillow, and SymPy are required. For generating the PDF documentation, the Python packages sphinxcontrib-svg2pdfconverter and cairosvg are also required, as well as the LaTex package Latexmk (which is included by default in some LaTex distributions).
Please refer to pyproject.toml
under project.optional-dependencies
for a list of all
dependencies that are needed if you want to participate in the development of lmfit.
You can install all these dependencies automatically by doing pip install lmfit[all]
,
or select only a subset (e.g., dev`
, doc
, or test
).
Please note: the “original” python setup.py install
is deprecated, but we will
provide a shim setup.py
file for as long as Python
and/or setuptools
allow the use of this legacy command.
Downloads¶
The latest stable version of lmfit is 1.3.2 and is available from PyPI. Check the Release Notes for a list of changes compared to earlier releases.
Installation¶
The easiest way to install lmfit is with:
pip install lmfit
For Anaconda Python, lmfit is not an official package, but several Anaconda channels provide it, allowing installation with (for example):
conda install -c conda-forge lmfit
Development Version¶
To get the latest development version from the lmfit GitHub repository, use:
git clone https://github.com/lmfit/lmfit-py.git
and install using:
pip install --upgrade build pip setuptools wheel
to install the required build dependencies and then do:
python -m build
pip install ".[all]"
to generate the wheel and install lmfit
with all its dependencies.
We welcome all contributions to lmfit! If you cloned the repository for this purpose, please read CONTRIBUTING.md for more detailed instructions.
Testing¶
A battery of tests scripts that can be run with the pytest testing framework
is distributed with lmfit in the tests
folder. These are automatically run
as part of the development process.
For any release or any master branch from the git repository, running pytest
should run all of these tests to completion without errors or failures.
Many of the examples in this documentation are distributed with lmfit in the
examples
folder, and should also run for you. Some of these examples assume
that matplotlib has been installed and is working correctly.
Acknowledgements¶
Many people have contributed to lmfit. The attribution of credit in a
project such as this is difficult to get perfect, and there are no doubt
important contributions that are missing or under-represented here. Please
consider this file as part of the code and documentation that may have bugs
that need fixing.
Some of the largest and most important contributions (in approximate order
of size of the contribution to the existing code) are from:
Matthew Newville wrote the original version and maintains the project.
Renee Otten wrote the brute force method, implemented the basin-hopping
and AMPGO global solvers, implemented uncertainty calculations for scalar
minimizers and has greatly improved the code, testing, and documentation
and overall project.
Till Stensitzki wrote the improved estimates of confidence intervals, and
contributed many tests, bug fixes, and documentation.
A. R. J. Nelson added differential_evolution, emcee, and greatly improved
the code, docstrings, and overall project.
Antonino Ingargiola wrote much of the high level Model code and has
provided many bug fixes and improvements.
Daniel B. Allan wrote much of the original version of the high level Model
code, and many improvements to the testing and documentation.
Austen Fox fixed many of the built-in model functions and improved the
testing and documentation of these.
Michal Rawlik added plotting capabilities for Models.
The method used for placing bounds on parameters was derived from the
clear description in the MINUIT documentation, and adapted from
J. J. Helmus's Python implementation in leastsqbounds.py.
E. O. Le Bigot wrote the uncertainties package, a version of which was
used by lmfit for many years, and is now an external dependency.
The original AMPGO code came from Andrea Gavana and was adopted for
lmfit.
The propagation of parameter uncertainties to uncertainties in a Model
was adapted from the excellent description at
https://www.astro.rug.nl/software/kapteyn/kmpfittutorial.html#confidence-and-prediction-intervals,
which references the original work of: J. Wolberg, Data Analysis Using the
Method of Least Squares, 2006, Springer.
Additional patches, bug fixes, and suggestions have come from Faustin
Carter, Christoph Deil, Francois Boulogne, Thomas Caswell, Colin Brosseau,
nmearl, Gustavo Pasquevich, Clemens Prescher, LiCode, Ben Gamari, Yoav
Roam, Alexander Stark, Alexandre Beelen, Andrey Aristov, Nicholas Zobrist,
Ethan Welty, Julius Zimmermann, Mark Dean, Arun Persaud, Ray Osborn, @lneuhaus,
Marcel Stimberg, Yoshiera Huang, Leon Foks, Sebastian Weigand, Florian LB,
Michael Hudson-Doyle, Ruben Verweij, @jedzill4, @spalato, Jens Hedegaard Nielsen,
Martin Majli, Kristian Meyer, @azelcer, Ivan Usov, and many others.
The lmfit code obviously depends on, and owes a very large debt to the code
in scipy.optimize. Several discussions on the SciPy-user and lmfit mailing
lists have also led to improvements in this code.
Copyright, Licensing, and Re-distribution¶
The LMFIT-py code is distributed under the following license:
BSD-3
Copyright 2022 Matthew Newville, The University of Chicago
Renee Otten, Brandeis University
Till Stensitzki, Freie Universitat Berlin
A. R. J. Nelson, Australian Nuclear Science and Technology Organisation
Antonino Ingargiola, University of California, Los Angeles
Daniel B. Allen, Johns Hopkins University
Michal Rawlik, Eidgenossische Technische Hochschule, Zurich
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Some code has been taken from the scipy library whose licence is below.
Copyright (c) 2001, 2002 Enthought, Inc.
All rights reserved.
Copyright (c) 2003-2019 SciPy Developers.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
a. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
b. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
c. Neither the name of Enthought nor the names of the SciPy Developers
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Some code has been taken from the AMPGO library of Andrea Gavana, which was
released under a MIT license.