Skip to content

Commit

Permalink
Applied changes suggested by @hodgestar
Browse files Browse the repository at this point in the history
  • Loading branch information
pmenczel committed Nov 25, 2024
1 parent 4f83ccb commit 03d1d61
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 91 deletions.
1 change: 1 addition & 0 deletions doc/apidoc/apidoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ complete list of QuTiP's public classes and functions.
quantumobject.rst
time_dep.rst
solver.rst
environments.rst
heom.rst
piqs.rst
visualization.rst
Expand Down
52 changes: 52 additions & 0 deletions doc/apidoc/environments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
************
Environments
************

Bosonic Environments
--------------------

.. autoclass:: qutip.core.BosonicEnvironment
:members:

.. autoclass:: qutip.core.DrudeLorentzEnvironment
:members:
:inherited-members:
:show-inheritance:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.UnderDampedEnvironment
:members:
:inherited-members:
:show-inheritance:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.OhmicEnvironment
:members:
:inherited-members:
:show-inheritance:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.CFExponent
:members:

.. autoclass:: qutip.core.ExponentialBosonicEnvironment
:members:
:show-inheritance:

.. autofunction:: qutip.core.environment.system_terminator


Fermionic Environments
----------------------

.. autoclass:: qutip.core.FermionicEnvironment
:members:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.LorentzianEnvironment
:members:
:show-inheritance:

.. autoclass:: qutip.core.ExponentialFermionicEnvironment
:members:
:show-inheritance:
55 changes: 0 additions & 55 deletions doc/apidoc/heom.rst
Original file line number Diff line number Diff line change
@@ -1,58 +1,3 @@
************
Environments
************

Bosonic Environments
--------------------

.. autoclass:: qutip.core.BosonicEnvironment
:members:

.. autoclass:: qutip.core.DrudeLorentzEnvironment
:members:
:inherited-members:
:show-inheritance:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.UnderDampedEnvironment
:members:
:inherited-members:
:show-inheritance:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.OhmicEnvironment
:members:
:inherited-members:
:show-inheritance:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.CFExponent
:members:

.. autoclass:: qutip.core.ExponentialBosonicEnvironment
:members:
:show-inheritance:

.. autofunction:: qutip.core.environment.system_terminator


Fermionic Environments
----------------------

.. autoclass:: qutip.core.FermionicEnvironment
:members:
:exclude-members: from_correlation_function, from_power_spectrum, from_spectral_density

.. autoclass:: qutip.core.LorentzianEnvironment
:members:
:show-inheritance:

.. autoclass:: qutip.core.ExponentialFermionicEnvironment
:members:
:show-inheritance:



********************************
Hierarchical Equations of Motion
********************************
Expand Down
2 changes: 1 addition & 1 deletion qutip/solver/brmesolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def brmesolve(
new_a_ops.append((a_op, spectra))
elif isinstance(spectra, BosonicEnvironment):
spec = SpectraCoefficient(
coefficient(lambda w: spectra.power_spectrum(w))
coefficient(spectra.power_spectrum)
)
new_a_ops.append((a_op, spec))
elif callable(spectra):
Expand Down
55 changes: 25 additions & 30 deletions qutip/solver/heom/bofin_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,9 @@ def _combine_bath_exponents(self, bath):
if (not isinstance(bath, (list, tuple))
or self._is_environment_api(bath)):
bath = [bath]
bath = [self._to_bath(b) for b in bath]
exponents = []
for b in bath:
if self._is_environment_api(b):
b = self._env_to_bath(b)
if (isinstance(b, (BosonicEnvironment, FermionicEnvironment))
and not isinstance(b, (BosonicBath, FermionicBath))):
raise ValueError("Environments must be passed with their"
" corresponding coupling operator as a list"
" or tuple (env, Q)")
exponents.extend(b.exponents)

if not all(exp.Q.dims == exponents[0].Q.dims for exp in exponents):
Expand All @@ -753,37 +747,38 @@ def _combine_bath_exponents(self, bath):
return exponents

def _is_environment_api(self, bath_spec):
is_list = isinstance(bath_spec, (list, tuple))
if not is_list:
if not isinstance(bath_spec, (list, tuple)) or len(bath_spec) < 2:
return False
env, Q, *args = bath_spec

starts_with_env = isinstance(
bath_spec[0], (BosonicEnvironment, FermionicEnvironment)
)
if not starts_with_env:
if not isinstance(env, (BosonicEnvironment, FermionicEnvironment)):
return False

contains_bath = any(
isinstance(elem, (Bath, BosonicBath, FermionicBath))
for elem in bath_spec
)
if contains_bath:
# Potentially confused user, passed mixed list of environments
# and baths. Error will be raised elsewhere.
if not isinstance(Q, (Qobj, QobjEvo)):
return False

return True

def _env_to_bath(self, bath_spec):
if isinstance(bath_spec[0], ExponentialBosonicEnvironment):
return BosonicBath.from_environment(*bath_spec)
if isinstance(bath_spec[0], ExponentialFermionicEnvironment):
return FermionicBath.from_environment(*bath_spec)
else:
raise ValueError("The HEOM solver requires the environment to have"
" a multi-exponential correlation function. Use"
" one of the `approx_by_` functions to generate a"
" multi-exponential approximation.")
def _to_bath(self, bath_spec):
if isinstance(bath_spec, (Bath, BosonicBath, FermionicBath)):
return bath_spec

if not self._is_environment_api(bath_spec):
raise ValueError(
"Environments must be passed as either Bath instances or"
" as a tuple or list corresponding to an environment and a"
" coupling operator, (env, Q)"
)
env, Q, *args = bath_spec

if isinstance(env, ExponentialBosonicEnvironment):
return BosonicBath.from_environment(env, Q, *args)
if isinstance(env, ExponentialFermionicEnvironment):
return FermionicBath.from_environment(env, Q, *args)
raise ValueError("The HEOM solver requires the environment to have"
" a multi-exponential correlation function. Use"
" one of the `approx_by_` functions to generate a"
" multi-exponential approximation.")

def _grad_n(self, he_n):
""" Get the gradient for the hierarchy ADO at level n. """
Expand Down
15 changes: 10 additions & 5 deletions qutip/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,18 @@ def _version2int(version_string):
#

def iterated_fit(
fun: Callable[..., complex], num_params: int,
xdata: ArrayLike, ydata: ArrayLike,
fun: Callable[..., complex],
num_params: int,
xdata: ArrayLike,
ydata: ArrayLike,
target_rmse: float = 1e-5,
Nmin: int = 1, Nmax: int = 10,
Nmin: int = 1,
Nmax: int = 10,
guess: ArrayLike | Callable[[int], ArrayLike] = None,
lower: ArrayLike = None, upper: ArrayLike = None,
sigma: float | ArrayLike = None, maxfev: int = None
lower: ArrayLike = None,
upper: ArrayLike = None,
sigma: float | ArrayLike = None,
maxfev: int = None
) -> tuple[float, ArrayLike]:
r"""
Iteratively tries to fit the given data with a model of the form
Expand Down

0 comments on commit 03d1d61

Please sign in to comment.