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

Add ability to mix batch initial conditions and internal IC generation #2610

Closed
wants to merge 5 commits into from

Conversation

CompRhys
Copy link
Contributor

@CompRhys CompRhys commented Nov 4, 2024

Motivation

See #2609

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Basic testing of the code is easy the challenge is working out what the run on implications might be, will this break people's code?

Related PRs

facebook/Ax#2938

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Nov 4, 2024
@CompRhys CompRhys force-pushed the mixed-initialization branch from f3c63bb to 10e7209 Compare November 4, 2024 18:15
botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/acquisition/input_constructors.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
test/optim/test_optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
@CompRhys CompRhys marked this pull request as ready for review November 5, 2024 16:22
Copy link
Contributor

@Balandat Balandat left a comment

Choose a reason for hiding this comment

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

Thanks. Seems like you have some dtype test issues to fix.

Also, if you rebase on the most recent main branch you don't have to run the conda test in the CI :)

botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
test/optim/test_optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
@CompRhys CompRhys force-pushed the mixed-initialization branch from b5b7fe5 to c1e6d32 Compare November 14, 2024 19:26
@CompRhys
Copy link
Contributor Author

locally tests still failing for FAILED test/optim/test_optimize.py::TestOptimizeAcqf::test_optimize_acqf_runs_given_batch_initial_conditions - RuntimeError: expected scalar type Long but found Float although not really sure how i've caused that

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.98%. Comparing base (a1763a1) to head (ede691c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2610   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files         196      196           
  Lines       17377    17410   +33     
=======================================
+ Hits        17375    17408   +33     
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@CompRhys CompRhys force-pushed the mixed-initialization branch from a2714e0 to 4b1196b Compare November 18, 2024 15:03
@facebook-github-bot
Copy link
Contributor

@saitcakmak has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@saitcakmak
Copy link
Contributor

Looks like the PR is out of sync with the main branch. Can you do another rebase please?

@CompRhys CompRhys changed the title Add ability to mix batch initial conditions and internal IC generation [Do Not Merge] Add ability to mix batch initial conditions and internal IC generation Nov 19, 2024
@CompRhys
Copy link
Contributor Author

CompRhys commented Nov 19, 2024

In this PR as stands I was confused about the roles of q and raw_samples in the initial_batch_generator argument.

Yes this PR doesn't achieve what I intended. This was written against raw_samples but it should be against n_restarts to match the original intent.

@CompRhys CompRhys force-pushed the mixed-initialization branch from e38a3ca to 570a2cb Compare November 20, 2024 15:37
@CompRhys CompRhys changed the title [Do Not Merge] Add ability to mix batch initial conditions and internal IC generation Add ability to mix batch initial conditions and internal IC generation Nov 20, 2024
@CompRhys
Copy link
Contributor Author

@saitcakmak I redid this whole thing after realizing that I had got confused and failed to implement what I originally intended by following raw_samples rather than num_repeats and then got distracted focussing on the trees rather than the forest.

@CompRhys
Copy link
Contributor Author

Apologies for linting..

Two solutions to the homotopy test failure:

  1. either change the following linked lines to the snippet testing that we prune and then generate new restarts.
    # First time we expect to call `prune_candidates` with 4 candidates
    self.assertEqual(
    prune_candidates_mock.call_args_list[0][1]["candidates"].shape,
    torch.Size([4, 1]),
    )
    for i in range(1, 5): # The paths should have been pruned to just one path
    self.assertEqual(
    prune_candidates_mock.call_args_list[i][1]["candidates"].shape,
    torch.Size([1, 1]),
    )
        for i in range(5):
            # assert that the number of restarts are repopulated at each step
            self.assertEqual(
                prune_candidates_mock.call_args_list[i][1]["candidates"].shape,
                torch.Size([4, 1]),
            )
            # assert that the candidates are pruned to just one candidate
            self.assertEqual(
                prune_candidates(**prune_candidates_mock.call_args_list[i][1]).shape,
                torch.Size([1, 1]),
            )
  1. set shared_optimize_acqf_kwargs["raw_samples"]=None at
    # Prune candidates
    to prevent the dimensions from the pruned restarts being filled with random designs in subsequent loops.

To get current behaviour the second option is better, but in principal despite the fact that random IC designs introduced later in the homotopy might not be able to be as readily optimized to sparsity the first option doesn't seem harmful (beyond there being no computational benefit to pruning) and may have upsides.

@saitcakmak
Copy link
Contributor

There is one remaining test failure and a rebase seems to be necessary. Lgtm otherwise

@CompRhys CompRhys force-pushed the mixed-initialization branch from 1ee598c to b6f8b85 Compare November 22, 2024 16:03
@facebook-github-bot
Copy link
Contributor

@saitcakmak has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@Balandat
Copy link
Contributor

reset: squash into single commit

Btw @CompRhys for future reference this is not really necessary - the actual commit on the main branch will be made by our github bot (while maintaining attribution to the PR author), which automatically squashes all the changes together.

@facebook-github-bot
Copy link
Contributor

@saitcakmak has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@Balandat Balandat left a comment

Choose a reason for hiding this comment

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

couple of minor nits, o/w this is good to go. If you merge in the recent changes on master that will also fix the tutorial failure.

botorch/optim/optimize.py Show resolved Hide resolved
botorch/optim/optimize.py Show resolved Hide resolved
botorch/optim/optimize.py Outdated Show resolved Hide resolved
CompRhys and others added 2 commits December 2, 2024 17:14
address internal linter errors and better error message

Co-authored-by: Max Balandat <[email protected]>
@facebook-github-bot
Copy link
Contributor

@saitcakmak has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@saitcakmak merged this pull request in 4190f74.

facebook-github-bot pushed a commit that referenced this pull request Dec 6, 2024
Summary:
## Motivation

In order to get facebook/Ax#2938 over the line with initial candidate generation that obey the constraints we want to use the existing tooling within `botorch`. The hard coded logic currently in Ax uses topk to downselect the sobol samples. To make a change there that will not impact existing users we then need to implement topk downselection in `botorch`.

Pull Request resolved: #2636

Test Plan:
TODO:
- [x] add tests for initialize_q_batch_topk

## Related PRs

facebook/Ax#2938. (#2610 was initially intended to play part of this solution but then I realized that the pattern I wanted to use was conflating repeats and the batch dimension.)

Reviewed By: Balandat

Differential Revision: D66413947

Pulled By: saitcakmak

fbshipit-source-id: 39e71f5cc0468d554419fa25dd545d9ee25289dc
@CompRhys CompRhys deleted the mixed-initialization branch December 14, 2024 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants