diff --git a/.github/workflows/tunny_ci.yml b/.github/workflows/tunny_ci.yml index e261e53c..fa7ddb6b 100644 --- a/.github/workflows/tunny_ci.yml +++ b/.github/workflows/tunny_ci.yml @@ -73,7 +73,7 @@ jobs: - name: Install dependencies run: | dotnet restore - pip install optuna find-libpython + pip install optuna optuna_dashboard find-libpython botorch - name: Set Python DLL path and PYTHONHOME run: | diff --git a/.vscode/settings.json b/.vscode/settings.json index 675ce3e8..30a839d2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "HITL", "hovertemplate", "Hyperband", + "isinstance", "libpython", "rhinocode", "showlegend", diff --git a/Optuna/Study/StudyWrapper.cs b/Optuna/Study/StudyWrapper.cs index a1fbd2c2..d3434d30 100644 --- a/Optuna/Study/StudyWrapper.cs +++ b/Optuna/Study/StudyWrapper.cs @@ -28,10 +28,11 @@ public StudyWrapper(dynamic study) PyInstance = study; dynamic optuna = Py.Import("optuna"); + dynamic dashboard = Py.Import("optuna_dashboard"); dynamic py = Py.Import("builtins"); - if (!py.isinstance(study, optuna.study.Study)) + if (!py.isinstance(study, optuna.study.Study) && !py.isinstance(study, dashboard.preferential.PreferentialStudy)) { - throw new ArgumentException("study must be an instance of optuna.study.Study."); + throw new ArgumentException("study must be an instance of optuna.study.Study or optuna_dashboard.preferential.PreferentialStudy."); } } diff --git a/OptunaTests/Dashboard/HumanInTheLoop/PreferentialTests.cs b/OptunaTests/Dashboard/HumanInTheLoop/PreferentialTests.cs new file mode 100644 index 00000000..e677e646 --- /dev/null +++ b/OptunaTests/Dashboard/HumanInTheLoop/PreferentialTests.cs @@ -0,0 +1,33 @@ +using Optuna.Sampler.Dashboard; +using Optuna.Study; + +using OptunaTests; + +using Python.Runtime; + +using Xunit; + +namespace Optuna.Dashboard.HumanInTheLoop.Tests +{ + public class PreferentialTests : IClassFixture + { + private readonly TestFixture _fixture; + + public PreferentialTests(TestFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void CreateStudyTest() + { + using (Py.GIL()) + { + dynamic sampler = new PreferentialGpSampler().ToPython(); + var preferential = new Preferential("tmpPath", "storagePath", sampler); + StudyWrapper study = preferential.CreateStudy(10, null, null, "objectiveName"); + Assert.NotNull(study); + } + } + } +} diff --git a/OptunaTests/Study/StudyWrapperTests.cs b/OptunaTests/Study/StudyWrapperTests.cs index d891a86e..e1ff7156 100644 --- a/OptunaTests/Study/StudyWrapperTests.cs +++ b/OptunaTests/Study/StudyWrapperTests.cs @@ -18,7 +18,20 @@ public StudyWrapperTests(TestFixture fixture) } [Fact] - public void ConstructorArgTypeTest() + public void ConstructorArgStudyTest() + { + using (Py.GIL()) + { + dynamic optuna = Py.Import("optuna"); + dynamic study = optuna.create_study(); + var studyWrapper = new StudyWrapper(study); + Assert.Equal(study, studyWrapper.PyInstance); + Assert.Equal(0, studyWrapper.Id); + } + } + + [Fact] + public void ConstructorArgPyIntTest() { using (Py.GIL()) {