Skip to content

Commit

Permalink
Merge pull request #259 from hrntsm/fix/single-objective-opt-continue…
Browse files Browse the repository at this point in the history
…-error

Fix SO optimization continue error
  • Loading branch information
hrntsm authored Feb 27, 2024
2 parents 2284533 + bb4958f commit 2965b6b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Optuna/Study/Study.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static StudySummary[] GetAllStudySummaries(IOptunaStorage storage)
IEnumerable<Trial.Trial> completeTrials = allTrials.Where(trial => trial.State == TrialState.COMPLETE);

StudyDirection direction = StudyDirection.NotSet;
StudyDirection[] directions = Array.Empty<StudyDirection>();
StudyDirection[] directions = null;
Trial.Trial bestTrial = null;
if (studies[i].Directions.Length == 1)
{
Expand Down
4 changes: 0 additions & 4 deletions Optuna/Study/StudySummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public StudyDirection[] Directions
{
get
{
if (_directions.Length == 1)
{
throw new InvalidOperationException("The study has only one direction.");
}
return _directions;
}
}
Expand Down
2 changes: 1 addition & 1 deletion OptunaTests/Storage/StorageSameBevaviorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Optuna.Storage.Tests
{
public class StorageSameBehaviorTests
{
[Theory()]
[Theory]
[InlineData(@"TestFile/sqlite.db", "sqlite")]
[InlineData(@"TestFile/journal.log", "log")]
public void StorageLoadTest(string path, string type)
Expand Down
29 changes: 29 additions & 0 deletions OptunaTests/Study/StudySummaryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

using Optuna.Storage;
using Optuna.Storage.Journal;
using Optuna.Storage.RDB;

using Xunit;

namespace Optuna.Study.Tests
{
public class StudySummaryTests
{
[Theory]
[InlineData(@"TestFile/sqlite.db", "sqlite")]
[InlineData(@"TestFile/journal.log", "log")]
public void StorageLoadStudySummaryTest(string path, string type)
{
IOptunaStorage storage = type == "sqlite"
? new SqliteStorage(path)
: (IOptunaStorage)new JournalStorage(path);
StudySummary[] summary = Study.GetAllStudySummaries(storage);
Assert.Equal(3, summary.Length);
Assert.Equal(2, summary[0].Directions.Length);
Assert.Throws<InvalidOperationException>(() => summary[0].Direction);
Assert.Equal(StudyDirection.Minimize, summary[1].Direction);
Assert.Equal(3, summary[2].Directions.Length);
}
}
}

0 comments on commit 2965b6b

Please sign in to comment.