facebook / Ax

Adaptive Experimentation Platform
https://ax.dev
MIT License
2.31k stars 294 forks source link

Idea for interactive template generation: multi-objective, multi-fidelity, batch optimization, etc. #1479

Open sgbaird opened 1 year ago

sgbaird commented 1 year ago

There's an idea I'm playing around with and thinking about implementing to make some of the advanced BO topics more accessible, especially in chemistry and materials science.

With the escience notebook tutorials that I put out (see @sp8rks's YouTube playlist), I started expanding them with progressively complicated names as I was incorporating different features:

A lot of these were based on content from other issues, often using the Service API, and occasionally delving into Developer API or BoTorch components. As I was creating these extra tutorials with a labmate in mind (@ramseyissa), it struck me how modular the functionality was (👏) as well as the sheer number of notebooks that would be required to cover every combination of these.

My idea is to create something somewhat similar to the interactive API snippets:

except allowing for an interactive selection of the desired features.

For example, a user could choose from the following options to create the corresponding template for 2.8.0.4-ax_service_existing_data_saasbo_multi_objective_batch_equality.ipynb:

Other categories:

And maybe in terms of the user experience, it would look and act like the PyTorch installation page:

https://user-images.githubusercontent.com/45469701/222261641-39e94351-d7c9-41d8-85f0-320daaa879b0.mp4

In terms of actually implementing the above, I wonder if ipywidgets might come in handy. I'm not very well versed in HTML and Javascript. I'm also having trouble finding the general language to describe this type of interface. An alternative would be a Google Colab notebook that someone can run based on the options they select (which is probably where I would start).

For PyTorch's graphical implementation, see What is the PyTorch installation interactive grid called and how do I make my own?.

The template snippets at the bottom could be generated in advance for all combinations, rather than trying to run something on-the-fly. Additionally, it would be possible to run unit tests for each of the snippet combinations (this could simply be ensuring that it runs without errors).

I wanted to make a post to get some feedback and also have a place where I can refer back to it. What are your thoughts?

EDIT: also gauging interest via Twitter and LinkedIn

CharlyEmpereurmot commented 1 year ago

As a chemist / material scientist discovering Ax just right now and looking into how to have batches for single-objective optimization with ALEBO, I am seduced.

mpolson64 commented 1 year ago

This is a neat idea! We are always looking for ways to improve our documentation and tutorials to make learning Ax easier. We already have some plans for improving docs in the pipeline, and I will raise this concept to the team as well. As always, thanks for your dedication to improving Ax for all our users :)

sgbaird commented 1 year ago

I'm fleshing this idea out more. I'm planning to:

sgbaird commented 1 year ago

I created a repo called Honegumi (骨組み, pronounced "ho neh goo mee") which means skeletal framework in Japanese. I wrote "a gentle introduction to Jinja" Colab tutorial that will make it easier for others to contribute via general feedback, design principles, and features.

Just as a very basic example, the following Jinja template has a toggle for switching between single- and multi-objective, going from the objective_name and minimize kwargs to the objectives kwarg with ObjectiveProperties

from ax.service.ax_client import AxClient
from ax.utils.measurement.synthetic_functions import branin
{% if use_moo %}
from ax.service.utils.instantiation import ObjectiveProperties

obj1_name = "branin"
obj2_name = "neg_branin"

def branin_moo(x1, x2):
    """Multi-objective branin function

    The first objective is the normal branin value and the second
    objective is the negative branin value.
    """
    return {obj1_name: branin(x1, x2), obj2_name: -branin(x1, x2)}
{% endif %}

ax_client = AxClient()
ax_client.create_experiment(
    parameters=[
        {"name": "x1", "type": "range", "bounds": [-5.0, 10.0]},
        {"name": "x2", "type": "range", "bounds": [0.0, 10.0]},
    ],
{% if use_moo %}
    objectives={
        obj1_name: ObjectiveProperties(minimize=True, threshold=None),
        obj2_name: ObjectiveProperties(minimize=True, threshold=None),
    },
{% else %}
    objective_name="branin",
    minimize=True,
{% endif %}
)

for _ in range(15):
    parameters, trial_index = ax_client.get_next_trial()
    results = branin{% if use_moo %}_moo{% endif %}(
        parameters["x1"], parameters["x2"]
        )
    ax_client.complete_trial(trial_index=trial_index, raw_data=results)

{% if use_moo %}
pareto_results = ax_client.get_pareto_optimal_parameters()
{% else %}
best_parameters, metrics = ax_client.get_best_parameters()
{% endif %}

Hoping to define some good design principles and a roadmap. Lmk if you're interested in helping!

lena-kashtelyan commented 11 months ago

@sgbaird, this is awesome, sorry we left this unanswered for a while! Any help you currently need?

sgbaird commented 11 months ago

@lena-kashtelyan, thanks! No worries. Actually, I almost have a full working prototype with just a few options. I'll share that really soon! I'd love to get some help with it.

sgbaird commented 11 months ago

Hi @lena-kashtelyan, what do you think of this kind of functionality in terms of the high-level interface? (nothing specific to Ax in this one - still need to connect the interface to the backend)

https://github.com/sgbaird/honegumi/blob/ax/docs/bootstrap_examples/bootstrap_gpt_help/main.html

(download and open in a browser)

Screencast: https://app.screencast.com/ywGS5w2FsLygO

lena-kashtelyan commented 11 months ago

This is very cool! Where are you thinking of hosting this, @sgbaird? Is the thought to put these on the Ax website or somewhere else?

sgbaird commented 11 months ago

@lena-kashtelyan, I've been wondering about that. For now, I plan to have a small Readthedocs page based on https://github.com/sgbaird/honegumi. While I'm focusing on Ax implementations, I also wanted to set it up so that solutions for other platforms could be added.

sgbaird commented 11 months ago

Hi @lena-kashtelyan, I'm actively thinking about that and open to feedback. While I'm prototyping, I plan to expose it via a readthedocs generated from https://github.com/sgbaird/honegumi. I'm designing the tool in a way that can be extended to other platforms; however, the Ax functionality has its own namespace and therefore can be installed independently from other platforms. Right now, my focus is on Ax.

I have almost all of the functionality ready:

The last major piece of plumbing I need is programmatically running pytest and gathering the results within Python to pass it to the HTML file.

lena-kashtelyan commented 11 months ago

Wow, very cool! @mpolson64 and @esantorella are thinking through a potential redesign of our website infra/deployment, and this seems like it could be an excellent fit to play into that project. I'll assign this issue to @mpolson64 to think that through : )

sgbaird commented 10 months ago

Hi @lena-kashtelyan, @mpolson64, and @esantorella, I have a working example on the index page of https://honegumi.readthedocs.io/. I'm keen to get your thoughts! See the short screencast below:

https://github.com/facebook/Ax/assets/45469701/fa362011-5a74-4279-9a40-995cf39acec7

cc @Balandat @saitcakmak @bernardbeckerman @Ryan-Rhys

lena-kashtelyan commented 10 months ago

Wow this is so cool!! cc @mpolson64 who is thinking through our potential website reset –– would be great to feature this!

sgbaird commented 9 months ago

Thank you! I felt really good getting to this working example. I would love some help on continuing to expand/develop this and make sure I don't make some early decisions that make it really hard to maintain/scale later on, add features that aren't as useful, etc.

sgbaird commented 1 month ago

Lots of progress made since then! https://honegumi.readthedocs.io/