Package vsql_core :: Package plan_generators :: Module generate_ova_plan
[hide private]
[frames] | no frames]

Source Code for Module vsql_core.plan_generators.generate_ova_plan

 1  import sys 
 2  sys.path.append('/scratch.1/VICTOR/') 
 3  sys.path.append('/scratch.1/chrisre/VICTOR/') 
 4   
 5  import generate_plan 
 6  from multiprocessing import Pool 
 7  import psycopg2 
 8  import time 
 9   
10  # This generates and executes one-versus-all-plans for V-SQL 
11   
12  ###################################################### 
13  ## This is a glorified SQL Execution thread handler 
14 -class PlanExecutor:
15 - def __init__(self, plan_id, connect_str, plan_str):
16 self.conn = psycopg2.connect(connect_str) 17 self.conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) 18 self.psql = self.conn.cursor() 19 self.plan = plan_str 20 self.plan_id = plan_id
21
22 - def go(self):
23 t0 = time.time() 24 print "[PlanExecutor:%d] Start" % self.plan_id 25 self.psql.execute("SELECT library_setup();") 26 self.psql.execute(self.plan) 27 print "[PlanExecutor:%d] Finished took %d seconds" % (self.plan_id,time.time() - t0)
28
29 - def close(self):
30 self.conn.close()
31 32 ######################## 33 # Main working thread
34 -def execute_work(work_tuple):
35 (plan_id, connect_str, plan) = work_tuple 36 plan_id = plan_id + 1 37 pe = PlanExecutor(plan_id, connect_str, plan) 38 pe.go() 39 pe.close() 40 return plan_id
41 42 43 # This is currently hardcoded for forest cover 44 # and ell2
45 -def ova_plan(print_only, connect_str, nprocesses):
46 base_mid = 10 47 epochs = 4 48 stepsize = 1e-2 49 diminish = 0.8 50 dim = 54 51 create_function = 'create_initial_model_with_bias' 52 iname_table = 'ell_two_model_instance' 53 curried_grad = 'curried_bias_grad_g' 54 grad = 'ell_two_bias_grad' 55 prox = None 56 57 work_list = [] 58 for i in range(1,8): 59 mid = base_mid + i 60 setup_query = "DELETE FROM %s where mid=%d;\n" % (iname_table, mid) 61 setup_query = setup_query + "INSERT INTO %s VALUES (%d, %s(%d));\n" % (iname_table, mid, create_function, dim) 62 data_query = "SELECT eid, CAST((label = %d) AS INT) as label, vec FROM forest_normalized" % i 63 P = generate_plan.Python_Plan(mid, epochs, stepsize, diminish, iname_table, curried_grad, grad, data_query, prox) 64 if print_only: 65 print setup_query 66 print data_query 67 print P.incremental_plan() 68 else: 69 work_list.append((i, connect_str, setup_query + P.incremental_plan())) 70 71 pool = Pool(processes=nprocesses) 72 print pool.map(execute_work, work_list)
73 74 ova_plan(False, 'dbname=chrisre', 4) 75