Commit 08f17992 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

+ Example fit_rosenbrock

parent b8ff8811
#!/usr/bin/env python3
import bornagain as ba
def rosenbrock(params):
x = params["x"].value
y = params["y"].value
tmp1 = y - x * x
tmp2 = 1 - x
return 100 * tmp1 * tmp1 + tmp2 * tmp2
params = ba.Parameters()
params.add("x", value=-1.2, min=-5.0, max=5.0, step=0.01)
params.add("y", value=1.0, min=-5.0, max=5.0, step=0.01)
minimizer = ba.Minimizer()
result = minimizer.minimize(rosenbrock, params)
print(result.toString())
###############################################################################
# Run unmodified examples
###############################################################################
set(test_script ${TOOL_DIR}/code/batch-plot.py)
set(output_dir ${TEST_OUTPUT_DIR_PY_EXAMPLES}) set(output_dir ${TEST_OUTPUT_DIR_PY_EXAMPLES})
file(MAKE_DIRECTORY ${output_dir}) file(MAKE_DIRECTORY ${output_dir})
####################################################################################################
# Run examples that don't plot
####################################################################################################
function(run_noplot example)
get_filename_component(name ${example} NAME_WE)
set(test_name Example.exec.${name})
add_test(${test_name}
env PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
${Python3_EXECUTABLE} ${example} ${output_dir})
endfunction()
file(GLOB ex_noplot
${EXAMPLES_DIR}/fit/algo/*.py
)
foreach(example ${ex_noplot})
run_noplot(${example})
endforeach()
####################################################################################################
# Run unmodified examples, with plots under batch control
####################################################################################################
set(test_script ${TOOL_DIR}/code/batch-plot.py)
# Run one Python example. # Run one Python example.
# Check whether the example passes. # Check whether the example passes.
# Don't check results. # Don't check results.
...@@ -46,9 +65,9 @@ file(GLOB examples ...@@ -46,9 +65,9 @@ file(GLOB examples
${EXAMPLES_DIR}/fit55_Specular/FitSpecularBasics.py) ${EXAMPLES_DIR}/fit55_Specular/FitSpecularBasics.py)
run_examples("${examples}" "") run_examples("${examples}" "")
############################################################################ ####################################################################################################
# Check results of modified examples # Persistence tests: Run modified examples, and check results against references
############################################################################ ####################################################################################################
set(OUTPUT_DIR ${TEST_OUTPUT_DIR_PY_PERSIST}) set(OUTPUT_DIR ${TEST_OUTPUT_DIR_PY_PERSIST})
file(MAKE_DIRECTORY ${OUTPUT_DIR}) file(MAKE_DIRECTORY ${OUTPUT_DIR})
......
Supports Markdown
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