-
Notifications
You must be signed in to change notification settings - Fork 9
Integrating MongoDB MVP #383
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
Open
Gawthaman
wants to merge
11
commits into
AccelerationConsortium:main
Choose a base branch
from
Gawthaman:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cfae831
Integrating MongoDB MVP
Gawthaman 4353f4f
Refactor experiment setup to include dynamic Sobol trial management a…
Gawthaman 0d5ae9d
Fixing MongdDB Integration Using Built In Serialization Method
Gawthaman fe004b8
Refactor snapshot handling in MongoDB integration and streamline gene…
Gawthaman 633f4b2
Remove temporary file handling from MongoDB snapshot saving function
Gawthaman c5c7a97
Refactor import statements and improve code formatting for MongoDB in…
Gawthaman 8c499f9
Clean up whitespace and improve code readability in MongoDB integrati…
Gawthaman 932d37b
Refactor MongoDB connection handling and improve snapshot saving logic
Gawthaman 454d471
Add scripts for MongoDB persistence testing and recovery demonstration
Gawthaman 3d65800
Refactor MongoDB persistence testing scripts and implement new integr…
Gawthaman 89b7183
Update references to 'Untitled-1.py' with 'mongodbintegrationmvp.py' …
Gawthaman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Generated by Honegumi (https://arxiv.org/abs/2502.06815) | ||
# pip install ax-platform==0.4.3 numpy pymongo | ||
import numpy as np | ||
from ax.service.ax_client import AxClient, ObjectiveProperties | ||
from pymongo import MongoClient # Added import for MongoDB | ||
|
||
|
||
obj1_name = "branin" | ||
|
||
|
||
def branin(x1, x2): | ||
y = float( | ||
(x2 - 5.1 / (4 * np.pi**2) * x1**2 + 5.0 / np.pi * x1 - 6.0) ** 2 | ||
+ 10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x1) | ||
+ 10 | ||
) | ||
|
||
return y | ||
|
||
|
||
# Connect to MongoDB | ||
tmongo_client = MongoClient("mongodb://localhost:27017/") | ||
db = tmongo_client["ax_db"] | ||
experiments_col = db["experiments"] | ||
|
||
# Experiment configuration | ||
parameters = [ | ||
{"name": "x1", "type": "range", "bounds": [-5.0, 10.0]}, | ||
{"name": "x2", "type": "range", "bounds": [0.0, 10.0]}, | ||
] | ||
objectives = {obj1_name: ObjectiveProperties(minimize=True)} | ||
|
||
# Load existing experiment state or initialize new | ||
record = experiments_col.find_one({"experiment_name": obj1_name}) | ||
if record: | ||
ax_client = AxClient() | ||
ax_client.create_experiment(name=obj1_name, parameters=parameters, objectives=objectives) | ||
saved_trials = record.get("trials", []) | ||
# Replay saved trials | ||
for t in saved_trials: | ||
ax_client.complete_trial(trial_index=t["trial_index"], raw_data=t["raw_data"]) | ||
Gawthaman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
start_i = len(saved_trials) | ||
else: | ||
ax_client = AxClient() | ||
ax_client.create_experiment(name=obj1_name, parameters=parameters, objectives=objectives) | ||
Gawthaman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
start_i = 0 | ||
experiments_col.insert_one({"experiment_name": obj1_name, "trials": []}) | ||
|
||
for i in range(start_i, 19): | ||
Gawthaman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
parameterization, trial_index = ax_client.get_next_trial() | ||
|
||
# extract parameters | ||
x1 = parameterization["x1"] | ||
x2 = parameterization["x2"] | ||
|
||
results = branin(x1, x2) | ||
ax_client.complete_trial(trial_index=trial_index, raw_data=results) | ||
Gawthaman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Save trial results to MongoDB | ||
experiments_col.update_one( | ||
{"experiment_name": obj1_name}, | ||
{"$push": {"trials": {"trial_index": trial_index, "raw_data": results}}}, | ||
) | ||
|
||
best_parameters, metrics = ax_client.get_best_parameters() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.