95f8306e3744ca8d092a5d6aaee3e7a8b3f21e80
[qpalma.git] / scripts / grid_predict.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import cPickle
5 import sys
6 import time
7 import pdb
8 import os
9 import os.path
10 import math
11
12 from pythongrid import KybJob, Usage
13 from pythongrid import process_jobs, submit_jobs, collect_jobs, get_status
14
15 from qpalma_main import *
16
17 import grid_predict
18
19
20 def get_slices(dataset_size,num_nodes):
21 all_instances = []
22
23 part = dataset_size / num_nodes
24 begin = 0
25 end = 0
26 for idx in range(1,num_nodes+1):
27
28 if idx == num_nodes:
29 begin = end
30 end = dataset_size
31 else:
32 begin = end
33 end = begin+part
34
35 params = (begin,end)
36
37 all_instances.append(params)
38
39 return all_instances
40
41
42 def makeJobs(run,dataset_fn,chunks,param_fn):
43 """
44 """
45
46 jobs=[]
47
48 for c_name,current_chunk in chunks:
49 current_job = KybJob(grid_predict.g_predict,[run,dataset_fn,current_chunk,param_fn,c_name])
50 current_job.h_vmem = '20.0G'
51 #current_job.express = 'True'
52
53 print "job #1: ", current_job.nativeSpecification
54
55 jobs.append(current_job)
56
57 return jobs
58
59
60 def create_and_submit():
61 """
62
63 """
64
65 jp = os.path.join
66
67 run_dir = '/fml/ag-raetsch/home/fabio/tmp/newest_run/alignment/saved_run'
68
69 run = cPickle.load(open(jp(run_dir,'run_obj.pickle')))
70 run['name'] = 'saved_run'
71
72 param_fn = jp(run_dir,'param_526.pickle')
73
74 run['result_dir'] = '/fml/ag-raetsch/home/fabio/tmp/vmatch_evaluation/spliced_1/prediction'
75 dataset_fn = '/fml/ag-raetsch/home/fabio/tmp/vmatch_evaluation/spliced_1/dataset/dataset_run_1.pickle.pickle'
76 prediction_keys_fn = '/fml/ag-raetsch/home/fabio/tmp/vmatch_evaluation/spliced_1/dataset/dataset_run_1.pickle.keys.pickle'
77
78 prediction_keys = cPickle.load(open(prediction_keys_fn))
79
80 print 'Found %d keys for prediction.' % len(prediction_keys)
81
82 num_splits = 25
83 #num_splits = 1
84 slices = get_slices(len(prediction_keys),num_splits)
85 chunks = []
86 for idx,slice in enumerate(slices):
87 #if idx != 0:
88 c_name = 'chunk_%d' % idx
89 chunks.append((c_name,prediction_keys[slice[0]:slice[1]]))
90
91 functionJobs = makeJobs(run,dataset_fn,chunks,param_fn)
92
93 sum = 0
94 for size in [len(elem) for name,elem in chunks]:
95 sum += size
96
97 print 'Got %d job(s)' % len(functionJobs)
98
99 #print "output ret field in each job before sending it onto the cluster"
100 #for (i, job) in enumerate(functionJobs):
101 # print "Job with id: ", i, "- ret: ", job.ret
102 #print ""
103 #print "sending function jobs to cluster"
104 #print ""
105
106 (sid, jobids) = submit_jobs(functionJobs)
107
108
109 def g_predict(run,dataset_fn,prediction_keys,param_fn,set_name):
110 """
111
112 """
113
114 qp = QPalma(False)
115 qp.init_prediction(run,dataset_fn,prediction_keys,param_fn,set_name)
116 return 'finished prediction of set %s.' % set_name
117
118
119 if __name__ == '__main__':
120 create_and_submit()