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 optuna hub force reload #384

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Optuna/Sampler/NSGAIIISampler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Optuna.Sampler.OptunaHub;

using Python.Runtime;

namespace Optuna.Sampler
Expand Down
4 changes: 2 additions & 2 deletions Optuna/Sampler/OptunaHub/AutoSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace Optuna.Sampler.OptunaHub
/// <summary>
/// https://hub.optuna.org/samplers/auto_sampler/
/// </summary>
public class AutoSampler : SamplerBase
public class AutoSampler : HubSamplerBase
{
private const string Package = "samplers/auto_sampler";

public dynamic ToPython()
{
dynamic optunahub = Py.Import("optunahub");
dynamic module = optunahub.load_module(package: Package);
dynamic module = optunahub.load_module(package: Package, force_reload: ForceReload);
return module.AutoSampler(
seed: Seed
);
Expand Down
7 changes: 7 additions & 0 deletions Optuna/Sampler/OptunaHub/HubSamplerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Optuna.Sampler.OptunaHub
{
public class HubSamplerBase : SamplerBase
{
public bool ForceReload { get; set; }
}
}
3 changes: 2 additions & 1 deletion Optuna/Sampler/OptunaHub/MOEADSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MOEADSampler : GASamplerBase
public double SwappingProb { get; set; } = 0.5;
public ScalarAggregationType ScalarAggregation { get; set; } = ScalarAggregationType.tchebycheff;
public int NumNeighbors { get; set; } = -1;
public bool ForceReload { get; set; }

public dynamic ToPython()
{
Expand All @@ -25,7 +26,7 @@ public dynamic ToPython()
{
NumNeighbors = PopulationSize / 5;
}
dynamic module = optunahub.load_module(package: Package);
dynamic module = optunahub.load_module(package: Package, force_reload: ForceReload);
return module.MOEADSampler(
population_size: PopulationSize,
mutation_prob: MutationProb,
Expand Down
4 changes: 2 additions & 2 deletions Optuna/Sampler/OptunaHub/MoCmaEsSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Optuna.Sampler.OptunaHub
{
public class MoCmaEsSampler : SamplerBase
public class MoCmaEsSampler : HubSamplerBase
{
private const string Package = "samplers/mocma";
public int? PopulationSize { get; set; }

public dynamic ToPython()
{
dynamic optunahub = Py.Import("optunahub");
dynamic module = optunahub.load_module(package: Package);
dynamic module = optunahub.load_module(package: Package, force_reload: ForceReload);
return module.MoCmaSampler(
popsize: PopulationSize,
seed: Seed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;

using Python.Runtime;

namespace Optuna.Sampler
namespace Optuna.Sampler.OptunaHub
{
/// <summary>
/// https://optuna.readthedocs.io/en/stable/reference/generated/optuna.samplers.NSGAIISampler.html
Expand All @@ -15,12 +13,13 @@ public class NSGAIISampler : GASamplerBase
public string Crossover { get; set; } = "BLXAlpha";
public double CrossoverProb { get; set; } = 0.9;
public double SwappingProb { get; set; } = 0.5;
public bool ForceReload { get; set; }

public dynamic ToPython(bool hasConstraints)
{
dynamic optuna = Py.Import("optuna");
dynamic optunahub = Py.Import("optunahub");
dynamic module = optunahub.load_module(package: Package);
dynamic module = optunahub.load_module(package: Package, force_reload: ForceReload);
return module.NSGAIIwITSampler(
population_size: PopulationSize,
mutation_prob: MutationProb,
Expand Down
38 changes: 21 additions & 17 deletions Tunny/WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
Command="{Binding QuickAccessStorageFileOpenCommand}"
SmallImageSource="{StaticResource OpenFolderOutline}"
ToolTip="Open Optimization Result File" />
<RibbonCheckBox
IsChecked="{Binding ShowTopmost}"
Label="Show Topmost"
ToolTip="Show Topmost" />
</RibbonQuickAccessToolBar>
</Ribbon.QuickAccessToolBar>

Expand Down Expand Up @@ -92,15 +96,8 @@
Label="GP BoTorch"
LargeImageSource="{StaticResource Torch}"
SmallImageSource="{StaticResource Torch}" />
<RibbonButton
Command="{Binding SelectSamplerCommand}"
CommandParameter="{x:Static common:SelectSamplerType.GpPreferential}"
IsEnabled="False"
Label="GP Preferential"
LargeImageSource="{StaticResource Compare}"
SmallImageSource="{StaticResource Compare}" />
</RibbonGroup>
<RibbonGroup Header="Genetic Algorithm">
<RibbonGroup Header="Evolution Algorithm">
<RibbonButton
Command="{Binding SelectSamplerCommand}"
CommandParameter="{x:Static common:SelectSamplerType.NSGAII}"
Expand All @@ -113,6 +110,13 @@
Label="NSGA-III"
LargeImageSource="{StaticResource EggEaster}"
SmallImageSource="{StaticResource EggEaster}" />
<RibbonButton
Command="{Binding SelectSamplerCommand}"
CommandParameter="{x:Static common:SelectSamplerType.MOEAD}"
IsEnabled="{Binding IsMultiObjective}"
Label="MOEA/D"
LargeImageSource="{StaticResource WrapDisabled}"
SmallImageSource="{StaticResource WrapDisabled}" />
</RibbonGroup>
<RibbonGroup Header="Evolution Strategy">
<RibbonButton
Expand All @@ -130,15 +134,6 @@
LargeImageSource="{StaticResource CircleMultiple}"
SmallImageSource="{StaticResource CircleMultiple}" />
</RibbonGroup>
<RibbonGroup Header="Evolution Algorithm">
<RibbonButton
Command="{Binding SelectSamplerCommand}"
CommandParameter="{x:Static common:SelectSamplerType.MOEAD}"
IsEnabled="{Binding IsMultiObjective}"
Label="MOEA/D"
LargeImageSource="{StaticResource WrapDisabled}"
SmallImageSource="{StaticResource WrapDisabled}" />
</RibbonGroup>
<RibbonGroup Header="Misc">
<RibbonButton
Command="{Binding SelectSamplerCommand}"
Expand All @@ -159,6 +154,15 @@
LargeImageSource="{StaticResource AllInclusiveBox}"
SmallImageSource="{StaticResource AllInclusiveBox}" />
</RibbonGroup>
<RibbonGroup Header="Human in the loop">
<RibbonButton
Command="{Binding SelectSamplerCommand}"
CommandParameter="{x:Static common:SelectSamplerType.GpPreferential}"
IsEnabled="False"
Label="GP Preferential"
LargeImageSource="{StaticResource Compare}"
SmallImageSource="{StaticResource Compare}" />
</RibbonGroup>
<RibbonGroup Header="Optuna Hub">
<RibbonButton
Command="{Binding RegisterOptunaHubSamplerCommand}"
Expand Down
11 changes: 11 additions & 0 deletions Tunny/WPF/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,16 @@ internal void UpdateExistStudySummaries()
viewModel.UpdateExistStudySummaries();
}
}

private bool? _showTopmost;
public bool? ShowTopmost
{
get => _showTopmost;
set
{
SetProperty(ref _showTopmost, value);
SharedItems.Instance.TunnyWindow.Topmost = value == true;
}
}
}
}
10 changes: 10 additions & 0 deletions Tunny/WPF/Views/Pages/Settings/Sampler/AutoSettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
Text="AUTO"
TextAlignment="Right" />

<CheckBox
x:Name="AutoForceReloadCheckBox"
Grid.Row="8"
Grid.Column="0"
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="ForceReload"
IsChecked="False" />

<Button
Grid.Row="8"
Grid.Column="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal AutoSampler ToSettings()
Seed = AutoSeedTextBox.Text == "AUTO"
? null
: (int?)int.Parse(AutoSeedTextBox.Text, CultureInfo.InvariantCulture),
ForceReload = AutoForceReloadCheckBox.IsChecked == true
};
}

Expand All @@ -51,6 +52,7 @@ private void AutoSeedTextBox_LostFocus(object sender, RoutedEventArgs e)
private void DefaultButton_Click(object sender, RoutedEventArgs e)
{
AutoSeedTextBox.Text = "AUTO";
AutoForceReloadCheckBox.IsChecked = false;
}
}
}
9 changes: 9 additions & 0 deletions Tunny/WPF/Views/Pages/Settings/Sampler/MOEADSettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@
Grid.Column="1"
Margin="5" />

<CheckBox
x:Name="MoeadForceReloadCheckBox"
Grid.Row="8"
Grid.Column="0"
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="ForceReload"
IsChecked="False" />
<Button
Grid.Row="8"
Grid.Column="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ internal MOEADSampler ToSettings()
NumNeighbors = MoeadNeighborsTextBox.Text == "AUTO"
? -1
: int.Parse(MoeadNeighborsTextBox.Text, CultureInfo.InvariantCulture),
ScalarAggregation = (ScalarAggregationType)MoeadScalarAggregationComboBox.SelectedIndex
ScalarAggregation = (ScalarAggregationType)MoeadScalarAggregationComboBox.SelectedIndex,
ForceReload = MoeadForceReloadCheckBox.IsChecked == true
};
}

Expand All @@ -64,6 +65,7 @@ internal static MOEADSettingsPage FromSettings(TSettings settings)
page.MoeadNeighborsTextBox.Text = moead.NumNeighbors == -1
? "AUTO"
: moead.NumNeighbors.ToString(CultureInfo.InvariantCulture);
page.MoeadForceReloadCheckBox.IsChecked = false;
return page;
}

Expand Down Expand Up @@ -111,6 +113,7 @@ private void DefaultButton_Click(object sender, RoutedEventArgs e)
MoeadCrossoverComboBox.SelectedIndex = 1;
MoeadNeighborsTextBox.Text = "AUTO";
MoeadScalarAggregationComboBox.SelectedIndex = 1;
MoeadForceReloadCheckBox.IsChecked = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
Text="AUTO"
TextAlignment="Right" />

<CheckBox
x:Name="MoCmaEsForceReloadCheckBox"
Grid.Row="8"
Grid.Column="0"
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="ForceReload"
IsChecked="False" />
<Button
Grid.Row="8"
Grid.Column="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal MoCmaEsSampler ToSettings()
PopulationSize = MoCmaEsPopulationSizeTextBox.Text == "AUTO"
? null
: (int?)int.Parse(MoCmaEsPopulationSizeTextBox.Text, CultureInfo.InvariantCulture),
ForceReload = MoCmaEsForceReloadCheckBox.IsChecked == true
};
}

Expand All @@ -44,6 +45,7 @@ internal static MoCmaEsSettingsPage FromSettings(TSettings settings)
page.MoCmaEsPopulationSizeTextBox.Text = cmaEs.PopulationSize == null
? "AUTO"
: cmaEs.PopulationSize?.ToString(CultureInfo.InvariantCulture);
page.MoCmaEsForceReloadCheckBox.IsChecked = false;
return page;
}

Expand All @@ -65,6 +67,7 @@ private void DefaultButton_Click(object sender, RoutedEventArgs e)
{
MoCmaEsSeedTextBox.Text = "AUTO";
MoCmaEsPopulationSizeTextBox.Text = "AUTO";
MoCmaEsForceReloadCheckBox.IsChecked = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@
Grid.Column="1"
Margin="5" />

<CheckBox
x:Name="NsgaiiForceReloadCheckBox"
Grid.Row="8"
Grid.Column="0"
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="ForceReload"
IsChecked="False" />
<Button
Grid.Row="8"
Grid.Column="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows;
using System.Windows.Controls;

using Optuna.Sampler;
using Optuna.Sampler.OptunaHub;

using Tunny.Core.Input;
using Tunny.Core.Settings;
Expand Down Expand Up @@ -35,7 +35,8 @@ internal NSGAIISampler ToSettings()
: (double?)double.Parse(NsgaiiMutationProbabilityTextBox.Text, System.Globalization.CultureInfo.InvariantCulture),
CrossoverProb = double.Parse(NsgaiiCrossoverProbabilityTextBox.Text, System.Globalization.CultureInfo.InvariantCulture),
SwappingProb = double.Parse(NsgaiiSwappingProbabilityTextBox.Text, System.Globalization.CultureInfo.InvariantCulture),
Crossover = ((NsgaCrossoverType)NsgaiiCrossoverComboBox.SelectedIndex).ToString()
Crossover = ((NsgaCrossoverType)NsgaiiCrossoverComboBox.SelectedIndex).ToString(),
ForceReload = NsgaiiForceReloadCheckBox.IsChecked == true
};
}

Expand All @@ -53,6 +54,7 @@ internal static NSGAIISettingsPage FromSettings(TSettings settings)
page.NsgaiiSwappingProbabilityTextBox.Text = nsgaii.SwappingProb.ToString(System.Globalization.CultureInfo.InvariantCulture);
page.NsgaiiCrossoverComboBox.SelectedIndex = string.IsNullOrEmpty(nsgaii.Crossover)
? 0 : (int)Enum.Parse(typeof(NsgaCrossoverType), nsgaii.Crossover);
page.NsgaiiForceReloadCheckBox.IsChecked = false;
return page;
}

Expand Down Expand Up @@ -90,6 +92,7 @@ private void DefaultButton_Click(object sender, RoutedEventArgs e)
NsgaiiCrossoverProbabilityTextBox.Text = "0.9";
NsgaiiSwappingProbabilityTextBox.Text = "0.5";
NsgaiiCrossoverComboBox.SelectedIndex = 1;
NsgaiiForceReloadCheckBox.IsChecked = false;
}
}
}
Loading