Skip to content

Commit

Permalink
Adding option to print full error information for HPX exceptions
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
hkaiser committed May 16, 2020
1 parent da3d150 commit e91cb62
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ jobs:
-DPHYLANX_WITH_ITERATIVE_SOLVERS=ON \
-DPHYLANX_WITH_DOCUMENTATION=ON \
-DPHYLANX_WITH_HIGHFIVE=OFF \
-DPHYLANX_WITH_CXX17=ON
-DPHYLANX_WITH_CXX17=ON \
-DPHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS=On
- persist_to_workspace:
root: /
paths:
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ phylanx_option(
"Enable or disable the compilation of benchmark tests"
ON ADVANCED CATEGORY "Build")

phylanx_option(
PHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS BOOL
"Python tests emit the full HPX diagnostics if exceptions are thrown"
OFF ADVANCED CATEGORY "Build")

phylanx_option(
PHYLANX_WITH_TESTS_REGRESSIONS BOOL
"Enable or disable the compilation of regression tests"
Expand Down
9 changes: 7 additions & 2 deletions cmake/Phylanx_AddPythonTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ macro(add_phylanx_python_test category name)
phylanx_debug("add_phylanx_python_test (${name})" "WORKING_DIRECTORY: ${_working_directory}")

set(_environment)
if(PHYLANX_WITH_PYTHON_TESTS_EMIT_FULL_DIAGNOSTICS)
set(_environment
PHYLANX_PYTHON_CONFIG="--hpx:ini=phylanx.full_error_diagnostics!=1"
)
endif()
if(${name}_ENVIRONMENT)
if(MSVC)
set(_environment ${CMAKE_COMMAND} -E env "${${name}_ENVIRONMENT}")
set(_environment ${CMAKE_COMMAND} -E env ${_environment} ${${name}_ENVIRONMENT})
else()
set(_environment ENVIRONMENT "${${name}_ENVIRONMENT}")
set(_environment ENVIRONMENT ${_environment} ${${name}_ENVIRONMENT})
endif()
endif()
phylanx_debug("add_phylanx_python_test (${name})" "ENVIRONMENT: ${_environment}")
Expand Down
14 changes: 14 additions & 0 deletions python/phylanx/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from phylanx.core import init_hpx_runtime
from phylanx.exceptions import RuntimeAlreadyInitializedError

import os
import platform


class PhylanxSession:
cfg = [
Expand All @@ -30,6 +33,17 @@ def init(num_threads=1):
if not PhylanxSession.is_initialized:
hpx_thread = "hpx.os_threads!=%s" % num_threads
PhylanxSession.cfg[3] = hpx_thread

# append additional config settings taken from the environment
if 'PHYLANX_PYTHON_CONFIG' in os.environ:
if platform.system() == "Windows":
sep = ';'
else:
sep = ':'

for e in os.environ['PHYLANX_PYTHON_CONFIG'].split(sep):
PhylanxSession.cfg.append(e)

init_hpx_runtime(PhylanxSession.cfg)
PhylanxSession.is_initialized = True
else:
Expand Down
25 changes: 25 additions & 0 deletions python/src/bindings/execution_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <hpx/runtime/threads/run_as_hpx_thread.hpp>

#include <cstdint>
#include <exception>
#include <string>
#include <vector>
#include <utility>
Expand Down Expand Up @@ -307,4 +308,28 @@ void phylanx::bindings::bind_execution_tree(pybind11::module m)
});
},
"wait for future to become ready");

// translate HPX exceptions and provide more error information, if desired
static pybind11::exception<hpx::exception> exc(
m, "HPXError", PyExc_RuntimeError);

pybind11::register_exception_translator([](std::exception_ptr p) {
try
{
if (p)
std::rethrow_exception(p);
}
catch (hpx::exception& e)
{
if (hpx::get_config_entry("phylanx.full_error_diagnostics", "0") ==
"1")
{
exc(hpx::diagnostic_information(e).c_str());
}
else
{
exc(e.what());
}
}
});
}

0 comments on commit e91cb62

Please sign in to comment.