code: def test_least_squares_with_bounds():
      """Test least_squares algorihhm with bounds."""
      # define "true" parameters
      p_true = lmfit.Parameters()
      p_true.add("amp", value=14.0)
      p_true.add("period", value=5.4321)
      p_true.add("shift", value=0.12345)
      p_true.add("decay", value=0.01000)
  
      def residual(pars, x, data=None):
          """Objective function of decaying sine wave."""
          amp = pars["amp"]
          per = pars["period"]
          shift = pars["shift"]
          decay = pars["decay"]
  
          if abs(shift) > np.pi / 2:
              shift = shift - np.sign(shift) * np.pi
  
          model = (
              amp
              * np.sin(shift + x / per)
              * np.exp(-x * x * decay * decay)
          )
          if data is None:
              return model
          return model - data
  
      # generate synthetic data
      np.random.seed(0)
      x = np.linspace(0.0, 250.0, 1500)
      noise = np.random.normal(scale=2.80, size=x.size)
      data = residual(p_true, x) + noise
  
      # create Parameters and set initial values and bounds
      fit_params = lmfit.Parameters()
      fit_params.add("amp", value=13.0, min=0.0, max=20)
      fit_params.add("period", value=2, max=10)
      fit_params.add(
          "shift", value=0.0, min=-np.pi / 2.0, max=np.pi / 2.0
      )
      fit_params.add("decay", value=0.02, min=0.0, max=0.10)
  
      mini = lmfit.Minimizer(residual, fit_params, fcn_args=(x, data))
      out = mini.minimize(method="least_squares")
  
      assert out.method == "least_squares"
      assert out.nfev > 10
      assert out.nfree > 50
      assert out.chisqr > 1.0
      assert out.errorbars
      assert out.success
      assert_allclose(out.params["decay"], p_true["decay"], rtol=1e-2)
      assert_allclose(out.params["shift"], p_true["shift"], rtol=1e-2)
  
file_path: lmfit-py/tests/test_least_squares.py
imports: import numpy
  from numpy.testing import assert_allclose
  import pytest
  from scipy.sparse import bsr_matrix
  from scipy.sparse.linalg import aslinearoperator
  import lmfit
  from lmfit.models import VoigtModel
label_desc: Use image node_id 1 for calling a global function with example usage: test_least_squares_with_bounds() and returns: unknown, model