-
Notifications
You must be signed in to change notification settings - Fork 8
BO / Prefect HiTL Slack integration tutorial #456
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
Open
Copilot
wants to merge
34
commits into
main
Choose a base branch
from
copilot/fix-382
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,903
−0
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
1e60493
Initial plan
Copilot ad0c718
Revise copilot instructions for clarity and detail
sgbaird e5222e7
Create BO/Prefect HiTL Slack integration tutorial with Ax Service API
Copilot 83fd619
Update GitHub Actions workflow for Copilot setup
sgbaird 233f2b3
Update dependency installation for specific branch
sgbaird 027376e
Update GitHub Actions workflow for branch handling
sgbaird d77fa4a
Update dependencies in copilot-setup-steps.yml
sgbaird 849630c
Remove duplicate package installation command
sgbaird c0626fd
Fix formatting in copilot-setup-steps.yml
sgbaird 95c2449
Remove all mocking, simplify code, reduce verbose logging as requested
Copilot 780062b
Add robust error handling, parameterization, and input validation
Copilot bcaeeba
Improve input validation and failed trial handling as requested
Copilot 11d898e
precect + ax workflow with HiTL slack
Daniel0813 98b6cad
Update README_BO_HITL_Tutorial.md with comprehensive documentation
Daniel0813 d57a293
Add Bayesian Optimization HITL deployment script with GitRepository b…
Daniel0813 4b88b9a
feat: Add containerized BO HITL workflow with Docker
Daniel0813 a39f6d0
Fix deployment entrypoint to use correct bo_hitl_slack_tutorial.py path
Daniel0813 86d0947
Convert Slack integration from Prefect blocks to environment variables
Daniel0813 af7cccb
Fix Slack message URL to use external accessible Prefect UI address
Daniel0813 c23d856
Fix Prefect UI URL format for flow runs
Daniel0813 00e6ae7
Fix Docker Prefect UI URL configuration for flow resumption
Daniel0813 3bc4c82
Update requirements.txt files with SQLAlchemy 2.x and prefect-slack d…
Daniel0813 f4b3ddd
Implement secure Slack notifications using Prefect Variables
Daniel0813 9010aaa
Fix variable name to use lowercase with dashes
Daniel0813 a8b384d
Fix Slack URL to use localhost instead of Docker IP
Daniel0813 0971c0a
Clean up unnecessary directories and add Docker containerization setup
Daniel0813 7d5e8d8
Enhance BO HITL deployment script with Unicode fixes and dependency i…
Daniel0813 072d8a0
Merge branch 'main' into copilot/fix-382
sgbaird a9d0ef0
Fix Slack webhook integration in BO HITL deployment script
Daniel0813 5eef28a
Clean up repository: remove duplicate directories
Daniel0813 4997797
Reorganize prefect scripts: move samples to dedicated folder
Daniel0813 b5b5e8f
Add MongoDB database integration module for BO experiments
Daniel0813 15a6b62
Implement comprehensive JSON storage system for BO campaigns
Daniel0813 12c89c4
Add dual storage system (JSON + MongoDB) to BO HITL tutorial
Daniel0813 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 hidden or 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 | ||
|---|---|---|---|---|
| @@ -1,3 +1,23 @@ | ||||
| # Changelog | ||||
|
|
||||
| All notable changes to this project will be documented in this file. | ||||
|
|
||||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||||
|
|
||||
| ## [Unreleased] | ||||
|
|
||||
| ### Added | ||||
| - BO / Prefect HiTL Slack integration tutorial (2025-01-18) | ||||
| - Created `scripts/prefect_scripts/bo_hitl_slack_tutorial.py` - Complete Bayesian Optimization workflow with human-in-the-loop evaluation via Slack | ||||
| - Added `scripts/prefect_scripts/test_bo_workflow.py` - Demonstration script showing BO workflow without dependencies | ||||
| - Added `scripts/prefect_scripts/README_BO_HITL_Tutorial.md` - Setup instructions and documentation | ||||
| - Implements Ax Service API for Bayesian optimization with Branin function | ||||
| - Integrates Prefect interactive workflows with pause_flow_run for human input | ||||
| - Provides Slack notifications for experiment suggestions | ||||
| - Supports evaluation via HuggingFace Branin space | ||||
| - Includes mock implementations for development without heavy dependencies | ||||
|
||||
| - Includes mock implementations for development without heavy dependencies |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| # Bayesian Optimization Human-in-the-Loop Slack Integration Tutorial | ||
|
|
||
| This tutorial demonstrates a complete Bayesian Optimization workflow with human evaluation via Slack and Prefect for evaluating the Branin function. | ||
|
|
||
| ## Overview | ||
|
|
||
| The minimal working example implements this exact workflow: | ||
|
|
||
| 1. **User runs Python script** starting BO campaign via Ax | ||
| 2. **Ax suggests parameters** → sends notification to Slack with parameter values | ||
| 3. **User evaluates Branin function** using HuggingFace space or API | ||
| 4. **User resumes Prefect flow** via Slack link and enters the objective value | ||
| 5. **Loop continues** for 5 iterations, finding optimal parameters | ||
| 6. **Final results** are posted to Slack with the best parameters found | ||
|
|
||
| ## Setup Instructions | ||
|
|
||
| ### 1. Install Dependencies | ||
|
|
||
| ```bash | ||
| # For Windows PowerShell | ||
| pip install ax-platform prefect prefect-slack gradio_client | ||
|
|
||
| # For Unix/Linux | ||
| # export PIP_TIMEOUT=600 | ||
| # export PIP_RETRIES=2 | ||
| # pip install ax-platform prefect prefect-slack gradio_client | ||
| ``` | ||
|
|
||
| ### 2. Register and Configure Slack Block | ||
|
|
||
| ```bash | ||
| # Register the Slack block | ||
| prefect block register -m prefect_slack | ||
|
|
||
| # Check available blocks | ||
| prefect block ls | ||
| ``` | ||
|
|
||
| You need to create a SlackWebhook block named "prefect-test" via the Prefect UI: | ||
|
|
||
| ```python | ||
| from prefect.blocks.notifications import SlackWebhook | ||
|
|
||
| # Create the webhook block | ||
| slack_webhook_block = SlackWebhook( | ||
| url="YOUR_SLACK_WEBHOOK_URL" # Get this from Slack Apps | ||
| ) | ||
|
|
||
| # Save it with the name expected by the tutorial | ||
| slack_webhook_block.save("prefect-test") | ||
| ``` | ||
|
|
||
| ### 3. Start Prefect Server | ||
|
|
||
| ```bash | ||
| prefect server start | ||
| ``` | ||
|
|
||
| To get a Slack webhook URL: | ||
| 1. Go to https://api.slack.com/apps | ||
| 2. Create a new app or select existing | ||
| 3. Enable "Incoming Webhooks" | ||
| 4. Create webhook for your channel | ||
| 5. Copy the webhook URL | ||
|
|
||
| ### 4. Run the Tutorial | ||
|
|
||
| ```bash | ||
| cd scripts/prefect_scripts | ||
| python bo_hitl_slack_tutorial.py | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| ### Optimization Problem | ||
|
|
||
| The tutorial optimizes the Branin function, a common benchmark in Bayesian Optimization: | ||
|
|
||
| - **Function**: Branin function (to be minimized) | ||
| - **Parameters**: | ||
| - x1 ∈ [-5.0, 10.0] | ||
| - x2 ∈ [0.0, 15.0] | ||
| - **Goal**: Find parameter values that minimize the function | ||
|
|
||
| ### Workflow Steps | ||
|
|
||
| 1. **Script starts** - Initializes Ax Service API client with proper parameter bounds | ||
| 2. **Ax suggests parameters** - Using Bayesian Optimization algorithms | ||
| 3. **Slack notification** - Sends parameter values and API instructions to Slack | ||
| 4. **Human evaluation** - User evaluates the function via: | ||
| - HuggingFace Space UI: https://huggingface.co/spaces/AccelerationConsortium/branin | ||
| - OR using the provided Python code snippet with gradio_client | ||
| 5. **Resume in Prefect** - User clicks the link in Slack message to open Prefect UI | ||
| 6. **Enter result** - User inputs the objective value from HuggingFace in Prefect UI | ||
| 7. **Optimization continues** - Ax uses the result to suggest better parameters | ||
| 8. **Repeat** - Process continues for 5 iterations | ||
| 9. **Final results** - Best parameters and value are displayed and sent to Slack | ||
|
|
||
| ## Expected Output | ||
|
|
||
| The tutorial will: | ||
| - Generate 5 experiment suggestions using Bayesian Optimization | ||
| - Send Slack messages with parameters and detailed API instructions | ||
| - Include a direct link in the Slack message to resume the Prefect flow | ||
| - Pause execution waiting for human input via the Prefect UI | ||
| - Resume when user provides objective values and optional notes | ||
| - Show optimization progress in the terminal logs | ||
| - Send a final summary to Slack with the best parameters found | ||
|
|
||
| ## Demo Video Recording | ||
|
|
||
| For the video demonstration, show: | ||
| 1. Running the Python script | ||
| 2. Receiving Slack notification | ||
| 3. Evaluating experiment on HuggingFace Branin space | ||
| 4. Clicking Slack link to Prefect UI | ||
| 5. Entering objective value and resuming | ||
| 6. Repeating loop 4-5 times | ||
|
|
||
| ## Files | ||
|
|
||
| - `bo_hitl_slack_tutorial.py` - Main tutorial script | ||
| - `README.md` - This setup guide | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - **Prefect server not running**: Start with `prefect server start` | ||
| - **Slack block missing**: Configure SlackWebhook block named "prefect-test" | ||
| - **Dependencies missing**: Install with `pip install ax-platform prefect prefect-slack gradio_client` | ||
| - **PREFECT_UI_URL not set**: Set with `prefect config set PREFECT_API_URL=http://127.0.0.1:4200/api` | ||
| - **HuggingFace API errors**: Ensure parameters are within bounds (x1: [-5.0, 10.0], x2: [0.0, 15.0]) | ||
|
|
||
| ## Technical Details | ||
|
|
||
| ### Ax Configuration | ||
|
|
||
| The script uses the Ax Service API to set up the optimization problem: | ||
|
|
||
| ```python | ||
| ax_client.create_experiment( | ||
| name="branin_bo_experiment", | ||
| parameters=[ | ||
| { | ||
| "name": "x1", | ||
| "type": "range", | ||
| "bounds": [-5.0, 10.0], | ||
| "value_type": "float", | ||
| }, | ||
| { | ||
| "name": "x2", | ||
| "type": "range", | ||
| "bounds": [0.0, 15.0], | ||
| "value_type": "float", | ||
| }, | ||
| ], | ||
| objectives={"branin": ObjectiveProperties(minimize=True)} | ||
| ) | ||
| ``` | ||
|
|
||
| ### Prefect-Slack Integration | ||
|
|
||
| The workflow uses the Prefect pause functionality combined with Slack notifications: | ||
| - Prefect pause_flow_run waits for user input | ||
| - Slack notification contains a link to resume the flow | ||
| - User input is captured using a custom ExperimentInput model | ||
|
|
||
| ## References | ||
|
|
||
| - [Ax Documentation](https://ax.dev/) | ||
| - [Prefect Interactive Workflows](https://docs.prefect.io/latest/guides/creating-interactive-workflows/) | ||
| - [HuggingFace Branin Space](https://huggingface.co/spaces/AccelerationConsortium/branin) | ||
| - [Prefect Slack Integration](https://docs.prefect.io/latest/integrations/notifications/) |
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.
The changelog references a file
test_bo_workflow.pyand mentions mock implementations, but these don't appear in the actual changes. The changelog should only document what is actually being added in this PR.