Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEOM Parity support #2261

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1a2e5d0
Added FitBath and OhmicBath classes, fix spelling on solver_base
gsuarezr Oct 11, 2023
27ed772
notebooks as example
gsuarezr Oct 11, 2023
3ba219d
formatting
gsuarezr Oct 11, 2023
40a914d
added tests
gsuarezr Oct 13, 2023
3edecc0
Merge branch 'qutip:master' into master
gsuarezr Oct 19, 2023
f51033a
Make fit classes inherit, which broke tests, refactored functions and…
gsuarezr Oct 19, 2023
c880375
minor refactoring
gsuarezr Oct 24, 2023
7080102
replaced tests to match new classes
gsuarezr Oct 24, 2023
390c596
added parity support changed prints to __str__
gsuarezr Oct 25, 2023
fa563b5
deleted innecessary comments and code
gsuarezr Oct 25, 2023
c6a7d4e
Rewrote summary methods,added comments,eliminated unnecessary code
gsuarezr Oct 26, 2023
5c03d92
Rewrote summary methods,added comments,eliminated unnecessary code
gsuarezr Oct 26, 2023
5f0003c
moving parity to another branch
gsuarezr Oct 27, 2023
22cdee6
Merge branch 'qutip:master' into parity
gsuarezr Oct 27, 2023
f16d52d
added parity support
gsuarezr Oct 27, 2023
fc794bc
Merge branch 'qutip:master' into parity
gsuarezr Nov 9, 2023
26c49ed
moved example notebook to tutorials
gsuarezr Nov 8, 2023
9699687
removed mpmath
gsuarezr Nov 9, 2023
77f23a4
removed bosonic fitting tests
gsuarezr Nov 9, 2023
2c74559
removed changes from other branches
gsuarezr Nov 9, 2023
b9d8093
codeclimate sugestions
gsuarezr Nov 9, 2023
3fe627e
refactoring according to codeclimate
gsuarezr Nov 13, 2023
65a8299
added changelog entry
gsuarezr Nov 13, 2023
ca7095a
revert unrelated changes
gsuarezr Nov 27, 2023
a79a305
revert unrelated changes 2
gsuarezr Nov 27, 2023
5ee816a
revert unrelated changes 3
gsuarezr Nov 27, 2023
aaa45f1
revert unrelated changes 4
gsuarezr Nov 27, 2023
27c878d
Merge branch 'qutip:master' into parity
gsuarezr Dec 11, 2023
4172aef
Merge branch 'qutip:master' into parity
gsuarezr Dec 19, 2023
4b5cfc1
make odd parity keyword only
gsuarezr Dec 20, 2023
e7f1360
Apply suggestions from code review
gsuarezr Dec 20, 2023
87a23a0
Merge branch 'qutip:master' into parity
gsuarezr Jan 15, 2024
01058af
added simple test
gsuarezr Feb 11, 2024
dd1f104
check broken tests
gsuarezr Feb 15, 2024
adaca75
daily
gsuarezr Feb 19, 2024
a5ce6cc
set use_mkl=False so tests pass for python 3.10
gsuarezr Feb 19, 2024
ce69039
code review suggestions
gsuarezr Mar 4, 2024
e004b44
Merge branch 'master' into parity
gsuarezr Mar 4, 2024
07d1c38
missed import
gsuarezr Mar 4, 2024
41ddaba
missed comma
gsuarezr Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/2261.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
It adds odd parity support to HEOM's fermionic solver
28 changes: 21 additions & 7 deletions qutip/solver/heom/bofin_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class HierarchyADOsState:
See :class:`HierarchyADOs` for a full list of the available attributes
and methods.
"""

def __init__(self, rho, ados, ado_state):
self.rho = rho
self._ado_state = ado_state
Expand Down Expand Up @@ -574,8 +575,20 @@ class HEOMSolver(Solver):
If multiple baths are given, they must all be either fermionic
or bosonic baths.

odd_parity : Bool
For fermionic baths only. Default is "False". "Parity" refers to the
parity of the initial system state used with the HEOM. An example of
an odd parity state is one made from applying an odd number of
fermionic creation operators to a physical density operator.
Physical systems have even parity, but allowing the generalization
to odd-parity states allows one to calculate useful physical quantities
like the system power spectrum or density of states.
The form of the HEOM differs depending on the parity of the initial
system state, so if this option is set to "True", a different RHS is
constructed, which can then be used with a system state of odd parity.

Copy link
Member

@nwlambert nwlambert Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simon asked us to help distill and clarify this a little bit; how about:

" For fermionic baths only. Default is "False". "Parity" refers to the parity of the initial system state used with the HEOM. An example of an odd parity state is one made from applying an odd number of fermionic creation operators to a physical density operator. Physical systems have even parity, but allowing the generalization to odd-parity states allows one to calculate useful physical quantities like the system power spectrum or density of states. The form of the HEOM differs depending on the parity of the initial system state, so if this option is set to "True", a different RHS is constructed, which can then be used with a system state of odd parity. "

max_depth : int
The maximum depth of the heirarchy (i.e. the maximum number of bath
The maximum depth of the hierarchy (i.e. the maximum number of bath
exponent "excitations" to retain).

options : dict, optional
Expand Down Expand Up @@ -610,9 +623,10 @@ class HEOMSolver(Solver):
"state_data_type": "dense",
}

def __init__(self, H, bath, max_depth, *, options=None):
def __init__(self, H, bath, max_depth, *, odd_parity=False, options=None):
_time_start = time()

# we call bool here because odd_parity will be used in arithmetic
self.odd_parity = bool(odd_parity)
if not isinstance(H, (Qobj, QobjEvo)):
raise TypeError("The Hamiltonian (H) must be a Qobj or QobjEvo")

Expand Down Expand Up @@ -761,10 +775,10 @@ def _grad_prev_fermionic(self, he_n, k):
]

n_excite = sum(he_fermionic_n)
sign1 = (-1) ** (n_excite + 1)
sign1 = (-1) ** (n_excite + 1 - self.odd_parity)

n_excite_before_m = sum(he_fermionic_n[:k])
sign2 = (-1) ** (n_excite_before_m)
sign2 = (-1)**(n_excite_before_m + self.odd_parity)

sigma_bar_k = k + self.ados.sigma_bar_k_offset[k]

Expand Down Expand Up @@ -808,10 +822,10 @@ def _grad_next_fermionic(self, he_n, k):
for i, exp in zip(he_n, self.ados.exponents)
]
n_excite = sum(he_fermionic_n)
sign1 = (-1) ** (n_excite + 1)
sign1 = (-1) ** (n_excite + 1 - self.odd_parity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


n_excite_before_m = sum(he_fermionic_n[:k])
sign2 = (-1) ** (n_excite_before_m)
sign2 = (-1)**(n_excite_before_m + self.odd_parity)

if self.ados.exponents[k].type == BathExponent.types["+"]:
if sign1 == -1:
Expand Down
45 changes: 41 additions & 4 deletions qutip/tests/solver/heom/test_bofin_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from qutip import (
basis, destroy, expect, liouvillian, qeye, sigmax, sigmaz, sigmay,
tensor, Qobj, QobjEvo, fidelity
tensor, Qobj, QobjEvo, fidelity, fdestroy
)
from qutip.core import data as _data
from qutip.solver.heom.bofin_baths import (
Expand Down Expand Up @@ -54,8 +54,8 @@ def assert_raises_steady_state_time_dependent(hsolver):
with pytest.raises(ValueError) as err:
hsolver.steady_state()
assert str(err.value) == (
"A steady state cannot be determined for a time-dependent"
" system"
"A steady state cannot be determined for a time-dependent"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can stay -- it's a valid indentation fix.

" system"
)


Expand Down Expand Up @@ -1145,7 +1145,44 @@ def test_solving_with_step(self):

assert states[-1] == ado_state.extract(0)


def test_parity(self):
depth = 2
Nk = 2
# system: two fermions
N = 2
d_1 = fdestroy(N, 0)
d_2 = fdestroy(N, 1)
# bath params:
mu = 0. # chemical potential
Gamma = 1 # coupling strenght
W = 2.5 # bath width
# system params:
# coulomb repulsion
U = 3 * np.pi * Gamma
# impurity energy
w0 = - U / 2.
beta = 1 / (0.2 * Gamma) # Inverse Temperature
H = w0 * (d_1.dag() * d_1 + d_2.dag()
* d_2) + U * d_1.dag() * d_1 * d_2.dag() * d_2

L = liouvillian(H)
bath1 = LorentzianPadeBath(
Q=d_1, gamma=2 * Gamma, w=W, mu=mu, T=1 / beta, Nk=Nk,
tag="Lead 1")
bath2 = LorentzianPadeBath(
Q=d_2, gamma=2 * Gamma, w=W, mu=mu, T=1 / beta, Nk=Nk,
tag="Lead 2")
solver = HEOMSolver(L, [bath1, bath2], depth, odd_parity=True)
rhoss, _ = solver.steady_state(use_mkl=False)
rhoss = rhoss.full()
expected_odd = np.diag([-0.18472, 0.68472, 0.68472, -0.18472])
np.testing.assert_allclose(rhoss, expected_odd, atol=1e-5)

solver = HEOMSolver(L, [bath1, bath2], depth, odd_parity=False)
rhoss, _ = solver.steady_state(use_mkl=False)
rhoss = rhoss.full()
expected = np.diag([0.10623, 0.39376, 0.39376, 0.10623])
np.testing.assert_allclose(rhoss, expected, atol=1e-5)
class TestHeomsolveFunction:
@pytest.mark.parametrize(['evo'], [
pytest.param("qobj", id="qobj"),
Expand Down