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

feat: Add example showing how to join tasks together. #52

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kirkrodrigues
Copy link
Member

@kirkrodrigues kirkrodrigues commented Jan 14, 2025

Description

This PR adds an example and docs for how to join tasks together.

Validation performed

TODO. Pending resolution of #50.

Summary by CodeRabbit

Release Notes

  • Documentation

    • Added comprehensive guide on joining tasks in Spider framework
    • Updated quick-start documentation with reference to new joining tasks guide
  • Examples

    • Introduced new example project demonstrating task integration techniques
    • Implemented mathematical tasks for illustrating task binding and execution
    • Added client application showcasing task graph creation and validation
  • Development

    • Configured clang-format for consistent code formatting
    • Created CMake build configuration for new example project

These updates provide developers with detailed insights into advanced task management in the Spider framework, focusing on task binding and nested task execution.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request introduces comprehensive documentation and an example implementation for task joining in the Spider framework. The changes include a new markdown document explaining task integration methods, updates to the quick-start guide, and a complete example project demonstrating how to bind and start tasks. The implementation showcases two primary approaches: binding task outputs and initiating tasks within other tasks, with a focus on creating directed acyclic graphs (DAGs) of computational tasks.

Changes

File Change Summary
docs/joining-tasks.md New documentation detailing task joining methods, spider::Driver::bind, and spider::Driver::start
docs/quick-start.md Updated "Next steps" section with a specific reference to the new joining tasks guide
examples/joining-tasks/.clang-format New clang-format configuration for include file ordering
examples/joining-tasks/CMakeLists.txt Added project configuration with tasks library and client executable
examples/joining-tasks/src/client.cpp Implemented client application for demonstrating task joining with job validation
examples/joining-tasks/src/tasks.cpp Defined mathematical tasks (square, square_root, sum) registered with Spider framework
examples/joining-tasks/src/tasks.hpp Header declarations for mathematical task functions

Sequence Diagram

sequenceDiagram
    participant Client
    participant Driver
    participant TaskGraph
    participant Tasks

    Client->>Driver: Create driver
    Client->>Driver: Bind tasks
    Driver->>TaskGraph: Configure task dependencies
    Client->>Driver: Start job
    Driver->>Tasks: Execute tasks
    Tasks-->>Driver: Return results
    Driver-->>Client: Job completion
Loading

Possibly related PRs

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (7)
examples/joining-tasks/src/tasks.cpp (1)

7-17: Mark unused TaskContext parameter.

Consider marking the unused TaskContext parameter with [[maybe_unused]] attribute to suppress compiler warnings.

-auto square(spider::TaskContext&, int value) -> int {
+auto square(spider::TaskContext& [[maybe_unused]] context, int value) -> int {

-auto square_root(spider::TaskContext&, int value) -> double {
+auto square_root(spider::TaskContext& [[maybe_unused]] context, int value) -> double {

-auto sum(spider::TaskContext&, int x, int y) -> int {
+auto sum(spider::TaskContext& [[maybe_unused]] context, int x, int y) -> int {
examples/joining-tasks/src/tasks.hpp (1)

6-26: Enhance function documentation.

The documentation comments should include descriptions for all parameters and more detailed return value descriptions.

 /**
  * @param context Task execution context for Spider framework
  * @param value The input value to square
- * @return The square of the given value.
+ * @return The square of the given value (value * value).
  */
 auto square(spider::TaskContext& context, int value) -> int;

 /**
  * @param context Task execution context for Spider framework
  * @param value The input value to calculate square root of
- * @return The square root of the given value.
+ * @return The square root of the given value. Throws std::invalid_argument if value is negative.
  */
 auto square_root(spider::TaskContext& context, int value) -> double;

 /**
  * @param context Task execution context for Spider framework
  * @param x First number to add
  * @param y Second number to add
- * @return The sum of x and y.
+ * @return The sum of the two input values (x + y).
  */
examples/joining-tasks/src/client.cpp (3)

19-19: Improve const correctness of validate_job_output function.

The job parameter should be const since the function only reads from it.

-auto validate_job_output(spider::Job<JobOutputType>& job, JobOutputType const& expected) -> bool {
+auto validate_job_output(spider::Job<JobOutputType> const& job, JobOutputType const& expected) -> bool {

53-56: Enhance storage URL validation.

The current validation only checks if the URL is empty. Consider adding more thorough URL validation.

     if (storage_url.empty()) {
         std::cerr << "storage-backend-url cannot be empty." << '\n';
         return 1;
     }
+    if (storage_url.find("://") == std::string::npos) {
+        std::cerr << "Invalid storage-backend-url format. Expected: <scheme>://<path>" << '\n';
+        return 1;
+    }

65-67: Consider using named constants for test values.

The values 4 and 5 are magic numbers. Consider using named constants to improve code readability.

+    // Using a 3-4-5 right triangle for testing
+    int const TRIANGLE_SIDE_A = 4;
+    int const TRIANGLE_SIDE_B = 5;
-    int const a = 4;
-    int const b = 5;
-    auto job = driver.start(hypotenuse_task_graph, a, b);
+    auto job = driver.start(hypotenuse_task_graph, TRIANGLE_SIDE_A, TRIANGLE_SIDE_B);
docs/joining-tasks.md (2)

49-50: Fix grammar in parameter description.

Change "is a either a" to "is either a" to correct the grammar.

-- Each subsequent parameter is a either a *source* runnable, or a value that conforms to the
+- Each subsequent parameter is either a *source* runnable, or a value that conforms to the
🧰 Tools
🪛 LanguageTool

[misspelling] ~49-~49: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...nables*. - Each subsequent parameter is a either a source runnable, or a value ...

(EN_A_VS_AN)


73-76: Fix blockquote formatting.

Remove the empty blockquote lines to comply with markdown formatting standards.

 > Unlike `std::bind`, `spider::Driver::bind` doesn't support placeholder inputs.
-
->
->
🧰 Tools
🪛 Markdownlint (0.37.0)

73-73: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7f7c48 and e587188.

📒 Files selected for processing (7)
  • docs/joining-tasks.md (1 hunks)
  • docs/quick-start.md (1 hunks)
  • examples/joining-tasks/.clang-format (1 hunks)
  • examples/joining-tasks/CMakeLists.txt (1 hunks)
  • examples/joining-tasks/src/client.cpp (1 hunks)
  • examples/joining-tasks/src/tasks.cpp (1 hunks)
  • examples/joining-tasks/src/tasks.hpp (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • examples/joining-tasks/.clang-format
  • docs/quick-start.md
  • examples/joining-tasks/CMakeLists.txt
🧰 Additional context used
🪛 LanguageTool
docs/joining-tasks.md

[misspelling] ~49-~49: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...nables*. - Each subsequent parameter is a either a source runnable, or a value ...

(EN_A_VS_AN)

🪛 Markdownlint (0.37.0)
docs/joining-tasks.md

73-73: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
🔇 Additional comments (1)
examples/joining-tasks/src/tasks.cpp (1)

19-25: LGTM! Task registration is properly implemented.

The NOLINT directives are appropriately used to suppress warnings about global constructors in task registration.

Comment on lines +11 to +13
auto square_root(spider::TaskContext&, int value) -> double {
return std::sqrt(value);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation for square_root function.

The square_root function should validate that the input value is non-negative to prevent undefined behaviour.

 auto square_root(spider::TaskContext&, int value) -> double {
+    if (value < 0) {
+        throw std::invalid_argument("Cannot calculate square root of negative number");
+    }
     return std::sqrt(value);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
auto square_root(spider::TaskContext&, int value) -> double {
return std::sqrt(value);
}
auto square_root(spider::TaskContext&, int value) -> double {
if (value < 0) {
throw std::invalid_argument("Cannot calculate square root of negative number");
}
return std::sqrt(value);
}

@kirkrodrigues kirkrodrigues changed the title feat: Add example showing how to join tasks together. feat: Add example showing how to join tasks together. Jan 14, 2025
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.

1 participant