def execPRO(run_id, what_metric, workDir, refFile, metricScoreFile):

    global tune_set_size
    global PRO_iters
    global sentFVecDict
    nbestFile = workDir + "all.nbest.out"
    featFile = workDir + "all.features.dat"
    wgtsFile = workDir + "run" + str(run_id) + ".weights.txt"
    optFile = workDir + 'run' + str(run_id) + '.opt.dat'

    prevWgtVec = readInitWgts(wgtsFile)
    featNames = ['w_lm', 'w_glue', 'w_wp', 'w_tm0', 'w_tm1', 'w_tm2', 'w_tm3', 'w_tm4']
    featsLst = []

    setTuningSetSize(featFile)
    for p_iter in xrange( PRO_iters ):
        sent_indx = 0
        start_indx = 0
        feat_offset = 0

        oF = open(optFile, 'w')
        while sent_indx < tune_set_size:
            cands_4_sent = loadFeatStats(featFile, sent_indx, feat_offset)
            metricScores = loadMetricStats(metricScoreFile, what_metric, start_indx, cands_4_sent)
            if what_metric == 'pareto' or SAMPLER_TYPE == 'rank':
                hypData = sentFVecDict[sent_indx]
                hypVal = metricScores[:]
            elif SAMPLER_TYPE == 'none':
                hypData = sentFVecDict[sent_indx]
                hypVal = metricThresholdLabeler(sent_indx, metricScores)
            else:
                hypData, hypVal = generateCandidatePool(sent_indx, cands_4_sent, metricScores)

            i = 0
            for featVec in hypData:
                j = 0
                for f_val in featVec:
                    if f_val != 0.0:
                        if what_metric == 'pareto' or SAMPLER_TYPE == 'rank' or SAMPLER_TYPE == 'none':
                            featsLst.append( str(j+1) + ':' + str(f_val) )
                        else: featsLst.append( featNames[j] + ' ' + str(f_val) )
                    j += 1
                if what_metric == 'pareto' or SAMPLER_TYPE == 'rank' or SAMPLER_TYPE == 'none':
                    oF.write( "%g qid:%d %s\n" % (hypVal[i], sent_indx+1, ' '.join(featsLst)) )
                else: oF.write( "%d\t%s\n" % (hypVal[i], ' '.join(featsLst)) )
                i += 1
                del featsLst[:]
            sent_indx += 1
            start_indx += cands_4_sent
            feat_offset += cands_4_sent + 2

        oF.close()

        if what_metric == 'pareto' or SAMPLER_TYPE == 'rank' or SAMPLER_TYPE == 'none':
            wgtVec = svmClassifier(featNames, optFile, workDir)
        else:
            wgtVec = linearClassifier(featNames, optFile, workDir)
        #finalWgts = normalizeWgts( interpolateWgts(prevWgtVec, wgtVec) )
        finalWgts = normalizeWgts(wgtVec)
        prevWgtVec = finalWgts[:]
        #writeFinalWgts(prevWgtVec, wgtsFile)

    newWgtsFile = workDir + "weights.txt"
    writeFinalWgts(prevWgtVec, newWgtsFile)

    logFile = workDir + "pro.log"
    bestHypIndxLst = identifyBestHyps(prevWgtVec, featFile)
    eval_met = MetricScores(workDir, refFile, nbestFile, bestHypIndxLst, logFile)
dataset/ETHPy150Open sfu-natlang/Kriya/src/Kriya-Decoder/mert-scripts/PRO.py/execPRO/original