dotnet / infer

Infer.NET is a framework for running Bayesian inference in graphical models
https://dotnet.github.io/infer/
MIT License
1.56k stars 228 forks source link

Infer .NET does not appear to work on .NET 8.0 #458

Closed JonahL closed 9 months ago

JonahL commented 10 months ago

If this has already been brought up and I somehow missed the issue, please feel free to close this.

Creating a new .NET 8 (8.0.101 in my case) console application, referencing Microsoft.ML.Probabilistic, and Microsoft.ML.Probabilistic.Compiler and replacing the contents of the Program.cs with the following:

using Microsoft.ML.Probabilistic.Models;

Variable<bool> firstCoin = Variable.Bernoulli(0.5).Named("firstCoin");
Variable<bool> secondCoin = Variable.Bernoulli(0.5).Named("secondCoin");

Variable<bool> bothHeads = (firstCoin & secondCoin).Named("bothHeads");

InferenceEngine engine = new InferenceEngine();

Console.WriteLine("Probability both coins are heads: " + engine.Infer(bothHeads));

generates this exception:

Unhandled exception. System.PlatformNotSupportedException: Current platform is not supported by the current compiler choice Auto. Try a different one.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
   at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames)
   at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerParameters options, String[] fileNames)
   at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.CompileWithCodeDom(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
   at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
   --- End of inner exception stack trace ---
   at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
   at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.WriteAndCompile(List`1 typeDeclarations)
   at Microsoft.ML.Probabilistic.Compiler.ModelCompiler.CompileWithoutParams[T](List`1 itds)
   at Microsoft.ML.Probabilistic.Compiler.ModelCompiler.CompileWithoutParams(ITypeDeclaration itd, MethodBase method, AttributeRegistry`2 inputAttributes)
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.Compile()
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.BuildAndCompile(Boolean inferOnlySpecifiedVars, IEnumerable`1 vars)
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.GetCompiledInferenceAlgorithm(Boolean inferOnlySpecifiedVars, IVariable var)
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.InferAll(Boolean inferOnlySpecifiedVars, IVariable var)
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.Infer(IVariable var)
   at Program.<Main>$(String[] args) in C:\Users\Jonah\Desktop\InferExamples\Program.cs:line 10

Process finished with exit code -532,462,766.

This is the *.csproj for reference

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ML.Probabilistic" Version="0.4.2301.301" />
    <PackageReference Include="Microsoft.ML.Probabilistic.Compiler" Version="0.4.2301.301" />
  </ItemGroup>

</Project>

For what it's worth, it works totally fine if I change the target framework from net8.0 to net7.0.

jonathantims commented 9 months ago

Fix in #459

JonahL commented 9 months ago

Ah, for some reason your notification slipped through the cracks. Appreciate the quick response and fix! I'll close this.