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

Feature/support net7 windows build #387

Merged
merged 4 commits into from
Feb 9, 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
7 changes: 5 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Rhino8 - netcore",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"preLaunchTask": "build-net7.0",
"program": "C:/Program Files/Rhino 8/System/Rhino.exe",
"targetArchitecture": "x86_64",
"args": "/netcore /nosplash /runscript=\"_Grasshopper\"",
Expand All @@ -25,7 +25,7 @@
"targetArchitecture": "x86_64",
"args": "/netfx /nosplash /runscript=\"_Grasshopper\"",
"env": {
"RHINO_PACKAGE_DIRS": "${workspaceFolder}/bin/Debug"
"RHINO_PACKAGE_DIRS": "${workspaceFolder}/bin"
},
"cwd": "${workspaceFolder}",
"console": "internalConsole",
Expand All @@ -38,6 +38,9 @@
"preLaunchTask": "build",
"program": "C:/Program Files/Rhino 7/System/Rhino.exe",
"args": "/nosplash /runscript=\"_Grasshopper\"",
"env": {
"RHINO_PACKAGE_DIRS": "${workspaceFolder}/bin"
},
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": true
Expand Down
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
"clear": true
},
"group": "build",
},
{
"label": "build-net7.0",
"command": "dotnet",
"type": "shell",
"args": [
"build",
"/p:TargetFramework=net7.0-windows",
"/clp:NoSummary",
"${workspaceFolder}/Tunny/Tunny.csproj"
],
"problemMatcher": "$msCompile",
"presentation": {
"reveal": "always",
"clear": true
},
"group": "build",
}
]
}
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Please see [here](https://github.com/hrntsm/Tunny/releases) for the data release
- Variables can now be set to log scale from the UI.
- Checkbox which minimize Rhino Window when start optimization
- Support some optunahub sampler.
- Auto sampler, MOEA/D sampler, MO-CMA-ES sampler
- Auto sampler, MOEA/D sampler, MO-CMA-ES sampler, DifferentialEvolution sampler
- ConstructFishEggByCsv component
- Make it easy to set FishEgg to use csv.
- Other Grasshopper component compatibility check.
- Support net7.0-windows build
- For Rhino8

### Changed

Expand Down
4 changes: 3 additions & 1 deletion Optuna/Dashboard/HumanInTheLoop/HumanSliderInput.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;

Expand Down Expand Up @@ -75,7 +76,8 @@
string path = $"{_tmpPath}/image_{study.Id}_{trial.Id}.png";
bitmap?.Save(path, System.Drawing.Imaging.ImageFormat.Png);
dynamic artifactId = uploadArtifact(_artifactBackend, trial.PyInstance, path);
noteText.AppendLine($"![](/artifacts/{study.Id}/{trial.Id}/{artifactId})");
string str = $"![](/artifacts/{study.Id}/{trial.Id}/{artifactId})";
noteText.AppendLine(str);

Check warning on line 80 in Optuna/Dashboard/HumanInTheLoop/HumanSliderInput.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Dashboard/HumanInTheLoop/HumanSliderInput.cs#L79-L80

Added lines #L79 - L80 were not covered by tests
}

dynamic textWrap = _importedLibrary.Get("textwrap");
Expand Down
5 changes: 3 additions & 2 deletions Optuna/Optuna.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48; net7.0-windows</TargetFrameworks>
<NoWarn>NU1701;NETSDK1086</NoWarn>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest-recommended</AnalysisLevel>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -44,6 +44,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0" />
<PackageReference Include="Stub.System.Data.SQLite.Core.NetFramework" Version="1.0.119" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions Optuna/Sampler/OptunaHub/DESampler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Python.Runtime;

namespace Optuna.Sampler.OptunaHub
{
/// <summary>
/// https://hub.optuna.org/samplers/differential_evolution/
/// </summary>
public class DESampler : HubSamplerBase
{
private const string Package = "samplers/differential_evolution";
public double DEFactor { get; set; } = 0.8;
public double CrossOverRate { get; set; } = 0.7;
public int? PopulationSize { get; set; }

public dynamic ToPython()
{
dynamic optunahub = Py.Import("optunahub");

Check warning on line 17 in Optuna/Sampler/OptunaHub/DESampler.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Sampler/OptunaHub/DESampler.cs#L16-L17

Added lines #L16 - L17 were not covered by tests
dynamic module = optunahub.load_module(package: Package, force_reload: ForceReload);
PyObject popSize;
if (PopulationSize == null || PopulationSize.Value <= 0)
{
popSize = new PyString("auto");
}

Check warning on line 23 in Optuna/Sampler/OptunaHub/DESampler.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Sampler/OptunaHub/DESampler.cs#L21-L23

Added lines #L21 - L23 were not covered by tests
else
{
popSize = new PyInt(PopulationSize.Value);
}

Check warning on line 27 in Optuna/Sampler/OptunaHub/DESampler.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Sampler/OptunaHub/DESampler.cs#L25-L27

Added lines #L25 - L27 were not covered by tests
return module.DESampler(
seed: Seed,
population_size: popSize,
F: DEFactor,
CR: CrossOverRate,
debug: false
);
}

Check warning on line 35 in Optuna/Sampler/OptunaHub/DESampler.cs

View check run for this annotation

Codecov / codecov/patch

Optuna/Sampler/OptunaHub/DESampler.cs#L29-L35

Added lines #L29 - L35 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion Optuna/Storage/IOptunaStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IOptunaStorage
int GetTrialNumberFromId(int trialId);
double GetTrialParam(int trialId, string paramName);
bool SetTrialStateValue(int trialId, TrialState state, double[] values = null);
void SetTrialIntermediateValue(int trialId, int step, double intermediateValue);
void SetTrialIntermediateValue(int trialId, int intermediateStep, double intermediateValue);
void SetTrialUserAttr(int trialId, string key, object value);
void SetTrialSystemAttr(int trialId, string key, object value);

Expand Down
2 changes: 1 addition & 1 deletion Optuna/Storage/Journal/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public void SetTrailParam(int trialId, string paramName, double paramValueIntern
GetTrial(trialId).Params[paramName] = paramValueInternal;
}

public void SetTrialIntermediateValue(int trialId, int step, double intermediateValue)
public void SetTrialIntermediateValue(int trialId, int intermediateStep, double intermediateValue)
{
throw new NotImplementedException();
}
Expand Down
8 changes: 4 additions & 4 deletions Optuna/Storage/RDB/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
throw new NotImplementedException();
}

public void SetTrialIntermediateValue(int trialId, int step, double intermediateValue)
public void SetTrialIntermediateValue(int trialId, int intermediateStep, double intermediateValue)
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -356,7 +356,7 @@
{
while (reader.Read())
{
directions.Add((StudyDirection)Enum.Parse(typeof(StudyDirection), reader.GetString(0), true));

Check warning on line 359 in Optuna/Storage/RDB/Storage.cs

View workflow job for this annotation

GitHub Actions / test

Prefer the generic overload 'System.Enum.Parse<TEnum>(string, bool)' instead of 'System.Enum.Parse(System.Type, string, bool)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2263)

Check warning on line 359 in Optuna/Storage/RDB/Storage.cs

View workflow job for this annotation

GitHub Actions / test

Prefer the generic overload 'System.Enum.Parse<TEnum>(string, bool)' instead of 'System.Enum.Parse(System.Type, string, bool)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2263)
}
}
}
Expand Down Expand Up @@ -446,7 +446,7 @@
{
TrialId = trialId,
Number = reader.GetInt32(0),
State = (TrialState)Enum.Parse(typeof(TrialState), reader.GetString(1), true),

Check warning on line 449 in Optuna/Storage/RDB/Storage.cs

View workflow job for this annotation

GitHub Actions / test

Prefer the generic overload 'System.Enum.Parse<TEnum>(string, bool)' instead of 'System.Enum.Parse(System.Type, string, bool)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2263)

Check warning on line 449 in Optuna/Storage/RDB/Storage.cs

View workflow job for this annotation

GitHub Actions / test

Prefer the generic overload 'System.Enum.Parse<TEnum>(string, bool)' instead of 'System.Enum.Parse(System.Type, string, bool)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2263)
DatetimeStart = reader.GetDateTime(2),
DatetimeComplete = completeTime
};
Expand Down Expand Up @@ -610,7 +610,7 @@
{
string key = reader.GetString(0);
string value = reader.GetString(1);
if (!string.IsNullOrEmpty(value) && value.Contains("[") && value.Contains("]"))
if (!string.IsNullOrEmpty(value) && value.Contains('[') && value.Contains(']'))
{
//FIXME: This is a hack to handle the case where the value is a list of strings.
if (key.Contains("preference"))
Expand All @@ -626,7 +626,7 @@
}
catch (JsonReaderException)
{
if (value.Contains("\""))
if (value.Contains('"'))
{
value = value.Replace("\"", "");
}
Expand All @@ -636,7 +636,7 @@
}
else
{
if (value.Contains("\""))
if (value.Contains('"'))
{
value = value.Replace("\"", "");
}
Expand Down
3 changes: 1 addition & 2 deletions OptunaTests/OptunaTests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48; net7.0-windows</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions Tunny.Core/Settings/Sampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public AutoSampler Auto { get; set; } = new AutoSampler();
public MOEADSampler MOEAD { get; set; } = new MOEADSampler();
public MoCmaEsSampler MoCmaEs { get; set; } = new MoCmaEsSampler();
public DESampler DE { get; set; } = new DESampler();

// Optuna
public RandomSampler Random { get; set; } = new RandomSampler();
Expand Down Expand Up @@ -71,6 +72,9 @@
case SamplerType.MoCmaEs:
optunaSampler = MoCmaEs.ToPython();
break;
case SamplerType.DE:
optunaSampler = DE.ToPython();
break;

Check warning on line 77 in Tunny.Core/Settings/Sampler.cs

View check run for this annotation

Codecov / codecov/patch

Tunny.Core/Settings/Sampler.cs#L76-L77

Added lines #L76 - L77 were not covered by tests
default:
throw new ArgumentException("Invalid sampler type.");
}
Expand Down
1 change: 1 addition & 0 deletions Tunny.Core/TEnum/SamplerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public enum SamplerType
AUTO = 11,
MoCmaEs = 12,
MOEAD = 13,
DE = 14,
}
}
4 changes: 2 additions & 2 deletions Tunny.Core/Tunny.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48; net7.0-windows</TargetFrameworks>
<NoWarn>NU1701;NETSDK1086</NoWarn>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest-recommended</AnalysisLevel>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions Tunny.CoreTests/Tunny.CoreTests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48; net7.0-windows</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Tunny/Component/LoadingInstruction/InitializeCef_Tunny.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;

using CefSharp;

using Grasshopper.Kernel;

using Tunny.Core.Util;
Expand All @@ -21,7 +19,9 @@ private static void InitializeCefRuntimeResolver()
{
try
{
CefRuntime.SubscribeAnyCpuAssemblyResolver(TEnvVariables.ComponentFolder);
#if NET48
CefSharp.CefRuntime.SubscribeAnyCpuAssemblyResolver(TEnvVariables.ComponentFolder);
#endif
}
catch (Exception e)
{
Expand Down
11 changes: 6 additions & 5 deletions Tunny/Component/Util/FishMarket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class FishMarket : GH_Component
{
private readonly List<Plane> _tagPlanes = new List<Plane>();
private List<GH_Fish> _fishes = new List<GH_Fish>();
private readonly List<GH_Fish> _fishes = new List<GH_Fish>();
private double _size = 1;
private Settings _settings = new Settings();

Expand Down Expand Up @@ -83,9 +83,10 @@

private GH_Structure<IGH_GeometricGoo> ArrayedGeometries(IEnumerable<object> fishObjects)
{
int countY = 0;
var arrayedGeometries = new GH_Structure<IGH_GeometricGoo>();
_fishes = fishObjects.Select(x => (GH_Fish)x).ToList();
throw new NotImplementedException();
// int countY = 0;

Check warning on line 87 in Tunny/Component/Util/FishMarket.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tunny/Component/Util/FishMarket.cs#L87

Remove this commented out code.
// var arrayedGeometries = new GH_Structure<IGH_GeometricGoo>();
// _fishes = fishObjects.Select(x => (GH_Fish)x).ToList();

// while (true)
// {
Expand All @@ -98,7 +99,7 @@
// countY++;
// }

return arrayedGeometries;
// return arrayedGeometries;
}

private bool SetGeometryToResultArray(int countY, GH_Structure<IGH_GeometricGoo> arrayedGeometries, List<List<GeometryBase>> fishGeometries)
Expand Down
Loading
Loading