Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yczhang-nv committed Oct 2, 2024
1 parent 85e048f commit e506b95
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <vector>

namespace morpheus {
/****** Component public implementations *******************/
/******************* MonitorController**********************/

/**
Expand All @@ -51,8 +50,7 @@ namespace morpheus {
* @file
*/

// A singleton that manages the lifetime of progress bars from any MonitorController<T> instances
// and customized streambuf
// A singleton that manages the lifetime of progress bars related to any MonitorController<T> instances
class ProgressBarContextManager
{
public:
Expand All @@ -70,7 +68,7 @@ class ProgressBarContextManager

// DynamicProgress should take ownership over progressbars: https://github.com/p-ranav/indicators/issues/134
// The fix to this issue is not yet released, so we need to:
// - Maintain the lifetime of the progress bar in MultiProgressBarContext while it is being used
// - Maintain the lifetime of the progress bar in m_progress_bars
// - Push the underlying progress bar object to the DynamicProgress container, since it accepts
// Indicator &bar rather than std::unique_ptr<Indicator> bar before the fix
return m_dynamic_progress_bars.push_back(*m_progress_bars.back());
Expand All @@ -90,12 +88,19 @@ class ProgressBarContextManager
};

/**
* @brief
* @brief A controller class that manages the display of progress bars that used by MonitorStage.
*/
template <typename MessageT>
class MonitorController
{
public:
/**
* @brief Construct a new Monitor Controller object
*
* @param description : A text label displayed on the left side of the progress bars
* @param unit : the unit of message count
* @param determine_count_fn : A function that computes the count for each incoming message
*/
MonitorController(const std::string& description,
std::string unit = "messages",
std::optional<std::function<size_t(MessageT)>> determine_count_fn = std::nullopt);
Expand Down
23 changes: 20 additions & 3 deletions python/morpheus/morpheus/_lib/include/morpheus/stages/monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include <string>

namespace morpheus {
/****** Component public implementations *******************/
/****** MonitorStage********************************/
/*************** Component public implementations ***************/
/******************** MonitorStage ********************/

/**
* @addtogroup controllers
Expand All @@ -39,7 +39,7 @@ namespace morpheus {
*/

/**
* @brief
* @brief Displays descriptive progress bars including throughput metrics for the messages passing through the pipeline.
*/
template <typename MessageT>
class MORPHEUS_EXPORT MonitorStage : public mrc::pymrc::PythonNode<std::shared_ptr<MessageT>, std::shared_ptr<MessageT>>
Expand All @@ -50,6 +50,13 @@ class MORPHEUS_EXPORT MonitorStage : public mrc::pymrc::PythonNode<std::shared_p
using typename base_t::source_type_t;
using typename base_t::subscribe_fn_t;

/**
* @brief Construct a new Monitor Stage object
*
* @param description : A text label displayed on the left side of the progress bars
* @param unit : the unit of message count
* @param determine_count_fn : A function that computes the count for each incoming message
*/
MonitorStage(const std::string& description,
const std::string& unit = "messages",
std::optional<std::function<int(sink_type_t)>> determine_count_fn = std::nullopt);
Expand Down Expand Up @@ -94,6 +101,16 @@ MonitorStage<MessageT>::subscribe_fn_t MonitorStage<MessageT>::build_operator()
template <typename MessageT>
struct MORPHEUS_EXPORT MonitorStageInterfaceProxy
{
/**
* @brief Create and initialize a MonitorStage, and return the result
*
* @param builder : Pipeline context object reference
* @param name : Name of a stage reference
* @param description : A text label displayed on the left side of the progress bars
* @param unit : the unit of message count
* @param determine_count_fn : A function that computes the count for each incoming message
* @return std::shared_ptr<mrc::segment::Object<MonitorStage<MessageT>>>
*/
static std::shared_ptr<mrc::segment::Object<MonitorStage<MessageT>>> init(
mrc::segment::Builder& builder,
const std::string& name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,3 @@ TEST_F(TestMonitorController, TestAutoCountFn)
// Test invalid message type
EXPECT_THROW(MonitorController<int>("invalid message type"), std::runtime_error);
}

TEST_F(TestMonitorController, TestProgressBar)
{
auto message_meta_mc = MonitorController<std::shared_ptr<MessageMeta>>("test_message_meta");
auto meta = MessageMeta::create_from_cpp(std::move(create_cudf_table_with_metadata(10, 2)));
auto message_meta_mc_2 = MonitorController<std::shared_ptr<MessageMeta>>("test_message_meta_2");
auto meta_2 = MessageMeta::create_from_cpp(std::move(create_cudf_table_with_metadata(10, 2)));
auto message_meta_mc_3 = MonitorController<std::shared_ptr<MessageMeta>>("test_message_meta_3");
auto meta_3 = MessageMeta::create_from_cpp(std::move(create_cudf_table_with_metadata(10, 2)));

auto control_message_mc = MonitorController<std::shared_ptr<ControlMessage>>("test_control_message");
auto control_message = std::make_shared<ControlMessage>();
auto cm_meta = MessageMeta::create_from_cpp(std::move(create_cudf_table_with_metadata(20, 3)));
control_message->payload(cm_meta);

for (int i = 0; i < 10; i++)
{
// std::cout << "log message" << std::endl;
message_meta_mc.progress_sink(meta);
// std::cout << "log message 2" << std::endl;
message_meta_mc_2.progress_sink(meta_2);
// std::cout << "log message 3" << std::endl;
message_meta_mc_3.progress_sink(meta_3);
control_message_mc.progress_sink(control_message);
std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::milliseconds(100));
}
}
9 changes: 0 additions & 9 deletions tests/test_monitor_stage_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@
from morpheus.stages.preprocess.deserialize_stage import DeserializeStage


def build_expected(df: pd.DataFrame, threshold: float, class_labels: typing.List[str]):
"""
Generate the expected output of an add class by filtering by a threshold and applying the class labels
"""
df = (df > threshold)
# Replace input columns with the class labels
return df.rename(columns=dict(zip(df.columns, class_labels)))


def sample_message_meta_generator(df_rows: int, df_cols: int, count: int) -> Generator[MessageMeta, None, None]:
data = {f'col_{i}': range(df_rows) for i in range(df_cols)}
df = cudf.DataFrame(data)
Expand Down

0 comments on commit e506b95

Please sign in to comment.