From afeac2e5c199bbe9142b84fedec77087ccf512c7 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Wed, 28 Feb 2024 00:06:31 +0900 Subject: [PATCH 1/2] Fix SO optimization continue error --- Optuna/Study/Study.cs | 2 +- Optuna/Study/StudySummary.cs | 4 ---- OptunaTests/Study/StudySummaryTests.cs | 29 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 OptunaTests/Study/StudySummaryTests.cs diff --git a/Optuna/Study/Study.cs b/Optuna/Study/Study.cs index c65dc5e4..4db4d7bb 100644 --- a/Optuna/Study/Study.cs +++ b/Optuna/Study/Study.cs @@ -105,7 +105,7 @@ public static StudySummary[] GetAllStudySummaries(IOptunaStorage storage) IEnumerable completeTrials = allTrials.Where(trial => trial.State == TrialState.COMPLETE); StudyDirection direction = StudyDirection.NotSet; - StudyDirection[] directions = Array.Empty(); + StudyDirection[] directions = null; Trial.Trial bestTrial = null; if (studies[i].Directions.Length == 1) { diff --git a/Optuna/Study/StudySummary.cs b/Optuna/Study/StudySummary.cs index a927d919..cbe46b28 100644 --- a/Optuna/Study/StudySummary.cs +++ b/Optuna/Study/StudySummary.cs @@ -66,10 +66,6 @@ public StudyDirection[] Directions { get { - if (_directions.Length == 1) - { - throw new InvalidOperationException("The study has only one direction."); - } return _directions; } } diff --git a/OptunaTests/Study/StudySummaryTests.cs b/OptunaTests/Study/StudySummaryTests.cs new file mode 100644 index 00000000..801a1817 --- /dev/null +++ b/OptunaTests/Study/StudySummaryTests.cs @@ -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(() => summary[0].Direction); + Assert.Equal(StudyDirection.Minimize, summary[1].Direction); + Assert.Equal(3, summary[2].Directions.Length); + } + } +} From bb4958f7df2099db4905d687d0213a90e3eee296 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Wed, 28 Feb 2024 00:15:25 +0900 Subject: [PATCH 2/2] Clean code --- OptunaTests/Storage/StorageSameBevaviorTests.cs | 2 +- OptunaTests/Study/StudySummaryTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OptunaTests/Storage/StorageSameBevaviorTests.cs b/OptunaTests/Storage/StorageSameBevaviorTests.cs index dbd79631..1b60523e 100644 --- a/OptunaTests/Storage/StorageSameBevaviorTests.cs +++ b/OptunaTests/Storage/StorageSameBevaviorTests.cs @@ -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) diff --git a/OptunaTests/Study/StudySummaryTests.cs b/OptunaTests/Study/StudySummaryTests.cs index 801a1817..dec7e9a2 100644 --- a/OptunaTests/Study/StudySummaryTests.cs +++ b/OptunaTests/Study/StudySummaryTests.cs @@ -10,7 +10,7 @@ namespace Optuna.Study.Tests { public class StudySummaryTests { - [Theory()] + [Theory] [InlineData(@"TestFile/sqlite.db", "sqlite")] [InlineData(@"TestFile/journal.log", "log")] public void StorageLoadStudySummaryTest(string path, string type)