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

Add terminal-based steering interface via an extract #1345

Merged
merged 7 commits into from
Aug 3, 2024

Conversation

siramok
Copy link
Collaborator

@siramok siramok commented Jul 30, 2024

This PR adds a new extract which puts the user into a basic shell-like steering interface. The main benefit is to have a simpler, no-dependency alternative to the existing ascent-jupyter-bridge steering interface.

It can be accessed via:

  action: "add_extracts"
  extracts:
    e1:
      type: "steering"

The current implementation allows users to manually, at runtime:

  • Add, edit, or delete numeric/string parameters with which to run callbacks (via an internally managed conduit node).
  • List registered callbacks (via new APIs that expose the callback names).
  • Run callbacks by name.
  • See any resulting output from running a callback.

Still to-do:

  • Verify that all MPI usage is properly guarded by ASCENT_MPI_ENABLED.
  • Similarly, verify that things work properly without MPI.
  • Add tests.

Despite not being ready, the big picture implementation details are unlikely to change (where I've implemented it, how I've plumbed it through). Any feedback you may have for me is welcome.

@siramok siramok requested a review from cyrush July 30, 2024 18:42
@siramok siramok marked this pull request as draft July 30, 2024 18:42
Copy link
Member

@cyrush cyrush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look great!
a few minor suggestions related to using C++ refs for strings and vectors, as well as the recipe for grabbing the right MPI comm

descriptions["run"] = "Run an Ascent callback with 'run my_callback_name'.";

#ifdef ASCENT_MPI_ENABLED
MPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not be using COMM_WORLD, so let's grab the right communicator using:

MPI_Comm mpi_comm = MPI_Comm_f2c(flow::Workspace::default_mpi_comm());

std::map<std::string, std::function<void()>> commands;
std::map<std::string, std::string> descriptions;
conduit::Node params;
conduit::Node output;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We like to use m_ prefix for member vars


void empty_run();
void exit_shell();
void parse_input(std::string cmd, std::vector<std::string> args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void parse_input(std::string cmd, std::vector<std::string> args);
void parse_input(std::string &cmd, std::vector<std::string> &args);

void exit_shell();
void parse_input(std::string cmd, std::vector<std::string> args);
void list_callbacks();
void modify_params(std::vector<std::string> args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void modify_params(std::vector<std::string> args);
void modify_params(std::vector<std::string> &args);

void modify_params(std::vector<std::string> args);
void print_help();
void print_params();
void run_callback(std::vector<std::string> args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void run_callback(std::vector<std::string> args);
void run_callback(std::vector<std::string> &args);

}

#ifdef ASCENT_MPI_ENABLED
MPI_Bcast(&input_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grab comm from workspace

@@ -87,6 +87,14 @@ void ASCENT_API execute_callback(std::string callback_name,
//-----------------------------------------------------------------------------
bool ASCENT_API execute_callback(std::string callback_name);

//-----------------------------------------------------------------------------
std::vector<std::string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref copy out style will be slight more efficient:

void ASCENT_API get_void_callbacks(std::vector<std::string> &name);


//-----------------------------------------------------------------------------
std::vector<std::string>
ASCENT_API get_bool_callbacks();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref copy out style will be slight more efficient:

void ASCENT_API get_bool_callbacks(std::vector<std::string> &name);

@@ -87,6 +87,14 @@ void ASCENT_API execute_callback(std::string callback_name,
//-----------------------------------------------------------------------------
bool ASCENT_API execute_callback(std::string callback_name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool ASCENT_API execute_callback(std::string callback_name);
bool ASCENT_API execute_callback(const std::string &callback_name);

@@ -928,6 +928,28 @@ execute_callback(std::string callback_name)
return callback_function();
}

//-----------------------------------------------------------------------------
std::vector<std::string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy out still ref args are a bit more efficient (see below)

Copy link
Member

@cyrush cyrush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the tweaks!

@cyrush
Copy link
Member

cyrush commented Aug 2, 2024

Tests exercising steering look good - let me know when you feel its ready to merge.

@siramok
Copy link
Collaborator Author

siramok commented Aug 2, 2024

Sweet, thanks Cyrus. I just made another polishing pass. Added comments, fixed formatting, simplified logic where I could, and made some tweaks after testing it out for myself. I feel comfortable merging it in it's current state.

I'll go create a new branch to work on an example instrumentation which makes use of this.

@cyrush cyrush marked this pull request as ready for review August 2, 2024 21:10
@cyrush cyrush changed the title Draft: Add terminal-based steering interface via an extract Add terminal-based steering interface via an extract Aug 3, 2024
@cyrush cyrush merged commit 0eb44cd into Alpine-DAV:develop Aug 3, 2024
19 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants