<jupyter_start><jupyter_text>Baryon-Baryon CorrelatorFirst we import stuff, and define all of the objects needed to create/annihilate baryons.  In the future this will be read in from a text file that is generated by some group theory code to construct operators in an automated way.<jupyter_code>import sys
import os

sys.path.append(os.getcwd()[:-9])

from WickContractions.ops.operator import *
from WickContractions.ops.elemental import *
from WickContractions.ops.quarks import *
from WickContractions.ops.commuting import *
from WickContractions.corrs.diagram import *
from WickContractions.wick.utilities import *
from WickContractions.wick.contract import *
from WickContractions.laph.diagram import *

from Nc_baryon import get_operators
operator = get_operators({'nc': 4, 
                     'I': 2, 'Iz': 2,
                     'S': 2, 'Sz': 2}
                    ,'4Weyl')
for k,v in operator.items():
    print(k)
    print(v['factor'])
annihilation_elementals=[]

intToUD = {'0': 'u', '1': 'd'}

for k,v in operator.items():

    c0=EpsilonTensor(['c0','c1','c2','c3'])
    c1=SpinMatrix('X1^'+k,['s0','s1','s2','s3'])
    
    
    q0=Quark(False,intToUD[k[0]],'s0','c0','tf','x1')
    q1=Quark(False,intToUD[k[1]],'s1','c1','tf','x1')
    q2=Quark(False,intToUD[k[2]],'s2','c2','tf','x1')
    q3=Quark(False,intToUD[k[3]],'s3','c3','tf','x1')

    annihilation_elementals.append(ElementalOperator(v['factor'][0],[c0,c1],[q0,q1,q2,q3]))
    
annihilate_baryon = Operator(annihilation_elementals)

creation_elementals = []
for k,v in operator.items():
    c2=EpsilonTensor(['c4','c5','c6','c7'])
    c3=SpinMatrix('X2^'+k,['s4','s5','s6','s7'])

    q4=Quark(True,intToUD[k[0]],'s4','c4','ti','x2')
    q5=Quark(True,intToUD[k[1]],'s5','c5','ti','x2')
    q6=Quark(True,intToUD[k[2]],'s6','c6','ti','x2')
    q7=Quark(True,intToUD[k[3]],'s7','c7','ti','x2')
    
    creation_elementals.append(ElementalOperator(v['factor'][0],[c2,c3],[q4,q5,q6,q7]))

create_baryon = Operator(creation_elementals)
print(annihilate_baryon)
print(create_baryon)<jupyter_output>1.0*eps_{c4 c5 c6 c7}*X2^0000_{s4 s5 s6 s7}*\bar{u}_{s4 c4}(x2, ti)*\bar{u}_{s5 c5}(x2, ti)*\bar{u}_{s6 c6}(x2, ti)*\bar{u}_{s7 c7}(x2, ti)<jupyter_text>Now do the contractions and store in Laph subspace<jupyter_code>res = contract(annihilate_baryon, create_baryon)

for i in range(len(res.diagrams)):
    res.diagrams[i]=LDiagram(res.diagrams[i])
    
print("B->B correlator has {} diagrams".format(len(res.diagrams)))<jupyter_output>B->B correlator has 24 diagrams<jupyter_text>Now we can apply laph smearing to the quarks.  We print out the B->B diagrams explicitly since there are only four.<jupyter_code>#testing a more generic way to make blocks.
tst=copy.deepcopy(res.diagrams)
for d in tst:
    d.create_baryon_blocks()
    #d.create_block('delta','M') # should allow this code to handle any number of mesons/baryons
    d.short_props()
    
for d in tst:
    d.create_baryon_source()       # not NC agnostic at the moment.
                                   # not generalized to accomodate mesons + baryons
    #if rank4tensor is symmetric_pairwise:
    #    d.use_symmetric_block_properties()
    #else if rank4tensor is antisymmetric_pairwise:
    #    d.use_antisymmetric_block_properties()
    #else:
    #    #hard computation - too bad
    
    print(d)
unique_blocks = []

for d in tst:
    for elem in d.commuting:
        name = str(elem).split('_')[0]
        if name not in unique_blocks:
            unique_blocks.append(name)

print(unique_blocks)<jupyter_output>['B*(X1^0000,tf,ti)', 'B(X2^0000,ti)']<jupyter_text>Quick Check of computationI just did a quick check of the loop cost and printed out each contraction that needed to be done.  The latter notation is used in Eigen::Tensor or Fastor.<jupyter_code>#brute force counting.
costs = {}
for d in tst:
    nested_sums = 0
    for idx in d.commuting[0].indices[0:4]:
        if(idx in d.commuting[1].indices):
            nested_sums+=1
    if nested_sums in costs:
        costs[nested_sums]+=1
    else:
        costs[nested_sums]=1
print('total loops:')
for k,v in costs.items():
    print('  {}*N^{}'.format(v,k))
contractions = []
for d in tst:
    diag=[]
    for i,idx in enumerate(d.commuting[0].indices[0:4]):
        j=d.commuting[1].indices.index(idx)
        diag.append([i,j])
                    
    b0 = unique_blocks.index( str(d.commuting[0]).split('_')[0] ) 
    b1 = unique_blocks.index( str(d.commuting[1]).split('_')[0] )
    
    contractions.append({'blocks': [b0,b1], 'indices': diag})
print(contractions)
for d in contractions:
    s='diagrams.push_back({},{},std::vector<std::vector<int>>{{'.format(d['blocks'][0],d['blocks'][1])
    for pair in d['indices'][:-1]:
        s+='{{{},{}}},'.format(pair[0],pair[1])
    s+='{{{},{}}}'.format(d['indices'][-1][0],d['indices'][-1][1])
    s+='});'
    print(s)
s='std::vector<double> coef {'
for d in tst[:-1]:
    s+='{},'.format(d.coef)
s+='{}}};'.format(tst[-1].coef)
print(s)<jupyter_output>std::vector<double> coef {1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0};
{'fraction_non_alphanumeric': 0.18599689681923973, 'fraction_numerical': 0.03995345228859581, 'mean_word_length': 4.162162162162162, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '306382', 'license': 'MIT', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2016, 'n_words': 372, 'path': 'examples/BaryonI=2.ipynb', 'repo_name': 'chrisculver/WickContractions', 'size': '5156'}