docs: def fast_sweep_time_evolution(Ep, epsilonp, gamma,
                                omega_level, rm, xi, theta,
                                semi_analytic=True,
                                file_name=None, return_code=False):
      r"""Return a spectrum of time evolutions of the density matrix.
  
      We test a basic two-level system.
  
      >>> import numpy as np
      >>> from sympy import symbols
      >>> from scipy.constants import physical_constants
  
      >>> e_num = physical_constants["elementary charge"][0]
      >>> hbar_num = physical_constants["Planck constant over 2 pi"][0]
  
      >>> Ne = 2
      >>> Nl = 1
      >>> Ep = [-1.0]
      >>> epsilonp = [np.array([0, 0, 1.0])]
      >>> delta = symbols("delta")
  
      >>> detuning_knob = [delta]
      >>> gamma = np.array([[0.0, -1.0], [1.0, 0.0]])
      >>> omega_level = np.array([0.0, 100.0])
      >>> rm = [np.array([[0.0, 0.0], [1.0, 0.0]])*hbar_num/e_num
      ...       for p in range(3)]
      >>> xi = np.array([[[0, 1], [1, 0]]])
      >>> theta = phase_transformation(Ne, Nl, rm, xi)
      >>> sweep_time_evolution = fast_sweep_time_evolution(Ep, epsilonp, gamma,
      ...                                                  omega_level, rm, xi,
      ...                                                  theta)
  
      >>> t = np.linspace(0, 1e1, 11)
      >>> unfolding = Unfolding(Ne, True, True, True)
      >>> rho0 = np.array([[1, 0], [0, 0]])
      >>> rho0 = unfolding(rho0)
  
      >>> deltas, rho = sweep_time_evolution(t, rho0, [[-20, 20, 5]])
      >>> print(rho.shape)
      (5, 11, 3)
      >>> print(rho)
      [[[ 0.0000e+00  0.0000e+00  0.0000e+00]
        [ 5.6205e-04 -1.8774e-02 -1.4437e-02]
        [ 1.0302e-03 -3.1226e-02 -7.3031e-03]
        [ 9.1218e-04 -3.0149e-02  1.3325e-03]
        [ 6.3711e-04 -2.5073e-02  2.7437e-03]
        [ 5.3438e-04 -2.3100e-02  2.2977e-04]
        [ 5.8098e-04 -2.4044e-02 -1.4626e-03]
        [ 6.3808e-04 -2.5209e-02 -1.3291e-03]
        [ 6.4675e-04 -2.5407e-02 -6.4498e-04]
        [ 6.2948e-04 -2.5071e-02 -3.7457e-04]
        [ 6.1812e-04 -2.4841e-02 -4.9967e-04]]
      <BLANKLINE>
       [[ 0.0000e+00  0.0000e+00  0.0000e+00]
        [ 5.8142e-03 -7.4650e-02  1.3859e-02]
        [ 2.2458e-03 -4.3027e-02 -1.9436e-02]
        [ 2.2788e-03 -4.6867e-02  8.1709e-03]
        [ 3.0571e-03 -5.4724e-02 -6.7300e-03]
        [ 2.0980e-03 -4.5626e-02 -2.2121e-03]
        [ 2.6866e-03 -5.1685e-02 -1.1906e-03]
        [ 2.4351e-03 -4.9072e-02 -3.8467e-03]
        [ 2.4572e-03 -4.9419e-02 -1.6141e-03]
        [ 2.5241e-03 -5.0036e-02 -2.8327e-03]
        [ 2.4491e-03 -4.9304e-02 -2.4541e-03]]
      <BLANKLINE>
       [[ 0.0000e+00  0.0000e+00  0.0000e+00]
        [ 1.4361e-01  0.0000e+00 -3.4458e-01]
        [ 3.0613e-01  0.0000e+00 -4.1373e-01]
        [ 3.6110e-01  0.0000e+00 -3.7387e-01]
        [ 3.5427e-01  0.0000e+00 -3.3710e-01]
        [ 3.3835e-01  0.0000e+00 -3.2630e-01]
        [ 3.3135e-01  0.0000e+00 -3.2873e-01]
        [ 3.3115e-01  0.0000e+00 -3.3244e-01]
        [ 3.3261e-01  0.0000e+00 -3.3388e-01]
        [ 3.3343e-01  0.0000e+00 -3.3383e-01]
        [ 3.3355e-01  0.0000e+00 -3.3348e-01]]
      <BLANKLINE>
       [[ 0.0000e+00  0.0000e+00  0.0000e+00]
        [ 5.8142e-03  7.4650e-02  1.3859e-02]
        [ 2.2458e-03  4.3027e-02 -1.9436e-02]
        [ 2.2788e-03  4.6867e-02  8.1709e-03]
        [ 3.0571e-03  5.4724e-02 -6.7300e-03]
        [ 2.0980e-03  4.5626e-02 -2.2121e-03]
        [ 2.6866e-03  5.1685e-02 -1.1906e-03]
        [ 2.4351e-03  4.9072e-02 -3.8467e-03]
        [ 2.4572e-03  4.9419e-02 -1.6141e-03]
        [ 2.5241e-03  5.0036e-02 -2.8327e-03]
        [ 2.4491e-03  4.9304e-02 -2.4541e-03]]
      <BLANKLINE>
       [[ 0.0000e+00  0.0000e+00  0.0000e+00]
        [ 5.6205e-04  1.8774e-02 -1.4437e-02]
        [ 1.0302e-03  3.1226e-02 -7.3031e-03]
        [ 9.1218e-04  3.0149e-02  1.3325e-03]
        [ 6.3711e-04  2.5073e-02  2.7437e-03]
        [ 5.3438e-04  2.3100e-02  2.2977e-04]
        [ 5.8098e-04  2.4044e-02 -1.4626e-03]
        [ 6.3808e-04  2.5209e-02 -1.3291e-03]
        [ 6.4675e-04  2.5407e-02 -6.4498e-04]
        [ 6.2948e-04  2.5071e-02 -3.7457e-04]
        [ 6.1812e-04  2.4841e-02 -4.9967e-04]]]
  
      >>> deltas, rho = sweep_time_evolution(t, rho0, [[-20, 20, 11]],
      ...                                    average=True)
      >>> print(rho)
      [[ 0.0006 -0.024  -0.0021]
       [ 0.0011 -0.0308 -0.0007]
       [ 0.0016 -0.0375  0.0024]
       [ 0.0041 -0.0604 -0.0061]
       [ 0.016  -0.1175 -0.0118]
       [ 0.2999  0.     -0.3291]
       [ 0.016   0.1175 -0.0118]
       [ 0.0041  0.0604 -0.0061]
       [ 0.0016  0.0375  0.0024]
       [ 0.0011  0.0308 -0.0007]
       [ 0.0006  0.024  -0.0021]]
  
      """
      # We unpack variables.
      if True:
          Nl = xi.shape[0]
      # We determine which arguments are constants.
      if True:
          try:
              Ep = np.array([complex(Ep[l]) for l in range(Nl)])
              variable_Ep = False
          except:
              variable_Ep = True
  
          try:
              epsilonp = [np.array([complex(epsilonp[l][i]) for i in range(3)])
                          for l in range(Nl)]
              variable_epsilonp = False
          except:
              variable_epsilonp = True
      # We obtain code for the time evolution.
      if True:
          detuning_knob = symbols("delta1:"+str(Nl))
          args = (Ep, epsilonp, detuning_knob, gamma, omega_level, rm, xi, theta,
                  file_name, True)
  
          args = (Ep, epsilonp, detuning_knob, gamma, omega_level, rm, xi,
                  theta, True, file_name, True)
          time_evolution = fast_time_evolution(*args)
          code = time_evolution+"\n\n"
      # We establish the arguments of the output function.
      if True:
          code += "def sweep_time_evolution(t, rho0, "
          if variable_Ep: code += "Ep, "
          if variable_epsilonp: code += "epsilonp, "
          code += "detuning_knob, average=False, "
          code += "time_evolution=time_evolution):\n"
          code += '    r"""A fast frequency sweep of the steady state."""\n'
      # Code to determine the sweep range.
      if True:
          code += """    sweepN = -1\n"""
          code += """    for i, delta in enumerate(detuning_knob):\n"""
          code += """        if hasattr(delta, "__getitem__"):\n"""
          code += """            sweepN = i\n"""
          code += """            delta0 = delta[0]\n"""
          code += """            deltaf = delta[1]\n"""
          code += """            Ndelta = delta[2]\n"""
          code += """            break\n\n"""
          code += """    if sweepN == -1:\n"""
          code += """        s = 'One of the detuning knobs '\n"""
          code += """        s += 'must be of the form '\n"""
          code += """        s += '(start, stop, Nsteps)'\n"""
          code += """        raise ValueError(s)\n\n"""
          code += """    deltas = np.linspace(delta0, deltaf, Ndelta)\n\n"""
      # We call time_evolution.
      if True:
          code += "    args = [[t, rho0, "
          if variable_Ep: code += "Ep, "
          if variable_epsilonp: code += "epsilonp, "
          code += """list(detuning_knob[:sweepN]) +\n"""
          code += """            [deltas[i]] +\n"""
          code += """            list(detuning_knob[sweepN+1:]), average]\n"""
          code += """          for i in range(Ndelta)]\n\n"""
          code += "    rho = np.array([time_evolution(*argsi)\n"
          code += "                   for argsi in args])\n\n"
      # We finish the code.
      if True:
          code += "    return deltas, rho\n"
      # We write the code to file if provided, and execute it.
      if True:
          if file_name is not None:
              f = file(file_name+".py", "w")
              f.write(code)
              f.close()
  
          sweep_time_evolution = code
          if not return_code:
              exec sweep_time_evolution
      return sweep_time_evolution