diff --git a/Tests/Py/Fit/CMakeLists.txt b/Tests/Py/Fit/CMakeLists.txt index 9b379d690ea988171451d8b7244e10f7195126d2..25fde18a3ae1c3ff92b44d2a066de0de2ca13f79 100644 --- a/Tests/Py/Fit/CMakeLists.txt +++ b/Tests/Py/Fit/CMakeLists.txt @@ -12,7 +12,7 @@ file(GLOB tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py) foreach(_test ${tests}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${_test} ${output_dir}/${_test} COPYONLY) - add_test(NAME PyFit.${_test} + add_test(NAME Py.Fit.${_test} COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} ${output_dir}/${_test}) endforeach() diff --git a/Tests/Py/Fit/README.md b/Tests/Py/Fit/README.md index 003cc60e8a4647cc10ded63f04bfe8ca8b62b7fb..a6048a5dac661cfc621ffcea8135419495b6fa2e 100644 --- a/Tests/Py/Fit/README.md +++ b/Tests/Py/Fit/README.md @@ -3,6 +3,3 @@ Collection of fitting tests for libBornAgainFit library. Different geometries, number of fit parameters, variety of minimizers and minimization strategies. - -Tests are executed automatically when user builds the -whole project with 'check' target cmake; make check diff --git a/Tests/Py/Fit/standalone_fits.py b/Tests/Py/Fit/standalone_fits.py index 42b4b9a4e9c1969e82979dd77927139a07899497..652016f119eeed54b2aa91d57d225f0c01607bb0 100644 --- a/Tests/Py/Fit/standalone_fits.py +++ b/Tests/Py/Fit/standalone_fits.py @@ -13,14 +13,9 @@ class Rosenbrock: self.m_expected_params = [1, 1.0] def objective_function(self, params): - """ - Returns the value of Rosenbrock function - """ x = params["x"].value y = params["y"].value - tmp1 = y - x * x - tmp2 = 1 - x - return 100 * tmp1 * tmp1 + tmp2 * tmp2 + return (1 - x)**2 + 100 * (y - x**2)**2 def decaying_sin(params, x): @@ -51,29 +46,40 @@ class DecayingSin: class StandaloneFitTest(unittest.TestCase): - def test_RosenbrockFit(self): - """ - Testing fit of rosenbrock function - """ - params = ba.Parameters() - params.add(ba.Parameter("x", -1.2, ba.AttLimits.limited(-5, 5), 0.01)) - params.add(ba.Parameter("y", 1, ba.AttLimits.limited(-5, 5), 0.01)) - - model = Rosenbrock() - minimizer = ba.Minimizer() - result = minimizer.minimize(model.objective_function, params) - - print(result.toString()) - - # check found parameter values - np.testing.assert_almost_equal(result.parameters().values(), - model.m_expected_params, 2) - - # check found minimum - np.testing.assert_almost_equal(result.minValue(), - model.m_expected_minimum, 2) +# Rosenbrock fit test disabled while waiting for ways to set tolerance etc +# (https://jugit.fz-juelich.de/mlz/bornagain/-/issues/693) +# +# def test_RosenbrockFit(self): +# print("\nStandalone fit test: Rosenbrock function") +# +# params = ba.Parameters() +# params.add(ba.Parameter("x", -1.2, ba.AttLimits.limited(-5, 5), 0.01)) +# params.add(ba.Parameter("y", 1, ba.AttLimits.limited(-5, 5), 0.01)) +# +# model = Rosenbrock() +# minimizer = ba.Minimizer() +# options = ba.MinimizerOptions() +# options.addOption("Strategy", 2); +# options.addOption("Tolerance", 1e-10); +# minimizer.setOptions(options) +# +# result = minimizer.minimize(model.objective_function, params) +# +# print(result.toString()) +# +# # check found parameter values +# np.testing.assert_almost_equal(result.parameters().values(), +# model.m_expected_params, 2) +# +# # check found minimum +# np.testing.assert_almost_equal(result.minValue(), +# model.m_expected_minimum, 2) +# +# print("Done with Rosenbrock function\n") def test_DecayingSinFit(self): + print("\nStandalone fit test: Decaying sin function") + params = ba.Parameters() params.add(ba.Parameter('amp', 1, ba.AttLimits.positive())) params.add(ba.Parameter('decay', 0.1, ba.AttLimits.positive())) @@ -90,6 +96,7 @@ class StandaloneFitTest(unittest.TestCase): np.testing.assert_almost_equal(result.parameters().values(), model.m_params.values(), 3) + print("Done with decaying sin function\n") if __name__ == '__main__': unittest.main()