From f87ca38df53a7e9d51ae8c8cd289ae2a2b334a4f Mon Sep 17 00:00:00 2001 From: Markus Holzer <markus.holzer@fau.de> Date: Wed, 17 Nov 2021 12:37:27 +0000 Subject: [PATCH] Update python coupling --- .gitignore | 1 + CMakeLists.txt | 26 ++++---- .../FlowAroundSphereCodeGen/CMakeLists.txt | 2 - .../PhaseFieldAllenCahn/CMakeLists.txt | 2 - apps/benchmarks/UniformGridGPU/CMakeLists.txt | 1 - .../UniformGridGenerated/CMakeLists.txt | 1 - apps/pythonmodule/CMakeLists.txt | 5 +- .../PhaseFieldAllenCahn/CPU/CMakeLists.txt | 2 - .../PhaseFieldAllenCahn/GPU/CMakeLists.txt | 2 - cmake/waLBerlaHelperFunctions.cmake | 2 +- extern/pybind11 | 2 +- src/python_coupling/CMakeLists.txt | 1 - src/python_coupling/DictWrapper.h | 1 - src/python_coupling/Manager.cpp | 1 + src/python_coupling/PythonCallback.cpp | 5 +- src/python_coupling/PythonCallback.h | 8 +-- src/python_coupling/PythonWrapper.h | 8 +++ src/python_coupling/export/BasicExport.cpp | 59 ------------------- tests/python_coupling/CMakeLists.txt | 2 - tests/python_coupling/CallbackTest.cpp | 32 ++++++---- .../python_coupling/ConfigFromPythonTest.cpp | 2 +- tests/python_coupling/FieldExportTest.cpp | 28 +++++---- utilities/conda/openmesh/bld.bat | 2 +- 23 files changed, 65 insertions(+), 130 deletions(-) diff --git a/.gitignore b/.gitignore index 88f876449..4430e54af 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,4 @@ CMakeDefs.h /walberla-config.cmake /cmake-build-debug/ /cmake-build-release/ +/cmake-build-debug-remote/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ebaffc675..c1b77656f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -578,18 +578,19 @@ endif ( ) ## ############################################################################################################################# if ( WALBERLA_BUILD_WITH_CODEGEN ) - find_package( PythonInterp 3 QUIET REQUIRED) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import lbmpy" + set( Python_FIND_FRAMEWORK LAST ) + find_package (Python COMPONENTS Interpreter Development) + execute_process(COMMAND ${Python_EXECUTABLE} -c "import lbmpy" RESULT_VARIABLE LBMPY_FOUND ) if(NOT LBMPY_FOUND EQUAL 0) message(FATAL_ERROR "WALBERLA_BUILD_WITH_CODEGEN activated but pystencils or lbmpy package not found. Please install lbmpy e.g.: 'pip3 install lbmpy'") endif() - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path())" + execute_process(COMMAND ${Python_EXECUTABLE} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path())" OUTPUT_VARIABLE PYSTENCILS_INCLUDE_PATH) include_directories( ${PYSTENCILS_INCLUDE_PATH} ) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import jinja2" + execute_process(COMMAND ${Python_EXECUTABLE} -c "import jinja2" RESULT_VARIABLE JINJA2_FOUND ) if(NOT JINJA2_FOUND EQUAL 0) message(FATAL_ERROR "WALBERLA_BUILD_WITH_CODEGEN activated and jinja2 package not found. @@ -607,13 +608,8 @@ endif() ## ############################################################################################################################# if ( WALBERLA_BUILD_WITH_PYTHON ) - - find_package( PythonInterp 3.6 QUIET REQUIRED) - find_package( PythonLibs QUIET REQUIRED) - - if( NOT (PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR ) ) - message( FATAL_ERROR "Couldn't find any python library" ) - endif() + set( Python_FIND_FRAMEWORK LAST ) + find_package( Python COMPONENTS Interpreter Development REQUIRED) if(WALBERLA_CXX_COMPILER_IS_INTEL) # Intel C++17 support introduced in 2.6.2 (https://github.com/pybind/pybind11/pull/2729) @@ -622,11 +618,11 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) set(PYBIND11_MINIMUM_VERSION "2.6.0") endif() - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pybind11; print(pybind11._version.__version__)" + execute_process(COMMAND ${Python_EXECUTABLE} -c "import pybind11; print(pybind11._version.__version__)" OUTPUT_VARIABLE pybind11_VERSION ERROR_QUIET RESULT_VARIABLE pybind11_VERSION_RESULT) string(STRIP "${pybind11_VERSION}" pybind11_VERSION) if(pybind11_VERSION_RESULT EQUAL "0" AND pybind11_VERSION VERSION_GREATER_EQUAL "${PYBIND11_MINIMUM_VERSION}") - execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11 --cmakedir + execute_process(COMMAND ${Python_EXECUTABLE} -m pybind11 --cmakedir OUTPUT_VARIABLE PYBIND11_CMAKE_PATH) string(STRIP "${PYBIND11_CMAKE_PATH}" PYBIND11_CMAKE_PATH) find_package(pybind11 PATHS "${PYBIND11_CMAKE_PATH}" NO_DEFAULT_PATH REQUIRED) @@ -656,10 +652,10 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) add_subdirectory(extern/pybind11) if(pybind11_VERSION VERSION_LESS "2.6.2") - # if pybind11 was installed into ${PYTHON_INCLUDE_DIR} (e.g. by pip), that will have a higher priority than the Git submodule unless we reorder the search path + # if pybind11 was installed into ${Python_INCLUDE_DIRS} (e.g. by pip), that will have a higher priority than the Git submodule unless we reorder the search path # introduced in 2.6.0 (https://github.com/pybind/pybind11/issues/2709), fixed in 2.6.2 (https://github.com/pybind/pybind11/pull/2716) set_property( TARGET pybind11::pybind11 - PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/extern/pybind11/include" "${PYTHON_INCLUDE_DIR}") + PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/extern/pybind11/include" "${Python_INCLUDE_DIRS}") endif() endif() diff --git a/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt b/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt index 6f7a128f3..a598b3323 100644 --- a/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt +++ b/apps/benchmarks/FlowAroundSphereCodeGen/CMakeLists.txt @@ -13,7 +13,6 @@ if (WALBERLA_BUILD_WITH_CUDA) FlowAroundSphereCodeGen_InfoHeader.h) waLBerla_add_executable( NAME FlowAroundSphereCodeGen FILE FlowAroundSphereCodeGen.cpp DEPENDS blockforest boundary core domain_decomposition field geometry timeloop vtk FlowAroundSphereGenerated) - set_target_properties( FlowAroundSphereCodeGen PROPERTIES CXX_VISIBILITY_PRESET hidden) else () waLBerla_generate_target_from_python(NAME FlowAroundSphereGenerated FILE FlowAroundSphereCodeGen.py @@ -27,5 +26,4 @@ else () FlowAroundSphereCodeGen_InfoHeader.h) waLBerla_add_executable( NAME FlowAroundSphereCodeGen FILE FlowAroundSphereCodeGen.cpp DEPENDS blockforest boundary core domain_decomposition field geometry timeloop vtk FlowAroundSphereGenerated) - set_target_properties( FlowAroundSphereCodeGen PROPERTIES CXX_VISIBILITY_PRESET hidden) endif() \ No newline at end of file diff --git a/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt b/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt index 951f04a22..629c9ec0a 100644 --- a/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt +++ b/apps/benchmarks/PhaseFieldAllenCahn/CMakeLists.txt @@ -16,7 +16,6 @@ if (WALBERLA_BUILD_WITH_CUDA) waLBerla_add_executable(NAME benchmark_multiphase FILES benchmark_multiphase.cpp InitializerFunctions.cpp multiphase_codegen.py DEPENDS blockforest core cuda field postprocessing lbm geometry timeloop gui BenchmarkPhaseFieldCodeGenGPU) - set_target_properties(benchmark_multiphase PROPERTIES CXX_VISIBILITY_PRESET hidden) else () waLBerla_generate_target_from_python(NAME BenchmarkPhaseFieldCodeGenCPU FILE multiphase_codegen.py @@ -32,6 +31,5 @@ else () waLBerla_add_executable(NAME benchmark_multiphase FILES benchmark_multiphase.cpp InitializerFunctions.cpp multiphase_codegen.py DEPENDS blockforest core field postprocessing lbm geometry timeloop gui BenchmarkPhaseFieldCodeGenCPU) - set_target_properties(benchmark_multiphase PROPERTIES CXX_VISIBILITY_PRESET hidden) endif (WALBERLA_BUILD_WITH_CUDA) diff --git a/apps/benchmarks/UniformGridGPU/CMakeLists.txt b/apps/benchmarks/UniformGridGPU/CMakeLists.txt index a3a430204..d084f8171 100644 --- a/apps/benchmarks/UniformGridGPU/CMakeLists.txt +++ b/apps/benchmarks/UniformGridGPU/CMakeLists.txt @@ -25,7 +25,6 @@ foreach(streaming_pattern pull push aa esotwist) waLBerla_add_executable(NAME UniformGridGPU_${config} FILES UniformGridGPU.cpp DEPENDS blockforest boundary core cuda domain_decomposition field geometry timeloop vtk UniformGridGPUGenerated_${config}) - set_target_properties( UniformGridGPU_${config} PROPERTIES CXX_VISIBILITY_PRESET hidden) # all configs are excluded from all except for pull d3q27. if (${streaming_pattern} STREQUAL "pull" AND ${stencil} STREQUAL "d3q27") diff --git a/apps/benchmarks/UniformGridGenerated/CMakeLists.txt b/apps/benchmarks/UniformGridGenerated/CMakeLists.txt index d0b16d6e2..dda05f8fd 100644 --- a/apps/benchmarks/UniformGridGenerated/CMakeLists.txt +++ b/apps/benchmarks/UniformGridGenerated/CMakeLists.txt @@ -16,6 +16,5 @@ foreach(config srt trt smagorinsky mrt entropic_kbc_n4 cumulant ) FILES UniformGridGenerated.cpp DEPENDS blockforest boundary core domain_decomposition field geometry timeloop vtk gui UniformGridGenerated_${config} python_coupling) - set_target_properties(UniformGridBenchmarkGenerated_${config} PROPERTIES CXX_VISIBILITY_PRESET hidden) endforeach() diff --git a/apps/pythonmodule/CMakeLists.txt b/apps/pythonmodule/CMakeLists.txt index 38290ffa5..ee58a3257 100644 --- a/apps/pythonmodule/CMakeLists.txt +++ b/apps/pythonmodule/CMakeLists.txt @@ -25,10 +25,9 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) SUFFIX "${PYTHON_MODULE_EXTENSION}" ) set_target_properties( walberla_cpp PROPERTIES MACOSX_RPATH TRUE ) - set_target_properties( walberla_cpp PROPERTIES CXX_VISIBILITY_PRESET hidden) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) - add_custom_target( pythonModule ALL ${PYTHON_EXECUTABLE} setup.py build DEPENDS walberla_cpp ) - add_custom_target( pythonModuleInstall ${PYTHON_EXECUTABLE} setup.py install --user DEPENDS walberla_cpp ) + add_custom_target( pythonModule ALL ${Python_EXECUTABLE} setup.py build DEPENDS walberla_cpp ) + add_custom_target( pythonModuleInstall ${Python_EXECUTABLE} setup.py install --user DEPENDS walberla_cpp ) endif() diff --git a/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt b/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt index cf550a8e1..07cc9000e 100644 --- a/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt +++ b/apps/showcases/PhaseFieldAllenCahn/CPU/CMakeLists.txt @@ -19,5 +19,3 @@ waLBerla_generate_target_from_python(NAME PhaseFieldCodeGenCPU waLBerla_add_executable(NAME multiphaseCPU FILES multiphase.cpp PythonExports.cpp InitializerFunctions.cpp multiphase_codegen.py DEPENDS blockforest core field postprocessing lbm geometry timeloop gui PhaseFieldCodeGenCPU) - -set_target_properties(multiphaseCPU PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt b/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt index a8ff39721..8cd135d56 100644 --- a/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt +++ b/apps/showcases/PhaseFieldAllenCahn/GPU/CMakeLists.txt @@ -19,5 +19,3 @@ waLBerla_generate_target_from_python(NAME PhaseFieldCodeGenGPU waLBerla_add_executable(NAME multiphaseGPU FILES multiphase.cpp PythonExports.cpp InitializerFunctions.cpp util.cpp multiphase_codegen.py DEPENDS blockforest core cuda field postprocessing lbm geometry timeloop gui PhaseFieldCodeGenGPU) - -set_target_properties(multiphaseGPU PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/cmake/waLBerlaHelperFunctions.cmake b/cmake/waLBerlaHelperFunctions.cmake index 50e457c07..b8c0f2ecb 100644 --- a/cmake/waLBerlaHelperFunctions.cmake +++ b/cmake/waLBerlaHelperFunctions.cmake @@ -79,7 +79,7 @@ function( waLBerla_generate_target_from_python ) add_custom_command(OUTPUT ${generatedWithAbsolutePath} DEPENDS ${sourceFile} - COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${WALBERLA_PYTHON_DIR}:$ENV{PYTHONPATH} ${PYTHON_EXECUTABLE} ${sourceFile} ${pythonParameters} + COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${WALBERLA_PYTHON_DIR}:$ENV{PYTHONPATH} ${Python_EXECUTABLE} ${sourceFile} ${pythonParameters} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${codegenCfg}") add_library(${PYGEN_NAME} ${generatedWithAbsolutePath}) diff --git a/extern/pybind11 b/extern/pybind11 index 8de7772cc..f7b499615 160000 --- a/extern/pybind11 +++ b/extern/pybind11 @@ -1 +1 @@ -Subproject commit 8de7772cc72daca8e947b79b83fea46214931604 +Subproject commit f7b499615e14d70ab098a20deb0cdb3889998a1a diff --git a/src/python_coupling/CMakeLists.txt b/src/python_coupling/CMakeLists.txt index 882a6d559..758289636 100644 --- a/src/python_coupling/CMakeLists.txt +++ b/src/python_coupling/CMakeLists.txt @@ -1,5 +1,4 @@ if (WALBERLA_BUILD_WITH_PYTHON) waLBerla_add_module(DEPENDS core communication domain_decomposition stencil field blockforest vtk cuda) target_link_libraries(python_coupling PUBLIC pybind11::embed core domain_decomposition) - set_target_properties(python_coupling PROPERTIES CXX_VISIBILITY_PRESET hidden) endif() \ No newline at end of file diff --git a/src/python_coupling/DictWrapper.h b/src/python_coupling/DictWrapper.h index c7f1f9511..c51902cfa 100644 --- a/src/python_coupling/DictWrapper.h +++ b/src/python_coupling/DictWrapper.h @@ -60,7 +60,6 @@ namespace python_coupling { #ifdef WALBERLA_BUILD_WITH_PYTHON - public: pybind11::dict & dict() { return d_; } const pybind11::dict & dict() const { return d_; } protected: diff --git a/src/python_coupling/Manager.cpp b/src/python_coupling/Manager.cpp index 4b22df974..eaae658ad 100644 --- a/src/python_coupling/Manager.cpp +++ b/src/python_coupling/Manager.cpp @@ -97,6 +97,7 @@ void Manager::triggerInitialization() py::module::import("__main__"); py::module::import("walberla_cpp"); + // Setup python path addPath( std::string(WALBERLA_SOURCE_DIR) + "/python" ); diff --git a/src/python_coupling/PythonCallback.cpp b/src/python_coupling/PythonCallback.cpp index b4d0fb6d8..61ef6a1cc 100644 --- a/src/python_coupling/PythonCallback.cpp +++ b/src/python_coupling/PythonCallback.cpp @@ -22,7 +22,7 @@ #include "PythonCallback.h" #include "DictWrapper.h" - +#include "core/logging/all.h" #ifdef WALBERLA_BUILD_WITH_PYTHON #include "Manager.h" @@ -69,7 +69,6 @@ namespace python_coupling { } catch ( py::error_already_set &e) { throw py::value_error(e.what()); - return py::none(); } } @@ -122,7 +121,7 @@ namespace python_coupling { { if ( ! isCallable() ) WALBERLA_ABORT_NO_DEBUG_INFO( "Could not call python function '" << functionName_ << "'. " << - "Did you forget to set the callback function?" ); + "Did you forget to set the callback function?" ) namespace py = pybind11; diff --git a/src/python_coupling/PythonCallback.h b/src/python_coupling/PythonCallback.h index 5d7aeb48c..038b544a2 100644 --- a/src/python_coupling/PythonCallback.h +++ b/src/python_coupling/PythonCallback.h @@ -82,8 +82,8 @@ namespace python_coupling { PythonCallback(); PythonCallback( const std::string & functionName ); PythonCallback( const std::string & moduleOrFile, - const std::string & functionName, - const std::vector<std::string> & argv = std::vector<std::string>() ); + const std::string & functionName, + const std::vector<std::string> & argv = std::vector<std::string>() ); DictWrapper & data() { return *exposedVars_; } const DictWrapper & data() const { return *exposedVars_; } @@ -97,9 +97,5 @@ namespace python_coupling { shared_ptr<DictWrapper> callbackDict_; }; - - } // namespace python_coupling } // namespace walberla - - diff --git a/src/python_coupling/PythonWrapper.h b/src/python_coupling/PythonWrapper.h index 9e1bfe173..d609230d6 100644 --- a/src/python_coupling/PythonWrapper.h +++ b/src/python_coupling/PythonWrapper.h @@ -28,6 +28,14 @@ #ifdef WALBERLA_BUILD_WITH_PYTHON // macro defined in waLBerlaDefinitions.h +#define PYBIND11_NAMESPACE walberla::pybind11 + +namespace PYBIND11_NAMESPACE {} +namespace pybind11 { + // pybind11 uses ::pybind11 in a few places internally, so we need this alias + using namespace PYBIND11_NAMESPACE; +} + #include "pybind11/pybind11.h" #endif diff --git a/src/python_coupling/export/BasicExport.cpp b/src/python_coupling/export/BasicExport.cpp index 767a6fd0c..22b444d1b 100644 --- a/src/python_coupling/export/BasicExport.cpp +++ b/src/python_coupling/export/BasicExport.cpp @@ -373,63 +373,6 @@ void timingTreeStopWrapper(WcTimingTree & tt, const std::string& name) tt.stop(name); } -void exportTiming(py::module_ &m) -{ - py::class_<WcTimer> (m, "Timer") - .def( py::init<>() ) - .def( "start", &WcTimer::start ) - .def( "stop", &WcTimer::end ) - .def( "reset", &WcTimer::reset ) - .def( "merge", &WcTimer::merge ) - .def_property_readonly( "counter", &WcTimer::getCounter ) - .def_property_readonly( "total", &WcTimer::total ) - .def_property_readonly( "sumOfSquares", &WcTimer::sumOfSquares ) - .def_property_readonly( "average", &WcTimer::average ) - .def_property_readonly( "variance", &WcTimer::variance ) - .def_property_readonly( "min", &WcTimer::min ) - .def_property_readonly( "max", &WcTimer::max ) - .def_property_readonly( "last", &WcTimer::last ) - ; - - - WcTimer & ( WcTimingPool::*pGetItem ) ( const std::string & ) = &WcTimingPool::operator[]; - - { - py::scope classScope = - py::class_<WcTimingPool, shared_ptr<WcTimingPool> > (m, "TimingPool") - .def( py::init<>() ) - .def_property_readonly( "__getitem__", pGetItem) - .def( "__contains__", &WcTimingPool::timerExists ) - .def( "getReduced", &WcTimingPool::getReduced) - .def( "merge", &WcTimingPool::merge) - .def( "clear", &WcTimingPool::clear ) - .def( "unifyRegisteredTimersAcrossProcesses", &WcTimingPool::unifyRegisteredTimersAcrossProcesses ) - .def( "logResultOnRoot", &WcTimingPool::logResultOnRoot) - ; - WALBERLA_UNUSED( classScope ); - - py::enum_<timing::ReduceType>(m, "ReduceType") - .value("min" , timing::REDUCE_MIN) - .value("avg" , timing::REDUCE_AVG) - .value("max" , timing::REDUCE_MAX) - .value("total", timing::REDUCE_TOTAL) - .export_values() - ; - } - - const WcTimer & ( WcTimingTree::*pTimingTreeGet ) ( const std::string & ) const = &WcTimingTree::operator[]; - py::class_<WcTimingTree, shared_ptr<WcTimingTree> > (m, "TimingTree") - .def( py::init<>() ) - .def_property_readonly( "__getitem__", pTimingTreeGet ) - .def( "start", &WcTimingTree::start ) - .def( "stop", &timingTreeStopWrapper ) - .def( "getReduced", &WcTimingTree::getReduced ) - .def( "toDict", &buildDictFromTimingTree ) - ; -} - - - //====================================================================================================================== // @@ -700,8 +643,6 @@ void exportBasicWalberlaDatastructures(py::module_ &m) exportCellInterval(m); exportAABB(m); - exportTiming(m); - exportIBlock(m); exportCommunication(m); diff --git a/tests/python_coupling/CMakeLists.txt b/tests/python_coupling/CMakeLists.txt index 462c2b8f2..81ab5fc72 100644 --- a/tests/python_coupling/CMakeLists.txt +++ b/tests/python_coupling/CMakeLists.txt @@ -14,12 +14,10 @@ if (WALBERLA_BUILD_WITH_PYTHON) waLBerla_compile_test( FILES CallbackTest.cpp DEPENDS blockforest field ) waLBerla_execute_test( NAME CallbackTest COMMAND $<TARGET_FILE:CallbackTest> ${CMAKE_CURRENT_SOURCE_DIR}/CallbackTest.py ) - set_target_properties(CallbackTest PROPERTIES CXX_VISIBILITY_PRESET hidden) waLBerla_compile_test( FILES FieldExportTest.cpp DEPENDS blockforest field ) waLBerla_execute_test( NAME FieldExportTest COMMAND $<TARGET_FILE:FieldExportTest> ${CMAKE_CURRENT_SOURCE_DIR}/FieldExportTest.py ) - set_target_properties(FieldExportTest PROPERTIES CXX_VISIBILITY_PRESET hidden) add_test( NAME PythonWalberlaTest COMMAND python3 -m unittest discover waLBerla_tests/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python/) diff --git a/tests/python_coupling/CallbackTest.cpp b/tests/python_coupling/CallbackTest.cpp index 08790f31f..be90b3055 100644 --- a/tests/python_coupling/CallbackTest.cpp +++ b/tests/python_coupling/CallbackTest.cpp @@ -32,14 +32,18 @@ using namespace walberla; +using ScalarField = GhostLayerField<int, 1>; + int main( int argc, char ** argv ) { auto pythonManager = python_coupling::Manager::instance(); - pythonManager->addExporterFunction( field::exportModuleToPython<Field<int,1>> ); + pythonManager->addExporterFunction( field::exportModuleToPython<Field<int, 1>> ); + pythonManager->triggerInitialization(); - if ( argc != 2 ) { - WALBERLA_ABORT_NO_DEBUG_INFO("Wrong parameter count: \nUsage: \n ./CallbackTest CallbackTest.py"); + if ( argc != 2 ) + { + WALBERLA_ABORT_NO_DEBUG_INFO("Wrong parameter count: \nUsage: \n ./CallbackTest CallbackTest.py") } std::string pythonFile ( argv[1] ); @@ -58,25 +62,27 @@ int main( int argc, char ** argv ) // This callback should sum up the two given integers python_coupling::PythonCallback cb1 ( pythonFile, "cb1" ); - WALBERLA_ASSERT( cb1.isCallable() ); + WALBERLA_ASSERT( cb1.isCallable() ) + cb1.data().exposeValue("input1", 5); cb1.data().exposeValue("input2", 10); cb1(); + int result = cb1.data().get<int>( "returnValue" ); - WALBERLA_CHECK_EQUAL( result, 15 ); - typedef GhostLayerField<int,1> ScalarField; + WALBERLA_CHECK_EQUAL( result, 15 ) + + ScalarField f ( 3,2,2, 1, 25 ); python_coupling::PythonCallback cb2 ( pythonFile, "cb2" ); - WALBERLA_ASSERT( cb2.isCallable() ); + + WALBERLA_ASSERT( cb2.isCallable() ) + cb2.data().exposePtr("field", &f ); cb2(); - WALBERLA_CHECK_EQUAL( f(0,0,0), 42 ); - WALBERLA_CHECK_EQUAL( f(-1,-1,-1), 5 ); - - //python_coupling::Shell shell("MyGreatInputShell"); - //shell(); + WALBERLA_CHECK_EQUAL( f(0,0,0), 42 ) + WALBERLA_CHECK_EQUAL( f(-1,-1,-1), 5 ) - return 0; + return EXIT_SUCCESS; } diff --git a/tests/python_coupling/ConfigFromPythonTest.cpp b/tests/python_coupling/ConfigFromPythonTest.cpp index 7b3437463..33a822699 100644 --- a/tests/python_coupling/ConfigFromPythonTest.cpp +++ b/tests/python_coupling/ConfigFromPythonTest.cpp @@ -55,7 +55,7 @@ int main(int argc, char** argv) WALBERLA_CHECK(testString == "someString") WALBERLA_CHECK(testDouble > 42 && testDouble < 43) - WALBERLA_CHECK(testVector == Vector3< real_t >(0.5, 0.5, 0.7)) + WALBERLA_CHECK(testVector == Vector3< real_t >(real_c(0.5), real_c(0.5), real_c(0.7))) WALBERLA_CHECK(testBool == false) WALBERLA_LOG_INFO_ON_ROOT(test_int) diff --git a/tests/python_coupling/FieldExportTest.cpp b/tests/python_coupling/FieldExportTest.cpp index b78bc3682..eb7d5020d 100644 --- a/tests/python_coupling/FieldExportTest.cpp +++ b/tests/python_coupling/FieldExportTest.cpp @@ -32,6 +32,7 @@ #include "python_coupling/PythonWrapper.h" #include "python_coupling/export/BlockForestExport.h" #include "python_coupling/export/FieldExports.h" +#include <pybind11/embed.h> #include "stencil/D2Q9.h" @@ -44,11 +45,18 @@ int main( int argc, char ** argv ) debug::enterTestMode(); mpi::Environment mpiEnv( argc, argv ); + if ( argc != 2 ) + { + WALBERLA_ABORT_NO_DEBUG_INFO("Wrong parameter count: \nUsage: \n ./FieldExportTest FieldExportTest.py") + } + std::string pythonFile ( argv[1] ); + auto pythonManager = python_coupling::Manager::instance(); pythonManager->addExporterFunction( field::exportModuleToPython<Field<int, 3>, Field<real_t, 3>> ); pythonManager->addBlockDataConversion< Field<int, 3>, Field<real_t, 3> >() ; pythonManager->addExporterFunction( blockforest::exportModuleToPython<stencil::D2Q9> ); + pythonManager->triggerInitialization(); shared_ptr< StructuredBlockForest > blocks = blockforest::createUniformBlockGrid( 1,1,1, 20,20,1, real_t(1.0), false, true,true,true ); @@ -58,7 +66,6 @@ int main( int argc, char ** argv ) auto srcDoubleFieldID = field::addToStorage< GhostLayerField<real_t, 3> >( blocks, "srcDoubleFieldID", real_t(0.0), field::fzyx, 1 ); auto dstDoubleFieldID = field::addToStorage< GhostLayerField<real_t, 3> >( blocks, "dstDoubleFieldID", real_t(0.0), field::fzyx, 1 ); - // random init for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt ) { @@ -70,14 +77,11 @@ int main( int argc, char ** argv ) *cellIt = math::realRandom( real_t(0.0), real_t(42.0) ); } - // call python function which should copy over the values to the Vector fields - std::string pythonFile ( argv[1] ); python_coupling::PythonCallback cb ( pythonFile, "theCallback" ); - WALBERLA_ASSERT( cb.isCallable() ); + WALBERLA_ASSERT( cb.isCallable() ) cb.data().exposeValue("blocks", blocks); cb(); - // check for equivalence for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt ) { @@ -91,20 +95,18 @@ int main( int argc, char ** argv ) for(cell_idx_t y = 0; y < cell_idx_c(srcIntField->zSize()); ++y) for(cell_idx_t x = 0; x < cell_idx_c(srcIntField->zSize()); ++x) { - WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 0), dstIntField->get(x,y,z, 0) ); - WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 1), dstIntField->get(x,y,z, 1) ); + WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 0), dstIntField->get(x,y,z, 0) ) + WALBERLA_CHECK_EQUAL( srcIntField->get(x,y,z, 1), dstIntField->get(x,y,z, 1) ) } for(cell_idx_t z = 0; z < cell_idx_c(srcDoubleField->zSize()); ++z) for(cell_idx_t y = 0; y < cell_idx_c(srcDoubleField->zSize()); ++y) for(cell_idx_t x = 0; x < cell_idx_c(srcDoubleField->zSize()); ++x) { - WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 0), dstDoubleField->get(x,y,z, 0) ); - WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 1), dstDoubleField->get(x,y,z, 1) ); - WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 2), dstDoubleField->get(x,y,z, 2) ); + WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 0), dstDoubleField->get(x,y,z, 0) ) + WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 1), dstDoubleField->get(x,y,z, 1) ) + WALBERLA_CHECK_FLOAT_EQUAL( srcDoubleField->get(x,y,z, 2), dstDoubleField->get(x,y,z, 2) ) } } } - - - return 0; + return EXIT_SUCCESS; } diff --git a/utilities/conda/openmesh/bld.bat b/utilities/conda/openmesh/bld.bat index a5583cece..d8e5fcb3a 100644 --- a/utilities/conda/openmesh/bld.bat +++ b/utilities/conda/openmesh/bld.bat @@ -10,7 +10,7 @@ cmake -LAH -G"Visual Studio 15 2017 Win64" ^ -DCMAKE_FIND_ROOT_PATH="%LIBRARY_PREFIX%" ^ -DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^ -DBUILD_APPS=OFF ^ - -DPYTHON_LIBRARY:FILEPATH="%PYTHON_LIBRARY%" ^ + -DPython_EXECUTABLE:FILEPATH="%PYTHON_LIBRARY%" ^ -DOPENMESH_PYTHON_VERSION="%PY_VER%" ^ -DPYTHON_INSTALL_DIR="%SP_DIR%" ^ -DOPENMESH_BUILD_PYTHON_UNIT_TESTS=ON .. -- GitLab