-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fixed_part.py
executable file
·76 lines (58 loc) · 2.51 KB
/
test_fixed_part.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
from dist_ecos.admm_consensus.prox_list import form_prox_list
from dist_ecos.admm_consensus.admm_consensus import solve
import pylab
import time
import cPickle as pickle
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate random block cone programs.')
parser.add_argument('--infile', type=argparse.FileType('rb'), dest='prob', help="problem to read, pickled file saved by random_cone_prob_fixed_part.py", required=True)
parser.add_argument('--outfile', default = "timings.p", type=argparse.FileType('wb'), dest='savefile', help="file to save timing information")
parser.add_argument('--noplot', dest='show_plot', action='store_const', const=False, default=True, help="do not show the plots (if omitted, will display)")
args = parser.parse_args()
data = pickle.load(args.prob)
for line in data['stats']:
print line
socp_vars = data['socp_vars']
objval = data['objval']
N = data['N']
partition_list = data['partition_list']
# first, solve with ecos
import ecos
sol = ecos.solve(**socp_vars)
ecos_time = sol['info']['timing']['runtime']
# next, solve with dist_ecos
def objective(x):
return socp_vars['c'].dot(x)
if args.show_plot:
pylab.spy(socp_vars['G'], marker='.', alpha=0.2)
pylab.show()
t = time.time()
prox_list, global_indices = form_prox_list(socp_vars, partition_list)
split_time = time.time() - t
result = solve(prox_list, global_indices, parallel=True, max_iters=1000, rho=2)
pri = result['res_pri']
dual = result['res_dual']
if args.show_plot:
pylab.semilogy(range(len(pri)), pri, range(len(dual)), dual)
pylab.legend(['primal', 'dual'])
pylab.show()
print 'split time: ', split_time
print 'solve time: ', result['solve_time']
print 'subsystem times'
for x in result['subsystem_stats']:
print 'subsystem: ', x
print
admm_objval = objective(result['sol'])
print 'admm objective ', admm_objval
print 'optimal objective', objval
print
print 'primal resid:', pri[-1]
print 'dual resid: ', dual[-1]
timing = {'ecos': ecos_time, 'admm': result['solve_time'],
'block_m': data['block_m'], 'block_n': data['block_n'],
'prob': data['prob'], 'N': N, 'objval': objval,
'admm_objval': admm_objval, 'iters': result['iters']+1,
'rel_err': abs(objval - admm_objval)/abs(objval)}
pickle.dump(timing, args.savefile)