Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e60493
Initial plan
Copilot Sep 18, 2025
ad0c718
Revise copilot instructions for clarity and detail
sgbaird Sep 18, 2025
e5222e7
Create BO/Prefect HiTL Slack integration tutorial with Ax Service API
Copilot Sep 18, 2025
83fd619
Update GitHub Actions workflow for Copilot setup
sgbaird Sep 18, 2025
233f2b3
Update dependency installation for specific branch
sgbaird Sep 18, 2025
027376e
Update GitHub Actions workflow for branch handling
sgbaird Sep 18, 2025
d77fa4a
Update dependencies in copilot-setup-steps.yml
sgbaird Sep 18, 2025
849630c
Remove duplicate package installation command
sgbaird Sep 18, 2025
c0626fd
Fix formatting in copilot-setup-steps.yml
sgbaird Sep 18, 2025
95c2449
Remove all mocking, simplify code, reduce verbose logging as requested
Copilot Sep 19, 2025
780062b
Add robust error handling, parameterization, and input validation
Copilot Sep 22, 2025
bcaeeba
Improve input validation and failed trial handling as requested
Copilot Sep 23, 2025
11d898e
precect + ax workflow with HiTL slack
Daniel0813 Oct 5, 2025
98b6cad
Update README_BO_HITL_Tutorial.md with comprehensive documentation
Daniel0813 Oct 5, 2025
d57a293
Add Bayesian Optimization HITL deployment script with GitRepository b…
Daniel0813 Oct 11, 2025
4b88b9a
feat: Add containerized BO HITL workflow with Docker
Daniel0813 Oct 17, 2025
a39f6d0
Fix deployment entrypoint to use correct bo_hitl_slack_tutorial.py path
Daniel0813 Oct 19, 2025
86d0947
Convert Slack integration from Prefect blocks to environment variables
Daniel0813 Oct 19, 2025
af7cccb
Fix Slack message URL to use external accessible Prefect UI address
Daniel0813 Oct 19, 2025
c23d856
Fix Prefect UI URL format for flow runs
Daniel0813 Oct 19, 2025
00e6ae7
Fix Docker Prefect UI URL configuration for flow resumption
Daniel0813 Oct 20, 2025
3bc4c82
Update requirements.txt files with SQLAlchemy 2.x and prefect-slack d…
Daniel0813 Oct 21, 2025
f4b3ddd
Implement secure Slack notifications using Prefect Variables
Daniel0813 Oct 21, 2025
9010aaa
Fix variable name to use lowercase with dashes
Daniel0813 Oct 21, 2025
a8b384d
Fix Slack URL to use localhost instead of Docker IP
Daniel0813 Oct 21, 2025
0971c0a
Clean up unnecessary directories and add Docker containerization setup
Daniel0813 Oct 21, 2025
7d5e8d8
Enhance BO HITL deployment script with Unicode fixes and dependency i…
Daniel0813 Oct 23, 2025
072d8a0
Merge branch 'main' into copilot/fix-382
sgbaird Nov 3, 2025
a9d0ef0
Fix Slack webhook integration in BO HITL deployment script
Daniel0813 Nov 7, 2025
5eef28a
Clean up repository: remove duplicate directories
Daniel0813 Nov 7, 2025
4997797
Reorganize prefect scripts: move samples to dedicated folder
Daniel0813 Nov 7, 2025
b5b5e8f
Add MongoDB database integration module for BO experiments
Daniel0813 Nov 9, 2025
15a6b62
Implement comprehensive JSON storage system for BO campaigns
Daniel0813 Nov 10, 2025
12c89c4
Add dual storage system (JSON + MongoDB) to BO HITL tutorial
Daniel0813 Nov 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
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
Comment on lines +13 to +19
Copy link

Copilot AI Sep 23, 2025

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.py and 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.

Suggested change
- 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
- 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

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Sep 23, 2025

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.py and 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.

Suggested change
- Includes mock implementations for development without heavy dependencies

Copilot uses AI. Check for mistakes.
- Follows minimal working example pattern with 4-5 optimization iterations
# CHANGELOG

## [Unreleased]
Expand Down
173 changes: 173 additions & 0 deletions scripts/prefect_scripts/README_BO_HITL_Tutorial.md
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/)
Loading
Loading