Пример #1
0
def oimp_matrix_form(oimp,ops_configs,cocc,vocc):
    # matrix elements of 
    # sum < | oimp | > where oimp acts only on the imp+bath space
    # cocc, vocc: lists of core, virtual labels
    assert not oimp.fermion # operator should have an even number of c/d operators
    start={}
    end={}
    nconfigs=[len(configs) for (ops, configs) in ops_configs]
    ops=[opi for (opi, configi) in ops_configs]
    for i, opi in enumerate(ops):
        start[opi]=sum(nconfigs[:i])
        end[opi]=start[opi]+nconfigs[i]

    full_mat=utils.zeros([sum(nconfigs),sum(nconfigs)])
    
    for i, (opi, configsi) in enumerate(ops_configs):
        opit=opi.t()
        mat=qoperator.matrix_form(oimp,configsi,configsi)
        for j, (opj, configj) in enumerate(ops_configs):
            if isinstance(opit,models.Unit) and isinstance(opj,models.Unit):
                norm=1.
                full_mat[start[opi]:end[opi],start[opj]:end[opj]]=norm*mat
            elif isinstance(opi,models.ContractedC) and isinstance(opj,models.ContractedC):
                norm=norm_c(opit,opj,cocc,vocc)
                full_mat[start[opi]:end[opi],start[opj]:end[opj]]=norm*mat
            elif isinstance(opi,models.ContractedD) and isinstance(opj,models.ContractedD):
                norm=norm_d(opit,opj,cocc,vocc)
                full_mat[start[opi]:end[opi],start[opj]:end[opj]]=norm*mat
            elif isinstance(opi,models.ContractedCD) and isinstance(opj,models.ContractedCD):
                norm=norm_cd(opit,opj,cocc,vocc)
                full_mat[start[opi]:end[opi],start[opj]:end[opj]]=norm*mat


    return full_mat
Пример #2
0
def oimp_matrix_form(oimp, ops_configs, cocc, vocc):
    # matrix elements of
    # sum < | oimp | > where oimp acts only on the imp+bath space
    # cocc, vocc: lists of core, virtual labels
    assert not oimp.fermion  # operator should have an even number of c/d operators
    start = {}
    end = {}
    nconfigs = [len(configs) for (ops, configs) in ops_configs]
    ops = [opi for (opi, configi) in ops_configs]
    for i, opi in enumerate(ops):
        start[opi] = sum(nconfigs[:i])
        end[opi] = start[opi] + nconfigs[i]
    full_mat = utils.zeros([sum(nconfigs), sum(nconfigs)])

    for i, (opi, configsi) in enumerate(ops_configs):
        opit = opi.t()
        mat = qoperator.matrix_form(oimp, configsi, configsi)
        for j, (opj, configj) in enumerate(ops_configs):
            if isinstance(opit, models.Unit) and isinstance(opj, models.Unit):
                norm = 1.
                full_mat[start[opi]:end[opi], start[opj]:end[opj]] = norm * mat
            elif isinstance(opi, models.ContractedC) and isinstance(
                    opj, models.ContractedC):
                norm = norm_c(opit, opj, cocc, vocc)
                full_mat[start[opi]:end[opi], start[opj]:end[opj]] = norm * mat
            elif isinstance(opi, models.ContractedD) and isinstance(
                    opj, models.ContractedD):
                norm = norm_d(opit, opj, cocc, vocc)
                full_mat[start[opi]:end[opi], start[opj]:end[opj]] = norm * mat
            elif isinstance(opi, models.ContractedCD) and isinstance(
                    opj, models.ContractedCD):
                norm = norm_cd(opit, opj, cocc, vocc)
                full_mat[start[opi]:end[opi], start[opj]:end[opj]] = norm * mat

    return full_mat
Пример #3
0
def oimp_matrix_bra_ket_form(oimp, ops_bra_configs, ops_ket_configs, cocc,
                             vocc):
    # imp is an operator that acts only on the imp and bath orbitals.
    # (e.g. himp)
    bra_start = {}
    bra_end = {}
    ket_start = {}
    ket_end = {}
    bra_nconfigs = [len(bra_configs) for (ops, bra_configs) in ops_bra_configs]
    ket_nconfigs = [len(ket_configs) for (ops, ket_configs) in ops_ket_configs]
    bra_ops = [opi for (opi, bra_configs) in ops_bra_configs]
    ket_ops = [opi for (opi, ket_configs) in ops_ket_configs]
    for i, opi in enumerate(bra_ops):
        bra_start[opi] = sum(bra_nconfigs[:i])
        bra_end[opi] = bra_start[opi] + bra_nconfigs[i]

    for i, opi in enumerate(ket_ops):
        ket_start[opi] = sum(ket_nconfigs[:i])
        ket_end[opi] = ket_start[opi] + ket_nconfigs[i]

    full_mat = utils.zeros([sum(bra_nconfigs), sum(ket_nconfigs)])

    for i, (opi, bra_configsi) in enumerate(ops_bra_configs):

        opit = opi.t()
        for j, (opj, ket_configsj) in enumerate(ops_ket_configs):

            # <imp1.core|opi oimp opj|core.imp2>:
            # parity is opi.parity*oimp.parity*core.parity
            # but assume core is even
            mat = qoperator.matrix_form(oimp, bra_configsi, ket_configsj)
            parity = 1.
            if oimp.fermion and opi.fermion:
                parity = -1.
            if isinstance(opit, models.Unit) and isinstance(opj, models.Unit):
                norm = 1.
                full_mat[bra_start[opi]:bra_end[opi],
                         ket_start[opj]:ket_end[opj]] = norm * mat * parity
            elif isinstance(opi, models.ContractedC) and isinstance(
                    opj, models.ContractedC):
                norm = norm_c(opit, opj, cocc, vocc)
                full_mat[bra_start[opi]:bra_end[opi],
                         ket_start[opj]:ket_end[opj]] = norm * mat * parity
            elif isinstance(opi, models.ContractedD) and isinstance(
                    opj, models.ContractedD):
                norm = norm_d(opit, opj, cocc, vocc)
                full_mat[bra_start[opi]:bra_end[opi],
                         ket_start[opj]:ket_end[opj]] = norm * mat * parity
            elif isinstance(opi, models.ContractedCD) and isinstance(
                    opj, models.ContractedCD):
                norm = norm_cd(opit, opj, cocc, vocc)
                full_mat[bra_start[opi]:bra_end[opi],
                         ket_start[opj]:ket_end[opj]] = norm * mat * parity

    return full_mat
Пример #4
0
def matrix_form(qop, ops_configs):
    """
    < bra opi | qop | opj ket >
    where <bra opi| and |opj ket> are the same set
    """
    nconfigs = [len(configs) for (ops, configs) in ops_configs]
    full_mat = utils.zeros([sum(nconfigs), sum(nconfigs)])

    for i, (opi, bra_configsi) in enumerate(ops_configs):
        iptr = sum(nconfigs[:i])
        for j, (opj, ket_configsj) in enumerate(ops_configs):
            jptr = sum(nconfigs[:j])
            prod_op = qoperator.ProductQOp([opi.t(), qop, opj])
            mat = qoperator.matrix_form(prod_op, bra_configsi, ket_configsj)
            full_mat[iptr:iptr + nconfigs[i], jptr:jptr + nconfigs[j]] = mat
    return full_mat
Пример #5
0
def matrix_form(qop,ops_configs):
    """
    < bra opi | qop | opj ket >
    where <bra opi| and |opj ket> are the same set
    """
    nconfigs=[len(configs) for (ops, configs) in ops_configs]
    full_mat=utils.zeros([sum(nconfigs),sum(nconfigs)])

    for i, (opi, bra_configsi) in enumerate(ops_configs):
        iptr=sum(nconfigs[:i])
        for j, (opj, ket_configsj) in enumerate(ops_configs):
            jptr=sum(nconfigs[:j])
            prod_op=qoperator.ProductQOp([opi.t(),qop,opj])
            mat=qoperator.matrix_form(prod_op,bra_configsi,ket_configsj)
            full_mat[iptr:iptr+nconfigs[i],jptr:jptr+nconfigs[j]]=mat
    return full_mat
Пример #6
0
def oimp_matrix_bra_ket_form(oimp,ops_bra_configs,ops_ket_configs,cocc,vocc):
    # imp is an operator that acts only on the imp and bath orbitals.
    # (e.g. himp)
    bra_start={}
    bra_end={}
    ket_start={}
    ket_end={}
    bra_nconfigs=[len(bra_configs) for (ops, bra_configs) in ops_bra_configs]
    ket_nconfigs=[len(ket_configs) for (ops, ket_configs) in ops_ket_configs]
    bra_ops=[opi for (opi, bra_configs) in ops_bra_configs]
    ket_ops=[opi for (opi, ket_configs) in ops_ket_configs]
    for i, opi in enumerate(bra_ops):
        bra_start[opi]=sum(bra_nconfigs[:i])
        bra_end[opi]=bra_start[opi]+bra_nconfigs[i]

    for i, opi in enumerate(ket_ops):
        ket_start[opi]=sum(ket_nconfigs[:i])
        ket_end[opi]=ket_start[opi]+ket_nconfigs[i]

    full_mat=utils.zeros([sum(bra_nconfigs),sum(ket_nconfigs)])
    
    for i, (opi, bra_configsi) in enumerate(ops_bra_configs):
        opit=opi.t()
        
        for j, (opj, ket_configsj) in enumerate(ops_ket_configs):
            # <imp1.core|opi oimp opj|core.imp2>:
            # parity is opi.parity*oimp.parity*core.parity
            # but assume core is even
            mat=qoperator.matrix_form(oimp,bra_configsi,ket_configsj)
            parity=1.
            if oimp.fermion and opi.fermion:
                parity=-1.

            if isinstance(opit,models.Unit) and isinstance(opj,models.Unit):
                norm=1.
                full_mat[bra_start[opi]:bra_end[opi],ket_start[opj]:ket_end[opj]]=norm*mat*parity
            elif isinstance(opi,models.ContractedC) and isinstance(opj,models.ContractedC):
                norm=norm_c(opit,opj,cocc,vocc)
                full_mat[bra_start[opi]:bra_end[opi],ket_start[opj]:ket_end[opj]]=norm*mat*parity
            elif isinstance(opi,models.ContractedD) and isinstance(opj,models.ContractedD):
                norm=norm_d(opit,opj,cocc,vocc)
                full_mat[bra_start[opi]:bra_end[opi],ket_start[opj]:ket_end[opj]]=norm*mat*parity
            elif isinstance(opi,models.ContractedCD) and isinstance(opj,models.ContractedCD):
                norm=norm_cd(opit,opj,cocc,vocc)
                full_mat[bra_start[opi]:bra_end[opi],ket_start[opj]:ket_end[opj]]=norm*mat*parity

    return full_mat
Пример #7
0
def matrix_bra_ket_form(qop,ops_bra_configs,ops_ket_configs):
    """
    < bra opi | qop | opj ket >
    where <bra opi| and |opj ket> can be different sets
    """
    bra_nconfigs=[len(configs) for (ops, configs) in ops_bra_configs]
    ket_nconfigs=[len(configs) for (ops, configs) in ops_ket_configs]
    full_mat=utils.zeros([sum(bra_nconfigs),sum(ket_nconfigs)])

    for i, (opi, bra_configsi) in enumerate(ops_bra_configs):
        iptr=sum(bra_nconfigs[:i])
        for j, (opj, ket_configsj) in enumerate(ops_ket_configs):
            jptr=sum(ket_nconfigs[:j])
            prod_op=qoperator.ProductQOp([opi.t(),qop,opj])
            mat=qoperator.matrix_form(prod_op,bra_configsi,ket_configsj)
            full_mat[iptr:iptr+bra_nconfigs[i],jptr:jptr+ket_nconfigs[j]]=mat
    return full_mat
Пример #8
0
def matrix_bra_ket_form(qop, ops_bra_configs, ops_ket_configs):
    """
    < bra opi | qop | opj ket >
    where <bra opi| and |opj ket> can be different sets
    """
    bra_nconfigs = [len(configs) for (ops, configs) in ops_bra_configs]
    ket_nconfigs = [len(configs) for (ops, configs) in ops_ket_configs]
    full_mat = utils.zeros([sum(bra_nconfigs), sum(ket_nconfigs)])

    for i, (opi, bra_configsi) in enumerate(ops_bra_configs):
        iptr = sum(bra_nconfigs[:i])
        for j, (opj, ket_configsj) in enumerate(ops_ket_configs):
            jptr = sum(ket_nconfigs[:j])
            prod_op = qoperator.ProductQOp([opi.t(), qop, opj])
            mat = qoperator.matrix_form(prod_op, bra_configsi, ket_configsj)
            full_mat[iptr:iptr + bra_nconfigs[i],
                     jptr:jptr + ket_nconfigs[j]] = mat
    return full_mat
Пример #9
0
def himp_ext_matrix_form(hcs_imp, hds_ext, hds_imp, hcs_ext, ops_configs, cocc,
                         vocc):
    # matrix elements of cross terms
    # sum < |  hcs_imp otimes hds_ext | > + < | hds_imp otimes hcs_ext | >
    assert not len(cocc) & 1, "parities assume even #els in core"

    start = {}
    end = {}
    nconfigs = [len(configs) for (ops, configs) in ops_configs]
    ops = [opi for (opi, configi) in ops_configs]
    for i, opi in enumerate(ops):
        start[opi] = sum(nconfigs[:i])
        end[opi] = start[opi] + nconfigs[i]

    full_mat = utils.zeros([sum(nconfigs), sum(nconfigs)])

    for i, (opi, configi) in enumerate(ops_configs):
        opit = opi.t()
        for j, (opj, configj) in enumerate(ops_configs):
            for hc_imp, hd_ext in zip(hcs_imp, hds_ext):
                # <a1 b1.core|cimp dext|b2.core a2>:
                # parity =-1 if fermion(b1) and core is even
                if isinstance(opit, models.Unit) and isinstance(
                        opj, models.ContractedC):
                    mat_imp = qoperator.matrix_form(hc_imp, configi, configj)
                    val = eval_hd_cv(hd_ext, opj, cocc, vocc)
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

                elif isinstance(opit, models.ContractedCD) and isinstance(
                        opj, models.ContractedC):
                    mat_imp = qoperator.matrix_form(hc_imp, configi, configj)
                    val = eval_codv_hd_cv(opit, hd_ext, opj, cocc, vocc)
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

                # parity is -1, since b1 is fermionic
                elif isinstance(opit, models.ContractedC) and isinstance(
                        opj, models.Unit):
                    mat_imp = qoperator.matrix_form(hc_imp, configi, configj)
                    val = -eval_co_hd(opit, hd_ext, cocc, vocc)  # parity=-1
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

                elif isinstance(opit, models.ContractedC) and isinstance(
                        opj, models.ContractedCD):
                    mat_imp = qoperator.matrix_form(hc_imp, configi, configj)
                    val = -eval_co_hd_cvdo(opit, hd_ext, opj, cocc,
                                           vocc)  #parity=-1
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

            for hd_imp, hc_ext in zip(hds_imp, hcs_ext):
                # <a1 b1.core|cext dimp|b2.core a2>:
                # parity =-1 if fermion(b2) and core is even
                if isinstance(opit, models.Unit) and isinstance(
                        opj, models.ContractedD):
                    mat_imp = qoperator.matrix_form(hd_imp, configi, configj)
                    val = -eval_hc_do(hc_ext, opj, cocc, vocc)  # parity=-1
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

                elif isinstance(opit, models.ContractedCD) and isinstance(
                        opj, models.ContractedD):
                    mat_imp = qoperator.matrix_form(hd_imp, configi, configj)
                    val = -eval_codv_hc_do(opit, hc_ext, opj, cocc,
                                           vocc)  # parity=-1
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

                elif isinstance(opit, models.ContractedD) and isinstance(
                        opj, models.Unit):
                    mat_imp = qoperator.matrix_form(hd_imp, configi, configj)
                    val = eval_dv_hc(opit, hc_ext, cocc, vocc)
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

                elif isinstance(opit, models.ContractedD) and isinstance(
                        opj, models.ContractedCD):
                    mat_imp = qoperator.matrix_form(hd_imp, configi, configj)
                    val = eval_dv_hc_cvdo(opit, hc_ext, opj, cocc, vocc)
                    full_mat[start[opi]:end[opi],
                             start[opj]:end[opj]] += mat_imp * val

    return full_mat
Пример #10
0
def himp_ext_matrix_form(hcs_imp,hds_ext,hds_imp,hcs_ext,ops_configs,cocc,vocc):
    # matrix elements of cross terms 
    # sum < |  hcs_imp otimes hds_ext | > + < | hds_imp otimes hcs_ext | >
    assert not len(cocc) & 1, "parities assume even #els in core"

    start={}
    end={}
    nconfigs=[len(configs) for (ops, configs) in ops_configs]
    ops=[opi for (opi, configi) in ops_configs]
    for i, opi in enumerate(ops):
        start[opi]=sum(nconfigs[:i])
        end[opi]=start[opi]+nconfigs[i]

    full_mat=utils.zeros([sum(nconfigs),sum(nconfigs)])

    for i, (opi, configi) in enumerate(ops_configs):
        opit=opi.t()
        for j, (opj, configj) in enumerate(ops_configs):
            for hc_imp, hd_ext in zip(hcs_imp,hds_ext):
                # <a1 b1.core|cimp dext|b2.core a2>: 
                # parity =-1 if fermion(b1) and core is even
                if isinstance(opit,models.Unit) and isinstance(opj,models.ContractedC):
                    mat_imp=qoperator.matrix_form(hc_imp,configi,configj)                    
                    val=eval_hd_cv(hd_ext,opj,cocc,vocc)
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

                elif isinstance(opit,models.ContractedCD) and isinstance(opj,models.ContractedC):
                    mat_imp=qoperator.matrix_form(hc_imp,configi,configj)                    
                    val=eval_codv_hd_cv(opit,hd_ext,opj,cocc,vocc)
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

                # parity is -1, since b1 is fermionic
                elif isinstance(opit,models.ContractedC) and isinstance(opj,models.Unit):
                    mat_imp=qoperator.matrix_form(hc_imp,configi,configj)                    
                    val=-eval_co_hd(opit,hd_ext,cocc,vocc) # parity=-1
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

                elif isinstance(opit,models.ContractedC) and isinstance(opj,models.ContractedCD):
                    mat_imp=qoperator.matrix_form(hc_imp,configi,configj)                    
                    val=-eval_co_hd_cvdo(opit,hd_ext,opj,cocc,vocc) #parity=-1
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

            for hd_imp, hc_ext in zip(hds_imp,hcs_ext):
                # <a1 b1.core|cext dimp|b2.core a2>: 
                # parity =-1 if fermion(b2) and core is even
                if isinstance(opit,models.Unit) and isinstance(opj,models.ContractedD):
                    mat_imp=qoperator.matrix_form(hd_imp,configi,configj)                    
                    val=-eval_hc_do(hc_ext,opj,cocc,vocc) # parity=-1
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

                elif isinstance(opit,models.ContractedCD) and isinstance(opj,models.ContractedD):
                    mat_imp=qoperator.matrix_form(hd_imp,configi,configj)                    
                    val=-eval_codv_hc_do(opit,hc_ext,opj,cocc,vocc) # parity=-1
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

                elif isinstance(opit,models.ContractedD) and isinstance(opj,models.Unit):
                    mat_imp=qoperator.matrix_form(hd_imp,configi,configj)                    
                    val=eval_dv_hc(opit,hc_ext,cocc,vocc) 
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val

                elif isinstance(opit,models.ContractedD) and isinstance(opj,models.ContractedCD):
                    mat_imp=qoperator.matrix_form(hd_imp,configi,configj)                    
                    val=eval_dv_hc_cvdo(opit,hc_ext,opj,cocc,vocc) 
                    full_mat[start[opi]:end[opi],start[opj]:end[opj]]+=mat_imp*val
                
    return full_mat