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

Confetti effect after training is done #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Training Results Dashboard</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<style>
.header {
display: flex;
Expand Down Expand Up @@ -383,10 +384,68 @@ <h1 class="app-title">Federated Training Results</h1>
}
}

// Function to trigger confetti animation
function triggerConfetti() {
// First burst with text
var duration = 3 * 1000;
var end = Date.now() + duration;

// Create text element
const text = document.createElement('div');
text.textContent = 'Congratulations, you have completed Federated Learning on SyftBox 🎉🎉🎉';
text.style.position = 'fixed';
text.style.top = '40%';
text.style.left = '50%';
text.style.transform = 'translate(-50%, -50%)';
text.style.fontSize = '3em';
text.style.fontWeight = 'bold';
text.style.color = '#dc2626';
text.style.opacity = '0';
text.style.transition = 'opacity 1s';
document.body.appendChild(text);

// Fade in text
setTimeout(() => {
text.style.opacity = '1';
}, 100);

// Multiple confetti bursts
(function frame() {
confetti({
particleCount: 20,
angle: 60,
spread: 55,
origin: { x: 0, y: 0.6 }
});
confetti({
particleCount: 20,
angle: 120,
spread: 55,
origin: { x: 1, y: 0.6 }
});

if (Date.now() < end) {
requestAnimationFrame(frame);
}
}());
}

// Function to check if the main.py script has finished running
async function checkIfDone() {
// Check done.json file
const doneData = await loadJSON('done.json');
if (doneData) {
console.log('Training completed:', doneData);
// Trigger confetti
triggerConfetti();
}
}

// Initialize the dashboard and start polling
async function initDashboard() {
await checkForUpdates();
setInterval(checkForUpdates, POLLING_INTERVAL);
setInterval(checkIfDone, POLLING_INTERVAL);
}

// Start the application
Expand Down
17 changes: 17 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import importlib.util
from syftbox.lib import Client
from syftbox.lib import SyftPermission
Expand Down Expand Up @@ -493,6 +494,19 @@ def save_model_accuracy_metrics(
json.dump(metrics, f)


def create_done_file(client: Client, proj_folder: Path) -> None:
"""
Create a done.json file to indicate that the script has finished running
"""
metrics_folder = client.my_datasite / "public" / "fl" / proj_folder.name
done_file = metrics_folder / "done.json"
done_data = {
"done_time": datetime.now().isoformat()
}
with open(done_file, "w") as f:
json.dump(done_data, f)


def advance_fl_round(client: Client, proj_folder: Path):
"""
1. Wait for the trained model from the clients
Expand All @@ -510,6 +524,7 @@ def advance_fl_round(client: Client, proj_folder: Path):
if current_round >= total_rounds + 1:
print(f"FL project {proj_folder.name} is complete ✅")
shift_project_to_done_folder(client, proj_folder, total_rounds)
create_done_file(client, proj_folder)
return

participants = fl_config["participants"]
Expand Down Expand Up @@ -598,6 +613,8 @@ def _advance_fl_project(client: Client, proj_folder: Path) -> None:
5. wait for the trained model from the clients
6. aggregate the trained model
7. repeat d until all the rounds are complete
8. move weights to done folder and create a done.json file to indicate that
the script has finished running
"""

try:
Expand Down
2 changes: 1 addition & 1 deletion samples/launch_config/fl_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"test_dataset": "mnist_test_dataset.pt",
"rounds": 3,
"epoch": 10,
"learning_rate": 0.1
"learning_rate": 0.01
}