<commit_before>"""
Tests for the Bosonic HEOM solvers.
"""
import numpy as np
from numpy.linalg import eigvalsh
from scipy.integrate import quad
from qutip import Qobj, sigmaz, sigmax, basis, expect, Options, destroy, basis
from bofin.heom import add_at_idx
from bofin.heom import HSolverDL
from bofin.heom import BosonicHEOMSolver
from bofin.heom import _heom_state_dictionaries
import pytest
from math import sqrt, factorial

def test_add_at_idx():
    """
    Tests the function to add at hierarchy index.
    """
    seq = (2, 3, 4)
    assert add_at_idx(seq, 2, 1), (2, 3, 5)

    seq = (2, 3, 4)
    assert add_at_idx(seq, 0, -1), (1, 3, 4)

def test_state_dictionaries():
    """
    Tests the _heom_state_dictionaries.
    """


    #bosonic
    kcut = 6
    N_cut = 4
    nhe, he2idx, idx2he = _heom_state_dictionaries(
            [N_cut + 1] * kcut, N_cut
        )
        
    total_nhe = int(
            factorial(N_cut + kcut)
            / (factorial(N_cut) * factorial(kcut))
        )
    assert nhe, total_nhe
        
  

@pytest.mark.filterwarnings("ignore::scipy.integrate.IntegrationWarning")
@pytest.mark.parametrize(['bnd_cut_approx', 'tol'], [
    pytest.param(True, 1e-4, id="bnd_cut_approx"),
    pytest.param(False,  1e-3, id="no_bnd_cut_approx"),  
])
def test_pure_dephasing_model_HSolverDL( bnd_cut_approx,  tol):
    """
    HSolverDL: Compare with pure-dephasing analytical assert that the
    analytical result and HEOM produce the same time dephasing evoltion.
    """
    cut_frequency = 0.05
    coupling_strength = 0.025
    lam_c = coupling_strength / np.pi
    temperature = 1 / 0.95<commit_msg>BoFiN: test check H and updates<commit_after>"""
Tests for the Bosonic HEOM solvers.
"""
import numpy as np
from numpy.linalg import eigvalsh
from scipy.integrate import quad
from qutip import (Qobj, QobjEvo, sigmaz, sigmax, basis, expect, Options, destroy, basis)
from bofin.heom import add_at_idx
from bofin.heom import HSolverDL
from bofin.heom import BosonicHEOMSolver
from bofin.heom import _heom_state_dictionaries, _check_Hsys
import pytest
from math import sqrt, factorial

def test_add_at_idx():
    """
    Tests the function to add at hierarchy index.
    """
    seq = (2, 3, 4)
    assert add_at_idx(seq, 2, 1), (2, 3, 5)

    seq = (2, 3, 4)
    assert add_at_idx(seq, 0, -1), (1, 3, 4)

def test_state_dictionaries():
    """
    Tests the _heom_state_dictionaries.
    """


    #bosonic
    kcut = 6
    N_cut = 4
    nhe, he2idx, idx2he = _heom_state_dictionaries(
            [N_cut + 1] * kcut, N_cut
        )
        
    total_nhe = int(
            factorial(N_cut + kcut)
            / (factorial(N_cut) * factorial(kcut))
        )
    assert nhe, total_nhe
        
def test_check_H():
    """Tests the function for checking system Hamiltonian"""
    assert(_check_Hsys(sigmax()))
    assert(_check_Hsys([sigmax(), sigmaz()]))
    assert(_check_Hsys([[sigmax(), np.sin], [sigmaz(), np.cos]]))
    assert(_check_Hsys([[sigmax(), np.sin], [sigmaz(), np.cos]]))
    assert(_check_Hsys(QobjEvo([sigmaz(), sigmax(), sigmaz()])))


    err_msg = r"Hamiltonian format is incorrect."

    with pytest.raises(RuntimeError, match=err_msg):
       _check_Hsys(sigmax().full())

    with pytest.raises(RuntimeError, match=err_msg):
       _check_Hsys([[1 , 0], [0, 1]])

    with pytest.raises(RuntimeError, match=err_msg):
       _check_Hsys([sigmax(), [[1 , 0], [0, 1]]])

    err_msg = r"Incorrect time dependent function for Hamiltonian."

    with pytest.raises(RuntimeError, match=err_msg):
       _check_Hsys([[sigmax(), [0, np.pi]]])

    with pytest.raises(RuntimeError, match=err_msg):
       _check_Hsys([[sigmax(), np.sin(0.5)]])


@pytest.mark.filterwarnings("ignore::scipy.integrate.IntegrationWarning")
@pytest.mark.parametrize(['bnd_cut_approx', 'tol'], [
    pytest.param(True, 1e-4, id="bnd_cut_approx"),
    pytest.param(False,  1e-3, id="no_bnd_cut_approx"),  
])
def test_pure_dephasing_model_HSolverDL( bnd_cut_approx,  tol):
    """
    HSolverDL: Compare with pure-dephasing analytical assert that the
    analytical result and HEOM produce the same time dephasing evoltion.
    """
    cut_frequency = 0.05
    coupling_strength = 0.025
    lam_c = coupling_strength / np.pi
    temperature = 1 / 0.95
{'fraction_non_alphanumeric': 0.1222533894343151, 'fraction_numerical': 0.019401589527816735, 'mean_word_length': 3.3797338792221083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6640930', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1557, 'n_words': 377}