Skip to content

Add Spark example using ask-and-tell interface - #328

Merged
nabenabe0928 merged 5 commits into
optuna:mainfrom
dhyeyinf:main
Aug 1, 2025
Merged

nabenabe0928 merged 5 commits into
optuna:mainfrom
dhyeyinf:main

Conversation

@dhyeyinf

Copy link
Copy Markdown
Contributor

Overview

This PR adds an example that demonstrates how to use Optuna's ask-and-tell interface with Apache Spark to distribute trial evaluations in parallel using PySpark's RDD API.

The script defines a simple quadratic objective function and evaluates it across Spark worker nodes. It shows how ask-and-tell can be used with a distributed engine without requiring integration with external orchestrators.

Motivation

The example is inspired by multiple user questions regarding Spark integration, as discussed in optuna/optuna#6077. While the functionality already exists via ask() and tell(), this example provides a hands-on script for users working with Spark.

Notes

  • This script is placed in the spark/ directory.
  • Includes fallback if PySpark is not installed.
  • Lightly formatted and runnable standalone (not Sphinx-bound).

Please let me know if you'd like the example adjusted further.

@dhyeyinf

Copy link
Copy Markdown
Contributor Author

Summary

  • ✅ Fixed isort import ordering in spark/ask_and_tell_spark.py
  • 📦 Added requirements.txt for the Spark ask-and-tell example

This ensures the example follows code style guidelines and includes required dependencies (optuna, pyspark) for easier execution.

Let me know if anything else should be added or refined!

@nabenabe0928 nabenabe0928 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I cannot make your code work.
Could you please modify your code so that your code works without any modifications?
For example, an obvious bug is optuna.seed, which does not exist.

@dhyeyinf

Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out! I've removed the invalid optuna.seed() line. The script now runs as-is with no modifications. Let me know if there’s anything else to adjust.

@dhyeyinf

dhyeyinf commented Jul 3, 2025

Copy link
Copy Markdown
Contributor Author

Hi @nabenabe0928, just following up on this PR — I made the changes you suggested a few days ago (removed the invalid optuna.seed() and ensured the script runs without any modifications). Please let me know if there's anything else you'd like me to address.

Appreciate your time and feedback! 🙇‍♂️

@github-actions

Copy link
Copy Markdown

This pull request has not seen any recent activity.

@github-actions github-actions Bot added the stale Exempt from stale bot labeling. label Jul 10, 2025
Comment thread spark/ask_and_tell_spark.py Resolved
Comment thread spark/ask_and_tell_spark.py Resolved
dhyeyinf and others added 2 commits July 14, 2025 11:31
@dhyeyinf

Copy link
Copy Markdown
Contributor Author

Thank you! I've applied your suggested changes

@nabenabe0928 nabenabe0928 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I missed one thing, could you please reduce the indents?
Please see my comment for more details.

Comment thread spark/ask_and_tell_spark.py Resolved
@dhyeyinf

Copy link
Copy Markdown
Contributor Author

Thank you for catching that! I've committed the suggested indentation fix.

@github-actions github-actions Bot removed the stale Exempt from stale bot labeling. label Jul 14, 2025
@github-actions

Copy link
Copy Markdown

This pull request has not seen any recent activity.

@github-actions github-actions Bot added the stale Exempt from stale bot labeling. label Jul 21, 2025
@dhyeyinf

Copy link
Copy Markdown
Contributor Author

Thank you for catching that! I've committed the suggested indentation fix.

@github-actions github-actions Bot removed the stale Exempt from stale bot labeling. label Jul 22, 2025
@github-actions

Copy link
Copy Markdown

This pull request has not seen any recent activity.

@github-actions github-actions Bot added the stale Exempt from stale bot labeling. label Jul 29, 2025

@nabenabe0928 nabenabe0928 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the late response, LGTM!

@nabenabe0928 nabenabe0928 added this to the v4.5.0 milestone Aug 1, 2025
@nabenabe0928
nabenabe0928 merged commit a2b06a4 into optuna:main Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Exempt from stale bot labeling.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants