Skip to content

Commit

Permalink
puntuation on docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
gsuarezr committed Feb 4, 2024
1 parent 0e322f2 commit 556a4ec
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 59 deletions.
30 changes: 15 additions & 15 deletions qutip/solver/heom/bofin_baths.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def correlation_function(self, t, **kwargs):
Returns
-------
The correlation function at time t as an array or float
The correlation function at time t as an array or float.
"""

def integrand(w, t):
Expand All @@ -407,11 +407,11 @@ def _bose_einstein(self, w):
Parameters
----------
w: float or array
Energy of the mode
Energy of the mode.
Returns
-------
The population of the mode with energy w
The population of the mode with energy w.
"""

if self.T is None:
Expand All @@ -433,11 +433,11 @@ def power_spectrum(self, w):
Parameters
----------
w: float or array
Energy of the mode
Energy of the mode.
Returns
----------
The power spectrum of the mode with energy w
The power spectrum of the mode with energy w.
"""

# For w=0, the result would have the form 0 * inf
Expand All @@ -458,11 +458,11 @@ def correlation_function_approx(self, t):
Parameters
----------
t: float or array
time to compute correlations
time to compute correlations.
Returns
----------
The correlation function of the bath at time t
The correlation function of the bath at time t.
"""

corr = np.zeros_like(t, dtype=complex)
Expand All @@ -486,11 +486,11 @@ def power_spectrum_approx(self, w):
Parameters
----------
w: float or array
Energy of the mode
Energy of the mode.
Returns
----------
The power spectrum of the mode with energy w
The power spectrum of the mode with energy w.
"""

S = np.zeros_like(w, dtype=float)
Expand All @@ -512,11 +512,11 @@ def spectral_density_approx(self, w):
Parameters
----------
w: float or array
Energy of the mode
Energy of the mode.
Returns
----------
The spectral density of the mode with energy w
The spectral density of the mode with energy w.
"""
J = self.power_spectrum_approx(w) / (self._bose_einstein(w) + 1) / 2
return J
Expand Down Expand Up @@ -619,11 +619,11 @@ def spectral_density(self, w):
Parameters
----------
w: float or array
Energy of the mode
Energy of the mode.
Returns
-------
The spectral density of the mode with energy w
The spectral density of the mode with energy w.
"""

return 2 * self.lam * self.gamma * w / (self.gamma**2 + w**2)
Expand Down Expand Up @@ -945,11 +945,11 @@ def spectral_density(self, w):
Parameters
----------
w: float or array
Energy of the mode
Energy of the mode.
Returns
-------
The spectral density of the mode with energy w
The spectral density of the mode with energy w.
"""

return self.lam**2 * self.gamma * w / ((w**2 - self.w0**2)**2
Expand Down
89 changes: 45 additions & 44 deletions qutip/solver/heom/bofin_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SpectralFitter:
at least twice the cutoff frequency of the desired spectral density.
J : np.array or callable
The spectral density to be fitted as an array or function
The spectral density to be fitted as an array or function.
"""

def __init__(self, T, Q, w, J):
Expand Down Expand Up @@ -69,7 +69,7 @@ def set_spectral_density(self, w, J):
def _meier_tannor_SD(w, a, b, c):
r"""
Underdamped spectral density used for fitting in Meier-Tannor form
(see Eq. 38 in the BoFiN paper, DOI: 10.1103/PhysRevResearch.5.013181)
(see Eq. 38 in the BoFiN paper, DOI: 10.1103/PhysRevResearch.5.013181).
$J(\omega) = \sum_{i=1}^{k} \\frac{2 \alpha_{i}^{2} \Gamma_{i} \omega
}{\left( \left( \omega + \Omega_{i}\right)^{2} + \Gamma_{i}^{2}
Expand Down Expand Up @@ -337,12 +337,13 @@ def get_fit(
Initial guesses for the parameters. Same structure as lower and
upper.
Note: If one of lower, upper, sigma, guesses is None, all are discarded
Note: If one of lower, upper, sigma, guesses is None,
all are discarded.
Returns
-------
* A Bosonic Bath created with the fit parameters with the original
correlation function (that was provided or interpolated)
correlation function (that was provided or interpolated).
* A dictionary containing the following information about the fit:
Nr:
The number of terms used to fit the real part of the
Expand Down Expand Up @@ -416,20 +417,20 @@ def _generate_bath(self, params_real, params_imag):
"""
Calculate the Matsubara coefficients and frequencies for the
fitted underdamped oscillators and generate the corresponding bosonic
bath
bath.
Parameters
----------
params_real : np.array
array of shape (N,3) where N is the number of fitted terms
for the real part
for the real part.
params_imag : np.imag
array of shape (N,3) where N is the number of fitted terms
for the imaginary part
for the imaginary part.
Returns
-------
A bosonic Bath constructed from the fitted exponents
A bosonic Bath constructed from the fitted exponents.
"""

a, b, c = params_real
Expand Down Expand Up @@ -461,13 +462,13 @@ class OhmicBath:
Q : Qobj
Operator describing the coupling between system and bath.
T : Float
Temperature of the bath
Temperature of the bath.
alpha : float
Coupling strength
Coupling strength.
wc : float
Cutoff parameter
s : float
Power of w in the spectral density
Power of w in the spectral density.
"""

def __init__(self, T, Q, alpha, wc, s):
Expand All @@ -489,11 +490,11 @@ def spectral_density(self, w):
Parameters
----------
w : float or array
Energy of the mode
Energy of the mode.
Returns
-------
The spectral density of the mode with energy w
The spectral density of the mode with energy w.
"""

return (self.alpha * w ** (self.s)
Expand All @@ -507,11 +508,11 @@ def correlation_function(self, t):
Parameters
----------
t : float or array
time
time.
Returns
-------
The correlation function at time t
The correlation function at time t.
"""

if self.T != 0:
Expand Down Expand Up @@ -544,7 +545,7 @@ def make_correlation_fit(
Provides a fit to the spectral density or corelation function
with N underdamped oscillators baths, This function gets the
number of harmonic oscillators based on reducing the normalized
root mean squared error below a certain threshold
root mean squared error below a certain threshold.
Parameters
----------
Expand All @@ -554,7 +555,7 @@ def make_correlation_fit(
rmse : float
Desired normalized root mean squared error. Only used if Nr and Ni
are not provided, defaults to 1e-4. The default is not good
when working with numbers much smaller than 0.1
when working with numbers much smaller than 0.1.
lower : list
lower bounds on the parameters for the fit. A list of size 3,
each containing the N lower bounds, The order of the parameters is
Expand All @@ -572,10 +573,10 @@ def make_correlation_fit(
upper.
Nr: int
The number of terms to use for the real part of the correlation
function
function.
Ni: int
The number of terms to use for the imaginary part of the
correlation function
correlation function.
Returns
-------
* A Bosonic Bath created with the fit parameters with the original
Expand Down Expand Up @@ -624,7 +625,7 @@ def make_spectral_fit(self, x, rmse=1e-5, lower=None, upper=None,
Provides a fit to the spectral density or corelation function
with N underdamped oscillators baths, This function gets the
number of harmonic oscillators based on reducing the normalized
root mean squared error below a certain threshold
root mean squared error below a certain threshold.
Parameters
----------
Expand All @@ -640,16 +641,16 @@ def make_spectral_fit(self, x, rmse=1e-5, lower=None, upper=None,
Number of underdamped oscillators for the real and imaginary
part if the method is correlation.
when set to None the number of oscillators is found according to
the rmse, and the Nk is set to 1
the rmse, and the Nk is set to 1.
rmse : float
Desired normalized root mean squared error. Only used if N is
not provided
not provided.
lower : list
lower bounds on the parameters for the fit.
upper: list
upper bounds on the parameters for the fit
upper bounds on the parameters for the fit.
sigma: float
uncertainty in the data considered for the fit
uncertainty in the data considered for the fit.
guesses : list
Initial guess for the parameters.
"""
Expand Down Expand Up @@ -685,24 +686,24 @@ def _unpack(params):

def _leastsq(func, y, x, guesses=None, lower=None, upper=None, sigma=None):
"""
Performs nonlinear least squares to fit the function func to x and y
Performs nonlinear least squares to fit the function func to x and y.
Parameters
----------
func : function
The function we wish to fit.
x : np.array
a numpy array containing the independent variable used for the fit
a numpy array containing the independent variable used for the fit.
y : np.array
a numpy array containing the dependent variable we use for the fit
a numpy array containing the dependent variable we use for the fit.
guesses : list
Initial guess for the parameters.
lower : list
lower bounds on the parameters for the fit.
upper : list
upper bounds on the parameters for the fit
upper bounds on the parameters for the fit.
sigma : float
uncertainty in the data considered for the fit
uncertainty in the data considered for the fit.
Returns
-------
Expand All @@ -728,18 +729,18 @@ def _leastsq(func, y, x, guesses=None, lower=None, upper=None, sigma=None):
def _rmse(func, x, y, a, b, c):
"""
Calculates the normalized root mean squared error for fits
from the fitted parameters a, b, c
from the fitted parameters a, b, c.
Parameters
----------
func : function
The approximated function for which we want to compute the rmse.
x: np.array
a numpy array containing the independent variable used for the fit
a numpy array containing the independent variable used for the fit.
y: np.array
a numpy array containing the dependent variable used for the fit
a numpy array containing the dependent variable used for the fit.
a, b, c : list
fitted parameters
fitted parameters.
Returns
-------
Expand All @@ -766,9 +767,9 @@ def _fit(func, C, t, N, default_guess_scenario='',
func : function
The function we wish to fit.
C : np.array
a numpy array containing the dependent variable used for the fit
a numpy array containing the dependent variable used for the fit.
t : np.array
a numpy array containing the independent variable used for the fit
a numpy array containing the independent variable used for the fit.
N : int
The number of modes / baths used for the fitting.
default_guess_scenario : str
Expand All @@ -781,9 +782,9 @@ def _fit(func, C, t, N, default_guess_scenario='',
lower : list
lower bounds on the parameters for the fit.
upper: list
upper bounds on the parameters for the fit
upper bounds on the parameters for the fit.
sigma: float
uncertainty in the data considered for the fit
uncertainty in the data considered for the fit.
Returns
-------
Expand Down Expand Up @@ -832,34 +833,34 @@ def _run_fit(funcx, y, x, final_rmse, default_guess_scenario=None, N=None,
It iteratively tries to fit the funcx to y on the interval x.
If N is provided the fit is done with N modes, if it is
None then this automatically finds the smallest number of modes that
whose mean squared error is smaller than final_rmse
whose mean squared error is smaller than final_rmse.
Parameters
----------
funcx : function
The function we wish to fit.
y : np.array
The function used for the fitting
The function used for the fitting.
x : np.array
a numpy array containing the independent variable used for the fit
a numpy array containing the independent variable used for the fit.
final_rmse : float
Desired normalized root mean squared error
Desired normalized root mean squared error.
default_guess_scenario : str
Determines how the default guesses and bounds are chosen (in the case
guesses or bounds are not specified). May be 'correlation_real',
'correlation_imag' or any other string. Any other string will use
guesses and bounds designed for the fitting of spectral densities.
N : optional , int
The number of modes used for the fitting, if not provided starts at
1 and increases until a desired RMSE is satisfied
1 and increases until a desired RMSE is satisfied.
sigma: float
uncertainty in the data considered for the fit
uncertainty in the data considered for the fit.
guesses : list
Initial guess for the parameters.
lower : list
lower bounds on the parameters for the fit.
upper: list
upper bounds on the parameters for the fit
upper bounds on the parameters for the fit.
Returns
-------
Expand Down

0 comments on commit 556a4ec

Please sign in to comment.