Skip to content

Commit

Permalink
Add LoadStudy method to Study class and use it in Visualize class
Browse files Browse the repository at this point in the history
  • Loading branch information
hrntsm committed Feb 24, 2024
1 parent f659b53 commit dead5e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Optuna/Study/Study.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,10 @@ public static dynamic CreateStudy(dynamic optuna, string studyName, dynamic samp
load_if_exists: loadIfExists
);
}

public static dynamic LoadStudy(dynamic optuna, dynamic storage, string studyName)
{

Check warning on line 151 in Optuna/Study/Study.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Study/Study.cs#L151

Added line #L151 was not covered by tests
return optuna.load_study(storage: storage, study_name: studyName);
}

Check warning on line 153 in Optuna/Study/Study.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Study/Study.cs#L153

Added line #L153 was not covered by tests
}
}
17 changes: 2 additions & 15 deletions Tunny/Solver/Visualize.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Windows.Forms;

using Optuna.Study;
using Optuna.Visualization;

using Python.Runtime;
Expand All @@ -24,20 +25,6 @@ public Visualize(TSettings settings, bool hasConstraint)
_hasConstraint = hasConstraint;
}

private static dynamic LoadStudy(dynamic optuna, dynamic storage, string studyName)
{
TLog.MethodStart();
try
{
return optuna.load_study(storage: storage, study_name: studyName);
}
catch (Exception e)
{
TunnyMessageBox.Show(e.Message, "Tunny", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}

public void Plot(Plot pSettings)
{
TLog.MethodStart();
Expand All @@ -46,7 +33,7 @@ public void Plot(Plot pSettings)
{
dynamic optuna = Py.Import("optuna");
dynamic storage = _settings.Storage.CreateNewOptunaStorage(false);
dynamic study = LoadStudy(optuna, storage, pSettings.TargetStudyName);
dynamic study = Study.LoadStudy(optuna, storage, pSettings.TargetStudyName);
if (study == null)
{
return;
Expand Down

0 comments on commit dead5e0

Please sign in to comment.