Skip to content

Commit

Permalink
Update LBFGS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptim0626 committed Sep 10, 2024
1 parent 8ecccf2 commit abecab6
Showing 1 changed file with 72 additions and 72 deletions.
144 changes: 72 additions & 72 deletions test/accelerate_tests/base_tests/LBFGS_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from test import utils as tu
from ptypy import utils as u
import ptypy
# ptypy.load_gpu_engines("serial")
from ptypy.custom import LBFGS, LBFGS_serial
import tempfile
import shutil
Expand Down Expand Up @@ -74,66 +73,67 @@ def check_engine_output(self, output, plotting=False, debug=False):
np.testing.assert_allclose(RMSE_pr, 0.0, atol=1e-2,
err_msg="The probe arrays are not matching as expected")
# np.testing.assert_allclose(RMSE_LL, 0.0, atol=1e-7,
# err_msg="The log-likelihood errors are not matching as expected")
# err_msg="The log-likelihood errors are not matching as expected")


# def test_LBFGS_serial_base(self):
# out = []
# for eng in ["LBFGS", "LBFGS_serial"]:
# engine_params = u.Param()
# engine_params.name = eng
# engine_params.numiter = 100
# engine_params.floating_intensities = False
# engine_params.reg_del2 = False
# engine_params.reg_del2_amplitude = 1.
# engine_params.scale_precond = False
# out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
# scanmodel="BlockFull", autosave=False, verbose_level="critical"))
# self.check_engine_output(out, plotting=False, debug=False)

# def test_LBFGS_serial_regularizer(self):
# out = []
# for eng in ["LBFGS", "LBFGS_serial"]:
# engine_params = u.Param()
# engine_params.name = eng
# engine_params.numiter = 90
# engine_params.floating_intensities = False
# engine_params.reg_del2 = True
# engine_params.reg_del2_amplitude = 1.
# engine_params.scale_precond = False
# out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
# scanmodel="BlockFull", autosave=False, verbose_level="critical"))
# self.check_engine_output(out, plotting=False, debug=False)
def test_LBFGS_serial_base(self):
out = []
for eng in ["LBFGS", "LBFGS_serial"]:
engine_params = u.Param()
engine_params.name = eng
engine_params.numiter = 100
engine_params.floating_intensities = False
engine_params.reg_del2 = False
engine_params.reg_del2_amplitude = 1.
engine_params.scale_precond = False
out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
scanmodel="BlockFull", autosave=False, verbose_level="critical"))
self.check_engine_output(out, plotting=False, debug=False)

def test_LBFGS_serial_regularizer(self):
out = []
for eng in ["LBFGS", "LBFGS_serial"]:
engine_params = u.Param()
engine_params.name = eng
engine_params.numiter = 90
engine_params.floating_intensities = False
engine_params.reg_del2 = True
engine_params.reg_del2_amplitude = 1.
engine_params.scale_precond = False
out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
scanmodel="BlockFull", autosave=False, verbose_level="critical"))
self.check_engine_output(out, plotting=False, debug=False)

# def test_LBFGS_serial_preconditioner(self):
# out = []
# for eng in ["LBFGS", "LBFGS_serial"]:
# engine_params = u.Param()
# engine_params.name = eng
# engine_params.numiter = 100
# engine_params.floating_intensities = False
# engine_params.reg_del2 = False
# engine_params.reg_del2_amplitude = 1.
# engine_params.scale_precond = True
# engine_params.scale_probe_object = 1e-6
# out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
# scanmodel="BlockFull", autosave=False, verbose_level="critical"))
# self.check_engine_output(out, plotting=False, debug=False)
def test_LBFGS_serial_preconditioner(self):
out = []
for eng in ["LBFGS", "LBFGS_serial"]:
engine_params = u.Param()
engine_params.name = eng
engine_params.numiter = 100
engine_params.floating_intensities = False
engine_params.reg_del2 = False
engine_params.reg_del2_amplitude = 1.
engine_params.scale_precond = True
engine_params.scale_probe_object = 1e-6
out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
scanmodel="BlockFull", autosave=False, verbose_level="critical"))
self.check_engine_output(out, plotting=False, debug=False)

# def test_LBFGS_serial_floating(self):
# out = []
# for eng in ["LBFGS", "LBFGS_serial"]:
# engine_params = u.Param()
# engine_params.name = eng
# engine_params.numiter = 100
# engine_params.floating_intensities = True
# engine_params.reg_del2 = False
# engine_params.reg_del2_amplitude = 1.
# engine_params.scale_precond = False
# out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
# scanmodel="BlockFull", autosave=False, verbose_level="critical"))
# self.check_engine_output(out, plotting=False, debug=False)
@unittest.skip("LBFGS may not work with floating intensities")
def test_LBFGS_serial_floating(self):
out = []
# fail at iter num 80
for eng in ["LBFGS", "LBFGS_serial"]:
engine_params = u.Param()
engine_params.name = eng
engine_params.numiter = 100
engine_params.floating_intensities = True
engine_params.reg_del2 = False
engine_params.reg_del2_amplitude = 1.
engine_params.scale_precond = False
out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
scanmodel="BlockFull", autosave=False, verbose_level="critical"))
self.check_engine_output(out, plotting=False, debug=False)

def test_LBFGS_serial_smoothing_regularizer(self):
out = []
Expand All @@ -151,22 +151,22 @@ def test_LBFGS_serial_smoothing_regularizer(self):
scanmodel="BlockFull", autosave=False, verbose_level="critical"))
self.check_engine_output(out, plotting=False, debug=False)

# def test_LBFGS_serial_all(self):
# out = []
# for eng in ["LBFGS", "LBFGS_serial"]:
# engine_params = u.Param()
# engine_params.name = eng
# engine_params.numiter = 100
# engine_params.floating_intensities = False
# engine_params.reg_del2 = True
# engine_params.reg_del2_amplitude = 1.
# engine_params.smooth_gradient = 20
# engine_params.smooth_gradient_decay = 1/10.
# engine_params.scale_precond = True
# engine_params.scale_probe_object = 1e-6
# out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
# scanmodel="BlockFull", autosave=False, verbose_level="critical"))
# self.check_engine_output(out, plotting=False, debug=False)
def test_LBFGS_serial_all(self):
out = []
for eng in ["LBFGS", "LBFGS_serial"]:
engine_params = u.Param()
engine_params.name = eng
engine_params.numiter = 100
engine_params.floating_intensities = False
engine_params.reg_del2 = True
engine_params.reg_del2_amplitude = 1.
engine_params.smooth_gradient = 20
engine_params.smooth_gradient_decay = 1/10.
engine_params.scale_precond = True
engine_params.scale_probe_object = 1e-6
out.append(tu.EngineTestRunner(engine_params, output_path=self.outpath, init_correct_probe=True,
scanmodel="BlockFull", autosave=False, verbose_level="critical"))
self.check_engine_output(out, plotting=False, debug=False)

if __name__ == "__main__":
unittest.main()

0 comments on commit abecab6

Please sign in to comment.