+ minor changes in the paths
[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_3/prediction'
75 #dataset_fn = '/fml/ag-raetsch/home/fabio/tmp/vmatch_evaluation/spliced_3/dataset/dataset_run_1.pickle.pickle'
76 #prediction_keys_fn = '/fml/ag-raetsch/home/fabio/tmp/vmatch_evaluation/spliced_3/dataset/dataset_run_1.pickle.keys.pickle'
77
78 run['result_dir'] = '/fml/ag-raetsch/share/projects/qpalma/thaliana_4_lanes/lane_4/spliced/prediction'
79 dataset_fn = '/fml/ag-raetsch/share/projects/qpalma/thaliana_4_lanes/lane_4/spliced/dataset/dataset_run_1.pickle'
80 prediction_keys_fn = '/fml/ag-raetsch/share/projects/qpalma/thaliana_4_lanes/lane_4/spliced/dataset/dataset_run_1.keys.pickle'
81
82 prediction_keys = cPickle.load(open(prediction_keys_fn))
83
84 print 'Found %d keys for prediction.' % len(prediction_keys)
85
86 num_splits = 50
87 #num_splits = 1
88 slices = get_slices(len(prediction_keys),num_splits)
89 chunks = []
90 for idx,slice in enumerate(slices):
91 #if idx != 0:
92 c_name = 'chunk_%d' % idx
93 chunks.append((c_name,prediction_keys[slice[0]:slice[1]]))
94
95 functionJobs = makeJobs(run,dataset_fn,chunks,param_fn)
96
97 sum = 0
98 for size in [len(elem) for name,elem in chunks]:
99 sum += size
100
101 print 'Got %d job(s)' % len(functionJobs)
102
103 #print "output ret field in each job before sending it onto the cluster"
104 #for (i, job) in enumerate(functionJobs):
105 # print "Job with id: ", i, "- ret: ", job.ret
106 #print ""
107 #print "sending function jobs to cluster"
108 #print ""
109
110 (sid, jobids) = submit_jobs(functionJobs)
111
112
113 def g_predict(run,dataset_fn,prediction_keys,param_fn,set_name):
114 """
115
116 """
117
118 qp = QPalma(False)
119 qp.init_prediction(run,dataset_fn,prediction_keys,param_fn,set_name)
120 return 'finished prediction of set %s.' % set_name
121
122
123 if __name__ == '__main__':
124 create_and_submit()