Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding locality parameter to python execution interface #1151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 8 additions & 2 deletions cmake/Phylanx_AddPythonTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ 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)
set(_environment ${${name}_ENVIRONMENT} ${_environment})
if(MSVC)
set(_environment ${CMAKE_COMMAND} -E env "${${name}_ENVIRONMENT}")
set(_environment ${CMAKE_COMMAND} -E env ${_environment})
else()
set(_environment ENVIRONMENT "${${name}_ENVIRONMENT}")
set(_environment ENVIRONMENT ${_environment})
endif()
endif()
phylanx_debug("add_phylanx_python_test (${name})" "ENVIRONMENT: ${_environment}")
Expand Down
90 changes: 90 additions & 0 deletions phylanx/execution_tree/compiler/actors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,49 @@ namespace phylanx { namespace execution_tree { namespace compiler
return extract_copy_value(arg_, name_);
}

// evaluate object itself and use the returned value to
// asynchronously evaluate the arguments
hpx::shared_future<result_type> async(
arguments_type const& args, eval_context ctx) const
{
if (is_primitive_operand(arg_))
{
arguments_type params;
params.reserve(args.size());
for (auto const& arg : args)
{
params.emplace_back(extract_ref_value(arg, name_));
}

return value_operand(arg_, std::move(params), name_).share();
}
return hpx::make_ready_future(extract_copy_value(arg_, name_))
.share();
}

hpx::shared_future<result_type> async(
arguments_type&& args, eval_context ctx) const
{
if (is_primitive_operand(arg_))
{
arguments_type keep_alive(std::move(args));

// construct argument-pack to use for actual call
arguments_type params;
params.reserve(keep_alive.size());
for (auto const& arg : keep_alive)
{
params.emplace_back(extract_ref_value(arg, name_));
}

return value_operand(
arg_, std::move(params), name_, "<unknown>", std::move(ctx))
.share();
}
return hpx::make_ready_future(extract_copy_value(arg_, name_))
.share();
}

using kwarguments_type = std::map<std::string, primitive_argument_type>;

result_type operator()(arguments_type&& args, kwarguments_type&& kwargs,
Expand Down Expand Up @@ -222,6 +265,53 @@ namespace phylanx { namespace execution_tree { namespace compiler
return extract_copy_value(arg_, name_);
}

hpx::shared_future<result_type> async(arguments_type&& args,
kwarguments_type&& kwargs, eval_context ctx) const
{
if (is_primitive_operand(arg_))
{
arguments_type keep_alive(std::move(args));
kwarguments_type kw_keep_alive(std::move(kwargs));

// construct argument-pack to use for actual call
arguments_type params;
params.reserve(keep_alive.size() + num_named_args_);
for (auto const& arg : keep_alive)
{
params.emplace_back(extract_ref_value(arg, name_));
}

// fill in the given named arguments at their correct positions
for (auto const& kwarg : kw_keep_alive)
{
auto it = std::find(named_args_.get(),
named_args_.get() + num_named_args_, kwarg.first);
if (it == named_args_.get() + num_named_args_)
{
HPX_THROW_EXCEPTION(hpx::bad_parameter,
"function::operator()",
hpx::util::format("cannot locate requested "
"named argument '{}'", kwarg.first));
}

std::ptrdiff_t kwarg_pos =
std::distance(named_args_.get(), it);
if (kwarg_pos >= std::ptrdiff_t(params.size()))
{
params.resize(kwarg_pos + 1);
}

params[kwarg_pos] = extract_ref_value(kwarg.second, name_);
}

return value_operand(
arg_, std::move(params), name_, "<unknown>", std::move(ctx))
.share();
}
return hpx::make_ready_future(extract_copy_value(arg_, name_))
.share();
}

template <typename T1, typename ... Ts>
typename std::enable_if<
!std::is_same<eval_context, typename std::decay<T1>::type>::value,
Expand Down
1 change: 1 addition & 0 deletions phylanx/plugins/controls/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <phylanx/plugins/controls/parallel_block_operation.hpp>
#include <phylanx/plugins/controls/parallel_map_operation.hpp>
#include <phylanx/plugins/controls/range_operation.hpp>
#include <phylanx/plugins/controls/sleep_operation.hpp>
#include <phylanx/plugins/controls/while_operation.hpp>

#endif
Expand Down
46 changes: 46 additions & 0 deletions phylanx/plugins/controls/sleep_operation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2020 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(PHYLANX_SLEEP_OPERATION_APR_24_2020_0840AM)
#define PHYLANX_SLEEP_OPERATION_APR_24_2020_0840AM

#include <phylanx/config.hpp>
#include <phylanx/execution_tree/primitives/base_primitive.hpp>
#include <phylanx/execution_tree/primitives/primitive_component_base.hpp>

#include <hpx/lcos/future.hpp>

#include <string>
#include <utility>

namespace phylanx { namespace execution_tree { namespace primitives {

class sleep_operation : public primitive_component_base
{
public:
static match_pattern_type const match_data;

sleep_operation() = default;

sleep_operation(primitive_arguments_type&& operands,
std::string const& name, std::string const& codename);

protected:
hpx::future<primitive_argument_type> eval(
primitive_arguments_type const& operands,
primitive_arguments_type const& args,
eval_context ctx) const override;
};

inline primitive create_sleep_operation(hpx::id_type const& locality,
primitive_arguments_type&& operands, std::string const& name = "",
std::string const& codename = "")
{
return create_primitive_component(
locality, "sleep", std::move(operands), name, codename);
}
}}} // namespace phylanx::execution_tree::primitives

#endif
Loading