Skip to content

Commit

Permalink
Merge pull request #337 from hrntsm/Fix/percentile-pruner
Browse files Browse the repository at this point in the history
Fix/percentile pruner
  • Loading branch information
hrntsm authored Nov 12, 2024
2 parents 25b7875 + 945112d commit 836cfc4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
21 changes: 20 additions & 1 deletion Tunny/Solver/Algorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ private TrialGrasshopperItems RunSingleOptimizeStep(OptimizationHandlingInfo opt
result.Artifacts.UploadArtifacts(optInfo.ArtifactBackend, trial);
}

if (!(bool)optInfo.Study._is_multi_objective() && (bool)trial.should_prune())
bool shouldPrune = CheckShouldPrune(trial);

if (Objective.Length == 1 && shouldPrune)
{
optInfo.Study.tell(trial, state: optuna.trial.TrialState.PRUNED);
TLog.Warning($"Trial {trialNum} pruned.");
Expand Down Expand Up @@ -384,6 +386,23 @@ private TrialGrasshopperItems RunSingleOptimizeStep(OptimizationHandlingInfo opt
return result;
}

//TODO: Fix Do not use try-catch block
private static bool CheckShouldPrune(dynamic trial)
{
bool shouldPrune;
try
{
shouldPrune = trial.should_prune();
}
catch (Exception)
{
PyObject pyShouldPrune = trial.should_prune().item();
shouldPrune = pyShouldPrune.As<bool>();
}

return shouldPrune;
}

private static bool IsSampleDuplicate(dynamic trial, out TrialGrasshopperItems result)
{
double[] values;
Expand Down
11 changes: 0 additions & 11 deletions Tunny/UI/OptimizationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ public OptimizationWindow(OptimizeComponentBase component)
SetupTTDesignExplorer();
SetOptimizeBackgroundWorker();
SetOutputResultBackgroundWorker();
CheckPruner();
}

private void CheckPruner()
{
TLog.MethodStart();
_settings.Pruner.CheckStatus();
if (_settings.Pruner.GetPrunerStatus() == PrunerStatus.PathError)
{
WPF.Common.TunnyMessageBox.Show("PrunerPath has something wrong. Please check.", "Tunny", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

private static void SetupTTDesignExplorer()
Expand Down
10 changes: 10 additions & 0 deletions Tunny/WPF/Common/TunnyMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ internal static void Error_IncorrectVariableInput()
MessageBoxImage.Error);
}

internal static void Error_PrunerPath()
{
TLog.MethodStart();
Show(
"PrunerPath has something wrong. Please check.",
"Tunny",
MessageBoxButton.OK,
MessageBoxImage.Error);
}

internal static void Error_IncorrectObjectiveInput()
{
TLog.MethodStart();
Expand Down
12 changes: 12 additions & 0 deletions Tunny/WPF/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public MainWindowViewModel()
_optimizePage = new OptimizePage();
_optimizePage.ChangeTargetSampler(OptimizeProcess.Settings.Optimize.SamplerType);
MainWindowFrame = _optimizePage;

CheckPruner();
}

private void UpdateTitle()
Expand All @@ -52,6 +54,16 @@ private void UpdateTitle()
WindowTitle = $"Tunny v{TEnvVariables.Version.ToString(2)} - {storagePath}";
}

private static void CheckPruner()
{
TLog.MethodStart();
OptimizeProcess.Settings.Pruner.CheckStatus();
if (OptimizeProcess.Settings.Pruner.GetPrunerStatus() == PrunerStatus.PathError)
{
TunnyMessageBox.Error_PrunerPath();
}
}

private DelegateCommand<VisualizeType?> _selectVisualizeTypeCommand;
public ICommand SelectVisualizeTypeCommand
{
Expand Down

0 comments on commit 836cfc4

Please sign in to comment.