<commit_before>#This file is part of QuTIP.
#
#    QuTIP is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#    QuTIP is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with QuTIP.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2011, <NAME> & <NAME>
#
###########################################################################

from scipy import *
from Qobj import *
from spre import *
from spost import *
from Counter import *
from ode_solve import *
from ode2es import *
from mcsolve import *

def correlation_es(H, rho0, tlist, taulist, c_op_list, a_op, b_op):
    """
    Calculate a two-time correlation function <A(t+tau)B(t)> using exponential
    series and the quantum regression theorem.
    """

    # contruct the Liouvillian
    n_op      = len(c_op_list)
    L = -1.0j * (spre(H) - spost(H))
    for m in range(0, n_op):
        cdc = c_op_list[m].dag() * c_op_list[m]
        L += spre(c_op_list[m])*spost(c_op_list[m].dag())-0.5*spre(cdc)-0.5*spost(cdc)

    if rho0 == None:
        rho0 = steady(L)

    C_mat = zeros([size(tlist),size(taulist)],dtype=complex)

    pgb = Counter(len(tlist), "Correlation function")

    solES_t = ode2es(L, rho0)

    for t_idx in range(len(tlist)):

        rho_t = esval_op(solES_t, [tlist[t_idx]])

        solES_tau = ode2es(L, b_op * rho_t)

        C_mat[t_idx, :] = esval(scalar_expect(a_op, solES_tau), taulist)
   
        pgb.update()

    pgb.finish()

    return C_mat


def correlation_ode(H, rho0, tlist, taulist, c_op_list, a_op, b_op):
    """
    Calculate a two-time correlation function <A(t+tau)B(t)> using the ode
    solver, and the quantum regression theorem.
    """

    if rho0 == None:
        # contruct the Liouvillian
        n_op      = len(c_op_list)
        L = -1.0j * (spre(H) - spost(H))
        for m in range(0, n_op):
            cdc = c_op_list[m].dag() * c_op_list[m]
            L += spre(c_op_list[m])*spost(c_op_list[m].dag())-0.5*spre(cdc)-0.5*spost(cdc)

        rho0 = steady(L)

    C_mat = zeros([size(tlist),size(taulist)],dtype=complex)

    pgb = Counter(len(tlist), "Correlation function")

    rho_t = me_ode_solve(H, rho0, tlist, c_op_list, [])

    for t_idx in range(len(tlist)):<commit_msg>fixed broken code in correlation function<commit_after>#This file is part of QuTIP.
#
#    QuTIP is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#    QuTIP is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with QuTIP.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2011, <NAME> & <NAME>
#
###########################################################################

from scipy import *
from Qobj import *
from spre import *
from spost import *
from Counter import *
from ode_solve import *
from ode2es import *
from mcsolve import *

def correlation_es(H, rho0, tlist, taulist, c_op_list, a_op, b_op):
    """
    Calculate a two-time correlation function <A(t+tau)B(t)> using exponential
    series and the quantum regression theorem.
    """

    # contruct the Liouvillian
    n_op      = len(c_op_list)
    L = -1.0j * (spre(H) - spost(H))
    for m in range(0, n_op):
        cdc = c_op_list[m].dag() * c_op_list[m]
        L += spre(c_op_list[m])*spost(c_op_list[m].dag())-0.5*spre(cdc)-0.5*spost(cdc)

    if rho0 == None:
        rho0 = steady(L)

    C_mat = zeros([size(tlist),size(taulist)],dtype=complex)

    pgb = Counter(len(tlist), "Correlation function")

    solES_t = ode2es(L, rho0)

    for t_idx in range(len(tlist)):

        rho_t = esval_op(solES_t, [tlist[t_idx]])

        solES_tau = ode2es(L, b_op * rho_t)

        C_mat[t_idx, :] = esval(expect(a_op, solES_tau), taulist)
   
        pgb.update()

    pgb.finish()

    return C_mat


def correlation_ode(H, rho0, tlist, taulist, c_op_list, a_op, b_op):
    """
    Calculate a two-time correlation function <A(t+tau)B(t)> using the ode
    solver, and the quantum regression theorem.
    """

    if rho0 == None:
        # contruct the Liouvillian
        n_op      = len(c_op_list)
        L = -1.0j * (spre(H) - spost(H))
        for m in range(0, n_op):
            cdc = c_op_list[m].dag() * c_op_list[m]
            L += spre(c_op_list[m])*spost(c_op_list[m].dag())-0.5*spre(cdc)-0.5*spost(cdc)

        rho0 = steady(L)

    C_mat = zeros([size(tlist),size(taulist)],dtype=complex)

    pgb = Counter(len(tlist), "Correlation function")

    rho_t = me_ode_solve(H, rho0, tlist, c_op_list, [])

    for t_idx in range(len(tlist)):
{'fraction_non_alphanumeric': 0.14612381483547127, 'fraction_numerical': 0.011154489682097044, 'mean_word_length': 3.1384615384615384, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2808071', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1949, 'n_words': 538}