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 journal storage loader #732

Merged
merged 16 commits into from
Jan 16, 2024

Conversation

gen740
Copy link
Member

@gen740 gen740 commented Dec 15, 2023

Contributor License Agreement

This repository (optuna-dashboard) and Goptuna share common code.
This pull request may therefore be ported to Goptuna.
Make sure that you understand the consequences concerning licenses and check the box below if you accept the term before creating this pull request.

  • I agree this patch may be ported to Goptuna by other Goptuna contributors.

Reference Issues/PRs

None

What does this implement/fix? Explain your changes.

  • Add journalStorage.ts into standalone app, enabling journal storage support.

Copy link

codecov bot commented Dec 15, 2023

Codecov Report

Attention: 26 lines in your changes are missing coverage. Please review.

Comparison is base (1203501) 68.22% compared to head (48629d3) 68.22%.
Report is 196 commits behind head on main.

Files Patch % Lines
optuna_dashboard/artifact/_backend.py 31.42% 24 Missing ⚠️
optuna_dashboard/_app.py 94.59% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #732   +/-   ##
=======================================
  Coverage   68.22%   68.22%           
=======================================
  Files          35       35           
  Lines        2329     2329           
=======================================
  Hits         1589     1589           
  Misses        740      740           

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

@gen740 gen740 marked this pull request as ready for review December 19, 2023 08:53
@nabenabe0928
Copy link
Collaborator

@c-bata Could you review this PR?

@nabenabe0928
Copy link
Collaborator

@c-bata I removed you from the assignee of this PR.
@keisuke-umezawa Could you review this PR?

Copy link
Member

@keisuke-umezawa keisuke-umezawa left a comment

Choose a reason for hiding this comment

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

This is early review comment. I checked PR other than JournalStorage implementation. I will check it later 🙏
Btw, I hope we can add some tests for it. At least, can you add e2e test for this one similar to this test?

def test_load_storage(
page: Page,
server_url: str,
) -> None:
study_name = "single-objective"
url = f"{server_url}"
def create_storage_file(filename: str):
import optuna
storage = optuna.storages.RDBStorage(f"sqlite:///{filename}")
study = optuna.create_study(study_name=study_name, storage=storage)
def objective(trial: optuna.Trial) -> float:
x1 = trial.suggest_float("x1", 0, 10)
x2 = trial.suggest_float("x2", 0, 10)
return (x1 - 2) ** 2 + (x2 - 5) ** 2
study.optimize(objective, n_trials=100)
with tempfile.TemporaryDirectory() as dir:
with tempfile.NamedTemporaryFile() as fp:
filename = fp.name
path = os.path.join(dir, filename)
create_storage_file(filename)
page.goto(url)
with page.expect_file_chooser() as fc_info:
page.get_by_role(
"button",
name="Load an Optuna Storage Drag your SQLite3 file here or click to browse.",
).click()
file_chooser = fc_info.value
file_chooser.set_files(path)
page.get_by_role("link", name=study_name).click()
def count_components(page: Page, component_name: str):
component_count = page.evaluate(
f"""() => {{
const components = document.querySelectorAll('.{component_name}');
return components.length;
}}"""
)
return component_count
count = count_components(page, "MuiCard-root")
assert count == 4

if (headerString === "SQLite format 3\u0000") {
loadSQLite3Storage(arrayBuffer, setStudies)
} else {
loadJournalStorage(arrayBuffer, setStudies)
Copy link
Member

Choose a reason for hiding this comment

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

[question] Do you have any way to check that the file is compatible with JournalStorage? If yes, we can add "else if" to check it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, there is no "header" or special "flag" in the JournalStorage log. The only requirement for JournalStorage is a JSON line file. We can detect the format by parsing the first line of the log, but I believe this should be handled in the JournalStorage class.

if (headerString === "SQLite format 3\u0000") {
loadSQLite3Storage(arrayBuffer, onceSetStudies)
} else {
loadJournalStorage(arrayBuffer, onceSetStudies)
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

@gen740
Copy link
Member Author

gen740 commented Jan 11, 2024

@keisuke-umezawa Thank you for your comments!
Currently, Optuna-dashboard's standalone app lacks a test system. Consequently, there is no way to implement tests at this time. However, I plan to develop and add a testing system for the standalone app as a follow-up.

@keisuke-umezawa
Copy link
Member

@gen740
Ok. In that case, I will quickly check this PR weather it will not break the entire system. If not, I will merge it soon.

@keisuke-umezawa
Copy link
Member

I confirmed that it also works well in my env. I merge it. Let's add some tests later.

@keisuke-umezawa keisuke-umezawa merged commit 5bc0a94 into optuna:main Jan 16, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants