<commit_before>import sys
import time
import logging
from tensorlog import comline
from tensorlog import declare
from tensorlog import interp
from tensorlog import mutil
from tensorlog import expt
from tensorlog import xctargets

CROSSCOMPILERS = []
if xctargets.theano:
  from tensorlog import theanoxcomp
  for c in [
    theanoxcomp.DenseMatDenseMsgCrossCompiler,
    theanoxcomp.SparseMatDenseMsgCrossCompiler
    ]:
    CROSSCOMPILERS.append(c)


modes = ["t_stress/io", "t_influences/io","t_cancer_spont/io", "t_cancer_smoke/io"]
def setExptParams():
    optdict,args = comline.parseCommandLine('--prog smokers.ppr --proppr --db smokers.cfacts'.split())
    ti = interp.Interp(optdict['prog'])
    ti.prog.setRuleWeights()
    ti.prog.maxDepth = 99
    rows = []
    for line in open('query-entities.txt'):
        sym = line.strip()
        rows.append(ti.db.onehot(sym))
    X = mutil.stack(rows)
    return ti,X

def runMain():

    (ti,X) = setExptParams()
    start0 = time.time()
    
    for modeString in modes:
        print 'eval',modeString,
        start = time.time()
        ti.prog.eval(declare.asMode(modeString), [X])
        print 'time',time.time() - start,'sec'
    tot = time.time() - start0
    print 'total time',tot,'sec'
    return tot

if __name__=="__main__":
    t = runMain()
    print 'time',t

    (ti,X) = setExptParams()
    for compilerClass in CROSSCOMPILERS:
        start0=time.time()
        xc = compilerClass(ti.prog)
        print expt.fulltype(xc)
        # compile everything
        for modeString in modes:
            mode = declare.asMode(modeString)
            xc.ensureCompiled(mode)
            print 'eval',modeString,
            start = time.time()
            if expt.fulltype(xc).find("tensorflow")>=0:
              xc.ensureSessionInitialized()
              xc.session.run(tf.global_variables_initializer())
            xc.inferenceFunction(mode)(X)
            print 'time',time.time() - start,'sec'
        print 'total time',expt.fulltype(xc),time.time()-start0,'sec'
<commit_msg>smokers: removed dangling tf cruft from native expt<commit_after>import sys
import time
import logging
from tensorlog import comline
from tensorlog import declare
from tensorlog import interp
from tensorlog import mutil
from tensorlog import expt
from tensorlog import xctargets

CROSSCOMPILERS = []
if xctargets.theano:
  from tensorlog import theanoxcomp
  for c in [
    theanoxcomp.DenseMatDenseMsgCrossCompiler,
    theanoxcomp.SparseMatDenseMsgCrossCompiler
    ]:
    CROSSCOMPILERS.append(c)


modes = ["t_stress/io", "t_influences/io","t_cancer_spont/io", "t_cancer_smoke/io"]
def setExptParams():
    optdict,args = comline.parseCommandLine('--prog smokers.ppr --proppr --db smokers.cfacts'.split())
    ti = interp.Interp(optdict['prog'])
    ti.prog.setRuleWeights()
    ti.prog.maxDepth = 99
    rows = []
    for line in open('query-entities.txt'):
        sym = line.strip()
        rows.append(ti.db.onehot(sym))
    X = mutil.stack(rows)
    return ti,X

def runMain():

    (ti,X) = setExptParams()
    start0 = time.time()
    
    for modeString in modes:
        print 'eval',modeString,
        start = time.time()
        ti.prog.eval(declare.asMode(modeString), [X])
        print 'time',time.time() - start,'sec'
    tot = time.time() - start0
    print 'total time',tot,'sec'
    return tot

if __name__=="__main__":
    t = runMain()
    print 'time',t

    (ti,X) = setExptParams()
    for compilerClass in CROSSCOMPILERS:
        start0=time.time()
        xc = compilerClass(ti.prog)
        print expt.fulltype(xc)
        # compile everything
        for modeString in modes:
            mode = declare.asMode(modeString)
            xc.ensureCompiled(mode)
            print 'eval',modeString,
            start = time.time()
            xc.inferenceFunction(mode)(X)
            print 'time',time.time() - start,'sec'
        print 'total time',expt.fulltype(xc),time.time()-start0,'sec'

{'fraction_non_alphanumeric': 0.11889168765743073, 'fraction_numerical': 0.00327455919395466, 'mean_word_length': 2.8703703703703702, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, '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': '7024050', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1301, 'n_words': 283}