Commit b2656375 authored by s.gretchko's avatar s.gretchko
Browse files

Added automatic regression tests (in new tests folder)

parent cbe5dd89
#Sylvain
# Module to be imported by test modules to set the ProxPython path
# after this is called, can use import statements like this one:
# from proxtoolbox.experiments.phase import Phase, JWST_AltP_in
......
......@@ -4,16 +4,16 @@ from proxtoolbox.experiments.sudoku.sudokuExperiment import SudokuExperiment
# if a puzzle is not specified, the sudoku experiment uses the
# default puzzle, which is the same as the one below:
puzzle = ((2,0,0,0,0,1,0,3,0),
(4,0,0,0,8,6,1,0,0),
(0,0,0,0,0,0,0,0,0),
(0,0,0,0,1,0,0,0,0),
(0,0,0,0,0,0,9,0,0),
(0,0,5,0,0,3,0,0,7),
(0,0,0,0,0,0,0,0,0),
(1,0,0,0,0,7,4,9,0),
(0,2,4,1,0,0,0,0,0))
# puzzle = ((2,0,0,0,0,1,0,3,0),
# (4,0,0,0,8,6,1,0,0),
# (0,0,0,0,0,0,0,0,0),
# (0,0,0,0,1,0,0,0,0),
# (0,0,0,0,0,0,9,0,0),
# (0,0,5,0,0,3,0,0,7),
# (0,0,0,0,0,0,0,0,0),
# (1,0,0,0,0,7,4,9,0),
# (0,2,4,1,0,0,0,0,0))
Sudoku = SudokuExperiment(algorithm='DRl', sudoku=puzzle)
Sudoku = SudokuExperiment(algorithm='DRl')
Sudoku.run()
Sudoku.show()
......@@ -28,6 +28,7 @@ class IterateMonitor:
self.anim = experiment.anim
self.anim_callback = experiment.animate
self.anim_step = experiment.anim_step
self.silent = experiment.silent
self.changes = None
......@@ -82,7 +83,7 @@ class IterateMonitor:
alg : instance of Algorithm class
Algorithm being monitored.
"""
if self.anim and self.anim_callback is not None \
if (not self.silent) and self.anim and self.anim_callback is not None \
and alg.iter % self.anim_step == 0:
self.anim_callback(alg)
......
......@@ -374,7 +374,7 @@ class Samsara():
def __first_step(self):
"""Initialise variables.
"""
print('First iteration: initialising...')
#print('First iteration: initialising...')
##################################################
# Initialisation
##################################################
......
......@@ -72,7 +72,8 @@ class ART_Experiment(Experiment):
GetData.getData('CT')
# load data
print('Loading data file ART_SheppLogan.mat ')
if not self.silent:
print('Loading data file ART_SheppLogan.mat ')
data_Shepp = loadmat('../InputData/CT/ART_SheppLogan.mat')
N = data_Shepp['N'].item()
p = data_Shepp['p'].item()
......
......@@ -101,6 +101,8 @@ class Experiment(metaclass=ExperimentMetaClass):
accelerator_name=None,
rotate=False,
verbose=0,
silent=False, # if set to True, means no print statement should be executed
# (including what would have been generated with verbose mode)
graphics=0,
anim=False,
anim_step = 2, # Tell how frequently the animation is updated, i.e., every `anim_step` step(s)
......@@ -150,6 +152,7 @@ class Experiment(metaclass=ExperimentMetaClass):
self.data_ball = data_ball
self.diagnostic = diagnostic
self.verbose = verbose
self.silent = silent
self.graphics = graphics
self.anim = anim
self.anim_step = anim_step
......@@ -266,10 +269,10 @@ class Experiment(metaclass=ExperimentMetaClass):
Run the algorithm associated with this experiment.
The initial iterate is obtained from the loadData() method.
"""
# TODO: implement multiple runs
print("Running " + self.algorithm_name + " on " + self.experiment_name + "...")
if self.verbose:
if not self.silent:
print("Running " + self.algorithm_name + " on " + self.experiment_name + "...")
if self.verbose and not self.silent:
self.printInput()
t = time.time()
......@@ -278,15 +281,16 @@ class Experiment(metaclass=ExperimentMetaClass):
self.output['stats']['time'] = time.time() - t
print("Took", self.output['stats']['iter'], "iterations and",
self.output['stats']['time'], "seconds.")
if not self.silent:
print("Took", self.output['stats']['iter'], "iterations and",
self.output['stats']['time'], "seconds.")
self.postprocess()
if self.save_output:
self.saveOutput()
if self.verbose:
if self.verbose and not self.silent:
self.printBenchmark()
if self.anim and mpl.is_interactive():
......
......@@ -75,8 +75,8 @@ class CDI_Experiment(PhaseExperiment):
# make sure input data can be found, otherwise download it
GetData.getData('Phase')
print('Loading data file CDI_intensity')
if not self.silent:
print('Loading data file CDI_intensity')
f = loadmat('../InputData/Phase/CDI_intensity.mat')
# diffraction pattern
dp = f['intensity']['img'][0, 0]
......@@ -115,7 +115,8 @@ class CDI_Experiment(PhaseExperiment):
self.magn = 1 # magnification factor
self.farfield = True
print('Using farfield formula.')
if not self.silent:
print('Using farfield formula.')
self.rt_data = Cell(1)
self.rt_data[0] = M
......
......@@ -89,7 +89,8 @@ class JWST_Experiment(PhaseExperiment):
# works well.
snr = 1e-8
print('Loading data.')
if not self.silent:
print('Loading data.')
with open('../InputData/Phase/pupil.pmod','r') as fid:
# read lower endian float <f
Xi_A = np.fromfile(fid, dtype='<f')
......
......@@ -85,7 +85,8 @@ class Krueger_Experiment(PhaseExperiment):
WG = WG['WG']
# hologram
print('Loading data hologram_not-normalized.mat')
if not self.silent:
print('Loading data hologram_not-normalized.mat')
I_exp = loadmat('../InputData/Phase/hologram_not-normalized.mat')
I_exp = I_exp['I_exp']
......
......@@ -84,7 +84,8 @@ class Phasepack_Experiment(PhaseExperiment):
print('*************************************************************************')
raise IOError(errMsg)
print("Loading data. This may take a while...")
if not self.silent:
print("Loading data. This may take a while...")
# transmission matrix
XH_test_dict = loadMatFile(data_dir + filenames[2])
......
......@@ -266,7 +266,8 @@ class PtychographyExperiment(Experiment):
# Average total intensity in experimental diffraction pattern
I_sum = np.sum(np.sum(self.I_exp,axis=1),axis=0)
I_avg = np.mean(I_sum)
print("Average intensity of single frame is {:.2e} photons".format(I_avg))
if not self.silent:
print("Average intensity of single frame is {:.2e} photons".format(I_avg))
# Maximum average intensity in a single experimental frame
I_max_avg = np.amax(I_sum) / (self.Nx*self.Ny)
......@@ -697,7 +698,8 @@ class PtychographyExperiment(Experiment):
if self.warmup:
# run warmup algorithm
print("Running warmup algorithm " + self.warmupExp.algorithm_name)
if not self.silent:
print("Running warmup algorithm " + self.warmupExp.algorithm_name)
warmup_out = self.warmupExp.algorithm.run(self.warmupExp.u0)
warmup_u = warmup_out['u']
u0 = Cell(3)
......@@ -707,7 +709,8 @@ class PtychographyExperiment(Experiment):
else:
u0 = self.u0
print("Running main algorithm (" + self.algorithm_name + ")")
if not self.silent:
print("Running main algorithm (" + self.algorithm_name + ")")
output = super(PtychographyExperiment, self).runAlgorithm(u0) # call parent's method
return output
......
# Module to be imported by test modules to set the ProxPython path
# after this is called, can use import statements like this one:
# from proxtoolbox.experiments.phase import Phase, JWST_AltP_in
import sys
import os
# add the proxpython directory into the Python's path
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/..")
This diff is collapsed.
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