1 """
2 This class generates and executes one-versus-all-plans for V-SQL
3 """
4
5 import sys_appends
6
7 import generate_plan
8 from multiprocessing import Pool
9 import psycopg2
10 import time
11
12
13
15 - def __init__(self, plan_id, connect_str, setup_q, plan):
16 """
17 Initializes the class
18 """
19 self.conn = psycopg2.connect(connect_str)
20 self.conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
21 self.psql = self.conn.cursor()
22 self.setup_q = setup_q
23 self.plan = plan
24 self.plan_id = plan_id
25
26
28 """
29 Runs
30 """
31 t0 = time.time()
32 print "[PlanExecutor %d] Start" % self.plan_id
33 self.psql.execute("SELECT library_setup();")
34 self.psql.execute(self.setup_q)
35 [header, body, loss_eval, footer] = self.plan
36 self.psql.execute(header)
37 print "[PlanExecutor %d] setup complete" % (self.plan_id)
38 for i in range(len(body)):
39 b = body[i]
40 t1 = time.time()
41 self.psql.execute(b)
42 t2 = time.time()
43 self.psql.execute(loss_eval)
44 (loss,) = self.psql.fetchone()
45 print "[PlanExecutor %d] label=%d epoch=%d took=%f obj=%f" % (self.plan_id, self.plan_id, i, t2- t1, loss)
46
47 self.psql.execute(footer)
48 print "[PlanExecutor:%d] Finished took %d seconds" % (self.plan_id,time.time() - t0)
49
51 """
52 Closes
53 """
54 self.conn.close()
55