-
Notifications
You must be signed in to change notification settings - Fork 66
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
WIP: Shell commands and function callbacks #1175
Merged
cyrush
merged 22 commits into
Alpine-DAV:task/2023_08_siramok_command_integration
from
siramok:develop
Aug 22, 2023
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
486d7ce
Initial callback and shell command implementations
siramok a62462f
Merge branch 'Alpine-DAV:develop' into develop
siramok 43489d5
Initial work to combine commands and callbacks
siramok 75288a2
Move callback registration and execution into Command
siramok 1ef9834
Catch the case where neither action is defined
siramok c35d61c
Allow defining multiline shell commands and callbacks
siramok c816e88
Minor formatting tweaks
siramok 8629395
Initial implementation of triggers with callbacks
siramok 01f06b7
Merge branch 'Alpine-DAV:develop' into develop
siramok 9ccfa0f
Improved organization, more error catching
siramok 3d1dcf7
Make sure that triggers either have a condition or callback
siramok 1dc2aeb
Make void callbacks take conduit node parameters
siramok 1b005dd
Initial attempt at exposing callbacks through ascent-jupyter-bridge
siramok 30333d6
Merge branch 'Alpine-DAV:develop' into develop
siramok 0b3c769
Let void callbacks return arbitrary data via conduit nodes
siramok 95815b8
Merge branch 'Alpine-DAV:develop' into develop
siramok 422b89e
Merge branch 'Alpine-DAV:develop' into develop
siramok 713857b
Disallow anonymous callbacks, add some tests
siramok a286cab
Add tests for shell commands and callbacks
siramok 156ff58
Refactor callback API into the main API, adjusts tests to reflect the…
siramok e4f82b2
Minor cleanups that I missed
siramok 7043d5d
Fix minor bug with the trigger + callback test
siramok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,29 @@ struct PyAscent_MPI_Ascent | |
Ascent *ascent; // NoteIterator is light weight, we can deal with copies | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
// Helper that promotes ascent error to python error | ||
//---------------------------------------------------------------------------// | ||
static void | ||
PyAscent_MPI_Ascent_Error_To_PyErr(const conduit::Error &e) | ||
{ | ||
std::ostringstream oss; | ||
oss << "Ascent Error: " << e.message(); | ||
PyErr_SetString(PyExc_RuntimeError, | ||
oss.str().c_str()); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
// Helper that promotes ascent error to python error | ||
//---------------------------------------------------------------------------// | ||
static void | ||
PyAscent_MPI_Cpp_Error_To_PyErr(const char *msg) | ||
{ | ||
std::ostringstream oss; | ||
oss << "Ascent Error: " << msg; | ||
PyErr_SetString(PyExc_RuntimeError, | ||
oss.str().c_str()); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
static PyObject * | ||
|
@@ -465,6 +488,72 @@ PyAscent_MPI_about() | |
return (PyObject*)py_node_res; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
// ascent::execute_callback | ||
//---------------------------------------------------------------------------// | ||
static PyObject * | ||
PyAscent_MPI_execute_callback(PyObject *self, | ||
PyObject *args) | ||
{ | ||
char *callback_name; | ||
PyObject *py_params = NULL; | ||
PyObject *py_output = NULL; | ||
|
||
if (!PyArg_ParseTuple(args, | ||
"sOO", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can use |
||
&callback_name, | ||
&py_params, | ||
&py_output)) | ||
{ | ||
return NULL; | ||
} | ||
|
||
try | ||
{ | ||
if(py_params != NULL && py_output != NULL) | ||
{ | ||
if(!PyConduit_Node_Check(py_params)) | ||
{ | ||
PyErr_SetString(PyExc_TypeError, | ||
"Ascent::execute_callback 'params' argument must be a " | ||
"conduit::Node"); | ||
return NULL; | ||
} | ||
else if (!PyConduit_Node_Check(py_output)) | ||
{ | ||
PyErr_SetString(PyExc_TypeError, | ||
"Ascent::execute_callback 'output' argument must be a " | ||
"conduit::Node"); | ||
return NULL; | ||
} | ||
std::string callback_name_string = callback_name; | ||
Node *params = PyConduit_Node_Get_Node_Ptr(py_params); | ||
Node *output = PyConduit_Node_Get_Node_Ptr(py_output); | ||
ascent::execute_callback(callback_name, *params, *output); | ||
Py_RETURN_NONE; | ||
} | ||
} | ||
catch(conduit::Error e) | ||
{ | ||
PyAscent_MPI_Ascent_Error_To_PyErr(e); | ||
return NULL; | ||
} | ||
// also try to bottle other errors, to prevent python | ||
// from crashing due to uncaught exception | ||
catch(std::exception &e) | ||
{ | ||
PyAscent_MPI_Cpp_Error_To_PyErr(e.what()); | ||
return NULL; | ||
} | ||
catch(...) | ||
{ | ||
PyAscent_MPI_Cpp_Error_To_PyErr("unknown cpp exception thrown"); | ||
return NULL; | ||
} | ||
|
||
Py_RETURN_NONE; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
// Python Module Method Defs | ||
//---------------------------------------------------------------------------// | ||
|
@@ -476,6 +565,11 @@ static PyMethodDef ascent_mpi_python_funcs[] = | |
METH_NOARGS, | ||
NULL}, | ||
//-----------------------------------------------------------------------// | ||
{"execute_callback", | ||
(PyCFunction)PyAscent_MPI_execute_callback, | ||
METH_VARARGS, | ||
NULL}, | ||
//-----------------------------------------------------------------------// | ||
// end ascent methods table | ||
//-----------------------------------------------------------------------// | ||
{NULL, NULL, METH_VARARGS, NULL} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,7 +510,7 @@ static PyMethodDef PyAscent_Ascent_METHODS[] = { | |
METH_VARARGS | METH_KEYWORDS, | ||
"{todo}"}, | ||
//-----------------------------------------------------------------------// | ||
{"execute", | ||
{"execute", | ||
(PyCFunction)PyAscent_Ascent_execute, | ||
METH_VARARGS | METH_KEYWORDS, | ||
"{todo}"}, | ||
|
@@ -596,6 +596,72 @@ PyAscent_about() | |
return (PyObject*)py_node_res; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
// ascent::execute_callback | ||
//---------------------------------------------------------------------------// | ||
static PyObject * | ||
PyAscent_execute_callback(PyObject *self, | ||
PyObject *args) | ||
{ | ||
char *callback_name; | ||
PyObject *py_params = NULL; | ||
PyObject *py_output = NULL; | ||
|
||
if (!PyArg_ParseTuple(args, | ||
"sOO", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also |
||
&callback_name, | ||
&py_params, | ||
&py_output)) | ||
{ | ||
return NULL; | ||
} | ||
|
||
try | ||
{ | ||
if(py_params != NULL && py_output != NULL) | ||
{ | ||
if(!PyConduit_Node_Check(py_params)) | ||
{ | ||
PyErr_SetString(PyExc_TypeError, | ||
"Ascent::execute_callback 'params' argument must be a " | ||
"conduit::Node"); | ||
return NULL; | ||
} | ||
else if (!PyConduit_Node_Check(py_output)) | ||
{ | ||
PyErr_SetString(PyExc_TypeError, | ||
"Ascent::execute_callback 'output' argument must be a " | ||
"conduit::Node"); | ||
return NULL; | ||
} | ||
std::string callback_name_string = callback_name; | ||
Node *params = PyConduit_Node_Get_Node_Ptr(py_params); | ||
Node *output = PyConduit_Node_Get_Node_Ptr(py_output); | ||
ascent::execute_callback(callback_name, *params, *output); | ||
Py_RETURN_NONE; | ||
} | ||
} | ||
catch(conduit::Error e) | ||
{ | ||
PyAscent_Ascent_Error_To_PyErr(e); | ||
return NULL; | ||
} | ||
// also try to bottle other errors, to prevent python | ||
// from crashing due to uncaught exception | ||
catch(std::exception &e) | ||
{ | ||
PyAscent_Cpp_Error_To_PyErr(e.what()); | ||
return NULL; | ||
} | ||
catch(...) | ||
{ | ||
PyAscent_Cpp_Error_To_PyErr("unknown cpp exception thrown"); | ||
return NULL; | ||
} | ||
|
||
Py_RETURN_NONE; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
// Python Module Method Defs | ||
//---------------------------------------------------------------------------// | ||
|
@@ -607,6 +673,11 @@ static PyMethodDef ascent_python_funcs[] = | |
METH_NOARGS, | ||
NULL}, | ||
//-----------------------------------------------------------------------// | ||
{"execute_callback", | ||
(PyCFunction)PyAscent_execute_callback, | ||
METH_VARARGS, | ||
NULL}, | ||
//-----------------------------------------------------------------------// | ||
// end ascent methods table | ||
//-----------------------------------------------------------------------// | ||
{NULL, NULL, METH_VARARGS, NULL} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should define these in the cpp file, otherwise they could be multiple defined by users calling ascent.