Skip to content

Hiopbbpy v0.05 dev #724

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

Merged
merged 8 commits into from
Apr 17, 2025
Merged

Hiopbbpy v0.05 dev #724

merged 8 commits into from
Apr 17, 2025

Conversation

thartland
Copy link
Collaborator

This PR adds capabilities to hiopbbpy for batched Bayesian optimization.

@thartland thartland requested review from nychiang and cnpetra April 15, 2025 15:14
@thartland
Copy link
Collaborator Author

thartland commented Apr 15, 2025

I am including some plots here which constitutes the tests of the added capabilities. I modified the BODriverEX.py to one without constraints besides the bound constraints. I ran 10 BO iterations using with a batch size of 2 and using the various strategies. I repeated experiments 10 times and compare against mean behavior of EI with a batch size of 1. The error bars show the variance in the repeated experiments. The horizontal axis is the number of batches, so there are twice as many function evaluations with q=2 then with q=1 (see plot legend).

Note: the number of function evaluations done in the BO loop will be equal to $q \cdot \text{number of BO batches}$.

CLmin
KB
KBLB
KBRand
KBUB

Copy link
Collaborator

@nychiang nychiang left a comment

Choose a reason for hiding this comment

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

some minor comments and questions.

Comment on lines +60 to 63
problem = LpNormProblem(nx, xlimits)
else:
problem = BraninProblem(constraints=None)
problem = BraninProblem()
problem.set_constraints(user_constraint)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have two ways to add the constraints:

  1. in the constructor, setting constraints=user_constraint
    or
  2. using function set_constraints.
    I should leave a comment in this example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I understand that there are two methods to set constraints. However, passing None as the constraints to BraninProblem is equivalent to instantiating a BraninProblem with no arguments since the default constraints argument of BraninProblem is None. Or at least it was until I recently changed the default to [ ].

Comment on lines 199 to 208
for batch in range(self.batch_size):
# Get a new sample point
x_new = self._find_best_point(x_train, y_train_virtual)

# Evaluate the new sample point
y_new = self.prob.evaluate(np.atleast_2d(x_new))
# Get a virtual point
y_virtual = self._get_virtual_point(np.atleast_2d(x_new))

# Update training set
x_train = np.vstack([x_train, x_new])
y_train = np.vstack([y_train, y_new])
# Update training set with the virtual point
x_train = np.vstack([x_train, x_new ])
y_train_virtual = np.vstack([y_train_virtual, y_virtual])
Copy link
Collaborator

Choose a reason for hiding this comment

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

if batch_size == 1, we don't need to compute the virtual point, do we?
No matter which batch_type is used, the virtual point only works with batch_size>=2, right?

x_new = self._find_best_point(x_train, y_train)
if self.batch_size > 1:
    y_train_virtual = y_train.copy()
    for batch in range(self.batch_size):
         # Get a virtual point
         y_virtual = self._get_virtual_point(np.atleast_2d(x_new))
         # Update training set with the virtual point
         x_train         = np.vstack([x_train,         x_new    ])
         y_train_virtual = np.vstack([y_train_virtual, y_virtual])
             
         x_new = self._find_best_point(x_train, y_train_virtual)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has now been address. The code was fine as is but it is not strictly necessary to call _get_virtual_point at the final point in the batch.

@@ -5,19 +5,19 @@
Nai-Yuan Chiang <chiang7@llnl.gov>
"""
import numpy as np
import collections.abc
Copy link
Collaborator

Choose a reason for hiding this comment

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

is collections a new dependency?

Copy link
Collaborator Author

@thartland thartland Apr 16, 2025

Choose a reason for hiding this comment

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

collections is a built in module that is not pip installable. See here.

…ecessary virtual_point calls, bug fix for x_opt, removing use of erroneously labeled index batch
Copy link
Collaborator

@cnpetra cnpetra left a comment

Choose a reason for hiding this comment

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

looks great!

@thartland
Copy link
Collaborator Author

@nychiang -- I believe I have addressed all of the changes that you requested. Let me know if there is anything left for me to update.

@cnpetra cnpetra merged commit a063c44 into develop Apr 17, 2025
7 checks passed
@cnpetra cnpetra mentioned this pull request Apr 17, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants