Skip to content

Commit 223dc5a

Browse files
committed
Adding option to print full error information for HPX exceptions
- add PHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS cmake variable - enable this option for CircleCI - adding ability to add to the Phylanx session configuration through PHYLANX_PYTHON_CONFIG environment variable - adding --hpx:ini=phylanx.full_error_diagnostics!=1 to enable full error diagnostics from Python code
1 parent da3d150 commit 223dc5a

6 files changed

Lines changed: 61 additions & 5 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ jobs:
153153
-DPHYLANX_WITH_ITERATIVE_SOLVERS=ON \
154154
-DPHYLANX_WITH_DOCUMENTATION=ON \
155155
-DPHYLANX_WITH_HIGHFIVE=OFF \
156-
-DPHYLANX_WITH_CXX17=ON
156+
-DPHYLANX_WITH_CXX17=ON \
157+
-DPHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS=On
157158
- persist_to_workspace:
158159
root: /
159160
paths:

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ phylanx_option(
9595
"Enable or disable the compilation of benchmark tests"
9696
ON ADVANCED CATEGORY "Build")
9797

98+
phylanx_option(
99+
PHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS BOOL
100+
"Python tests emit the full HPX diagnostics if exceptions are thrown"
101+
OFF ADVANCED CATEGORY "Build")
102+
98103
phylanx_option(
99104
PHYLANX_WITH_TESTS_REGRESSIONS BOOL
100105
"Enable or disable the compilation of regression tests"

cmake/Phylanx_AddPythonTest.cmake

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,27 @@ macro(add_phylanx_python_test category name)
3030
phylanx_debug("add_phylanx_python_test (${name})" "WORKING_DIRECTORY: ${_working_directory}")
3131

3232
set(_environment)
33+
if(PHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS)
34+
set(_environment
35+
PHYLANX_PYTHON_CONFIG="--hpx:ini=phylanx.full_error_diagnostics!=1"
36+
)
37+
endif()
3338
if(${name}_ENVIRONMENT)
3439
if(MSVC)
35-
set(_environment ${CMAKE_COMMAND} -E env "${${name}_ENVIRONMENT}")
40+
if(NOT ("${_environment}x" STREQUAL "x"))
41+
set(_environment ${CMAKE_COMMAND} -E env "${_environment}\;${${name}_ENVIRONMENT}")
42+
else()
43+
set(_environment ${CMAKE_COMMAND} -E env "${${name}_ENVIRONMENT}")
44+
endif()
3645
else()
37-
set(_environment ENVIRONMENT "${${name}_ENVIRONMENT}")
46+
if(NOT ("${_environment}x" STREQUAL "x"))
47+
set(_environment ENVIRONMENT "${_environment}:${${name}_ENVIRONMENT}")
48+
else()
49+
set(_environment ENVIRONMENT "${${name}_ENVIRONMENT}")
50+
endif()
3851
endif()
3952
endif()
40-
phylanx_debug("add_phylanx_python_test (${name})" "ENVIRONMENT: ${_environment}")
53+
phylanx_info("add_phylanx_python_test (${name})" "ENVIRONMENT: ${_environment}")
4154

4255
set(script ${CMAKE_CURRENT_SOURCE_DIR}/${${name}_SCRIPT})
4356

python/phylanx/core/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from phylanx.core import init_hpx_runtime
77
from phylanx.exceptions import RuntimeAlreadyInitializedError
88

9+
import os, platform
10+
911

1012
class PhylanxSession:
1113
cfg = [
@@ -30,6 +32,17 @@ def init(num_threads=1):
3032
if not PhylanxSession.is_initialized:
3133
hpx_thread = "hpx.os_threads!=%s" % num_threads
3234
PhylanxSession.cfg[3] = hpx_thread
35+
36+
# append additional config settings taken from the environment
37+
if 'PHYLANX_PYTHON_CONFIG' in os.environ:
38+
if platform.system() == "Windows":
39+
sep = ';'
40+
else:
41+
sep = ':'
42+
43+
for e in os.environ['PHYLANX_PYTHON_CONFIG'].split(sep):
44+
PhylanxSession.cfg.append(e)
45+
3346
init_hpx_runtime(PhylanxSession.cfg)
3447
PhylanxSession.is_initialized = True
3548
else:

python/src/bindings/execution_tree.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,28 @@ void phylanx::bindings::bind_execution_tree(pybind11::module m)
307307
});
308308
},
309309
"wait for future to become ready");
310+
311+
// translate HPX exceptions and provide more error information, if desired
312+
static pybind11::exception<hpx::exception> exc(
313+
m, "HPXError", PyExc_RuntimeError);
314+
315+
pybind11::register_exception_translator([](std::exception_ptr p) {
316+
try
317+
{
318+
if (p)
319+
std::rethrow_exception(p);
320+
}
321+
catch (hpx::exception& e)
322+
{
323+
if (hpx::get_config_entry("phylanx.full_error_diagnostics", "0") ==
324+
"1")
325+
{
326+
exc(hpx::diagnostic_information(e).c_str());
327+
}
328+
else
329+
{
330+
exc(e.what());
331+
}
332+
}
333+
});
310334
}

tests/unit/python/distributed/simple_remote_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def sleep(x):
1818

1919
@Phylanx
2020
def call_sleep():
21-
sleep(1000) # sleep for 1 second
21+
sleep1(1000) # sleep for 1 second
2222
return
2323

2424

0 commit comments

Comments
 (0)