Commit 5c745a7a authored by Stefan Ziehe's avatar Stefan Ziehe
Browse files

A small bugfix for PALM. Not relly worth talking about.

parent bb79c5db
......@@ -75,6 +75,6 @@ class PALM(Algorithm):
u = tmp_u;
change = current_change if ignore_error else change[1:iters+1];
custom_errors = [] if ignore_error else custom_errors[:,1:iters+1];
custom_errors = numpy.empty((5,0)) if ignore_error else custom_errors[:,1:iters+1];
return tmp_u, tmp_u.copy(), iters, change, custom_errors;
......@@ -11,11 +11,11 @@ import numpy, matplotlib
import json, time
from matplotlib import pyplot
from ptychography import Ptychography
from Problems import Ptychography
# Sort out some functions useless for our benchmark
# Sort out some functions that are useless for our benchmark
class BenchmarkPtychography(Ptychography):
def _postsolve(self):
......@@ -27,39 +27,69 @@ def go():
config['blocking_switch'] = True;
config['maxiter'] = 300;
config['block_rows'] = 2;
config['block_cols'] = 2;
config['between_blocks_scheme'] = 'parallel';
config['within_blocks_scheme'] = 'none';
config['overrelax'] = 15;
#config['overrelax'] = 15;
# This might still need some thinking
config['tol'] = 1e-5;
#algorithms = ['PALM','PALMregPhiPtwise','Rodenburg','Thibault'];
algorithms = ['PALMregPhiPtwise'];
algorithms = ['PALM','PALMregPhiPtwise','Rodenburg','Thibault'];
blocks = [(2,2), (4,4)];
times = {};
for b in blocks:
for a in algorithms:
config['ptychography_prox'] = a;
config['block_rows'] = b[0];
config['block_cols'] = b[1];
problem = BenchmarkPtychography(config);
print('Algorithm {}, {}x{} blocks'.format(a, b[0], b[1]));
t = time.clock();
problem.solve();
t = time.clock() - t;
times[a + '_parallel'] = t;
pyplot.imsave('%s_parallel_amplitude.png' % a, \
numpy.abs(problem.u_final.obj));
pyplot.imsave('%s_parallel_phase.png' % a, \
numpy.angle(problem.u_final.obj));
pyplot.imsave('%s_parallel_probe.png' % a, \
matplotlib.colors.hsv_to_rgb(problem._im2hsv(problem.u_final.probe,1.0)));
numpy.savez_compressed('%s_parallel_data' % a, \
phi=problem.u_final.phi, \
obj=problem.u_final.obj, \
probe=problem.u_final.probe, \
change=problem.change, \
rms_err_obj=problem.custom_errors[0,:], \
rms_err_probe=problem.custom_errors[1,:], \
phi_change=problem.custom_errors[2,:], \
rfactor=problem.custom_errors[3,:], \
objective_value=problem.custom_errors[4,:], \
block_iters=problem.algorithm.block_iters);
config['blocking_switch'] = False;
for a in algorithms:
config['ptychography_prox'] = a;
problem = BenchmarkPtychography(config);
#print 'Algorithm %s, 2x2 blocks' % a;
print 'Algorithm %s, 2x2 blocks' % a;
print('Algorithm {}, no blocking'.format(a));
t = time.clock();
problem.solve();
t = time.clock() - t;
times[a + '_parallel'] = t;
times[a + '_sequential'] = t;
pyplot.imsave('%s_parallel_amplitude.png' % a, \
pyplot.imsave('%s_sequential_amplitude.png' % a, \
numpy.abs(problem.u_final.obj));
pyplot.imsave('%s_parallel_phase.png' % a, \
pyplot.imsave('%s_sequential_phase.png' % a, \
numpy.angle(problem.u_final.obj));
pyplot.imsave('%s_parallel_probe.png' % a, \
pyplot.imsave('%s_sequential_probe.png' % a, \
matplotlib.colors.hsv_to_rgb(problem._im2hsv(problem.u_final.probe,1.0)));
numpy.savez_compressed('%s_parallel_data' % a, \
numpy.savez_compressed('%s_sequential_data' % a, \
phi=problem.u_final.phi, \
obj=problem.u_final.obj, \
probe=problem.u_final.probe, \
......@@ -68,39 +98,8 @@ def go():
rms_err_probe=problem.custom_errors[1,:], \
phi_change=problem.custom_errors[2,:], \
rfactor=problem.custom_errors[3,:], \
objective_value=problem.custom_errors[4,:], \
block_iters=problem.algorithm.block_iters);
config['blocking_switch'] = False;
objective_value=problem.custom_errors[4,:]);
#for a in algorithms:
# config['ptychography_prox'] = a;
# problem = BenchmarkPtychography(config);
# print 'Algorithm %s, no blocking' % a;
#
# t = time.clock();
# problem.solve();
# t = time.clock() - t;
# times[a + '_sequential'] = t;
#
# pyplot.imsave('%s_sequential_amplitude.png' % a, \
# numpy.abs(problem.u_final.obj));
# pyplot.imsave('%s_sequential_phase.png' % a, \
# numpy.angle(problem.u_final.obj));
# pyplot.imsave('%s_sequential_probe.png' % a, \
# matplotlib.colors.hsv_to_rgb(problem._im2hsv(problem.u_final.probe,1.0)));
#
# numpy.savez_compressed('%s_sequential_data' % a, \
# phi=problem.u_final.phi, \
# obj=problem.u_final.obj, \
# probe=problem.u_final.probe, \
# change=problem.change, \
# rms_err_obj=problem.custom_errors[0,:], \
# rms_err_probe=problem.custom_errors[1,:], \
# phi_change=problem.custom_errors[2,:], \
# rfactor=problem.custom_errors[3,:], \
# objective_value=problem.custom_errors[4,:]);
#
json.dump(times, open('time.json','w'));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment