Giter VIP home page Giter VIP logo

zen's People

Contributors

alberdingk-thijm avatar maxlevatich avatar microsoft-github-operations[bot] avatar microsoftopensource avatar rabeckett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zen's Issues

Tracking progress of Solve()

Would it be possible to provide a mechanism to track the progress of the Solve() method?
The purpose is to allow callers to gain greater visibility on the performance and work done. With that, we could show a progress bar to the end user.

Something like the following:

IProgress<int> p = new Progress<int>(i => progressBar1.Value = i);
var solution = Zen.And(constraints).Solve(progress: p);

In combination with #87 , this allows end-users to see the progress, and even cancel the execution (if he deems it will take too long)

Apple silicon compatibility?

Running on macOS Sonoma 14.3 with Apple M2 Pro, using .NET 8.0.101:

Test.csproj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ZenLib" Version="3.1.6" />
    <PackageReference Include="ZenLib.Generators" Version="0.1.3" />
  </ItemGroup>

</Project>

Point.cs

using ZenLib;

[ZenObject]
public class Point {
    public int X { get; set; }
    public int Y { get; set; }
    
    public static Zen<Point> Add(Zen<Point> p1, Zen<Point> p2) {
        return p1.WithX(p1.GetX() + p2.GetX()).WithY(p1.GetY() + p2.GetY());
    }
}

Program.cs

using ZenLib;
using static Point;

var p = Zen.Symbolic<Point>();
var q = Zen.Symbolic<Point>();
var b = Point.Add(p, q).GetX() > 0;
var solution = b.Solve();
System.Console.WriteLine(solution.Get(p));

Errors on botnet build

CSC : warning CS8034: Unable to load Analyzer assembly /Users/a/.nuget/packages/zenlib.generators/0.1.3/analyzers/dotnet/cs/ZenLib.Generators.dll : Unable to load ZenLib.Generators [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/Point.cs(9,28): error CS1061: 'Zen<Point>' does not contain a definition for 'GetX' and no accessible extension method 'GetX' accepting a first argument of type 'Zen<Point>' could be found (are you missing a using directive or an assembly reference?) [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/Point.cs(9,40): error CS1061: 'Zen<Point>' does not contain a definition for 'GetX' and no accessible extension method 'GetX' accepting a first argument of type 'Zen<Point>' could be found (are you missing a using directive or an assembly reference?) [/Users/a/test/Test/Test.csproj]
...

I also tried .NET SDK x64 (but running on Apple silicon) and the errors are:

/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(6,11): error CS1001: Identifier expected [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(6,11): error CS1514: { expected [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(6,12): error CS0116: A namespace cannot directly contain members such as fields, methods or statements [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(6,28): error CS1001: Identifier expected [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(6,28): error CS1514: { expected [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(7,1): error CS1022: Type or namespace definition, or end-of-file expected [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/ZenLib.Generators/ZenLib.Generators.ZenIncrementalGenerator/PointExtensions_0_zen.g.cs(58,2): error CS1513: } expected [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/Point.cs(9,28): error CS1061: 'Zen<Point>' does not contain a definition for 'GetX' and no accessible extension method 'GetX' accepting a first argument of type 'Zen<Point>' could be found (are you missing a using directive or an assembly reference?) [/Users/a/test/Test/Test.csproj]
/Users/a/test/Test/Point.cs(9,40): error CS1061: 'Zen<Point>' does not contain a definition for 'GetX' and no accessible extension method 'GetX' accepting a first argument of type 'Zen<Point>' could be found (are you missing a using directive or an assembly reference?) [/Users/a/test/Test/Test.csproj]
...

Does ZenLib support the Apple silicon at present? Thank you very much!

Support for class/struct types with more than 8 fields broken

Using my own classes and/or structs with more than 8 fields doesn't seem to work. Maybe I'm doing something wrong? Here's what I tried:

    public class /* struct */ Matrix3x3
    {
        public int v11, v12, v13;
        public int v21, v22, v23;
        public int v31, v32, v33;
    }

    class Program
    {
        static Zen<bool> PerformMath(Zen<Matrix3x3> m)
        {
            return true;
        }

        static void Main(string[] args)
        {
            var function = Function<Matrix3x3,bool>(PerformMath);
            var input = function.Find((a, result) => result);
        }
    }

This leads to the following exception:

System.InvalidOperationException: 'Sequence contains no elements'
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.Research.Zen.Generation.GeneratorHelper.GetCreateObjectMethod(Int32 numFields) in C:\Users\de\Source\Repos\Zen\Zen\Generation\GeneratorHelper.cs:line 54
   at Microsoft.Research.Zen.Generation.GeneratorHelper.ApplyToObject(Func`2 recurse, Type objectType, Dictionary`2 fields) in C:\Users\de\Source\Repos\Zen\Zen\Generation\GeneratorHelper.cs:line 91
   at Microsoft.Research.Zen.Generation.SymbolicInputGenerator.VisitObject(Func`2 recurse, Type objectType, Dictionary`2 fields) in C:\Users\de\Source\Repos\Zen\Zen\Generation\SymbolicInputGenerator.cs:line 109
   at Microsoft.Research.Zen.ReflectionUtilities.ApplyTypeVisitor[T](ITypeVisitor`1 visitor, Type type) in C:\Users\de\Source\Repos\Zen\Zen\ReflectionUtilities.cs:line 341
   at Microsoft.Research.Zen.Language.Arbitrary[T](Int32 listSize, Boolean checkSmallerLists) in C:\Users\de\Source\Repos\Zen\Zen\Language.cs:line 125
   at Microsoft.Research.Zen.ZenFunction`2.Find(Func`3 invariant, Zen`1 input, Int32 listSize, Boolean checkSmallerLists, Boolean simplify, Backend backend) in C:\Users\de\Source\Repos\Zen\Zen\ZenFunction.cs:line 158
   at BrentEq.Program.Main(String[] args) in C:\Users\de\Source\Repos\Zen\BrentEq\Program.cs:line 24

When I remove field Matrix3x3.v33, the program appears to work as expected.

Limit Solve() duration

Would it be possible to add a CancellationToken (or a timeout) to the Solve() method, to allow the callers to control how much time he's willing to wait?

Something along the line of:

CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var solution = Zen.And(constraints).Solve(cancellationToken: cts.Token);

or

var solution = Zen.And(constraints).Solve(timeout: TimeSpan.FromSeconds(10));

Such a mechanism will allow callers to search for a solution up to a certain amount of time, and if not found, try again with different constraints.
Using a CancellationToken will also allow callers to cancel the execution, to avoid doing needless work.

What appears to be a bug of comparison operators in Zen

Hi, I have developed a data plane verification software using Zen and found what appears to be a bug of comparison operators in Zen.

The following comparison operation will be false in Zen, but true in C#.

Zen<ulong> a = 0xffffffffffffffff; 
Zen<ulong> b = 0x1000000000000000;
// false
Console.WriteLine(a > b);

ulong c = 0xffffffffffffffff;
ulong d = 0x1000000000000000;
// true
Console.WriteLine(c > d);

Could you check it ?

Thanks.

FSeq question

Hello,

While trying to find a way to specify sequences like "the value of the element is the index+1" or "the value of the element is the sum of the 2 previous elements", I've encountered the below behavior, where a solution will be found for sequence len=5, but not for len=6:

int len = 5; // 5 will succeed with solution {1, 2, 0, 0, 0}, but 6 will not find solutions?
var l = Zen.Symbolic<FSeq<byte>>();
var idx = Zen.Symbolic<BigInteger>();
var sol = And(
  l.Length() == (BigInteger)len,
  l.At(idx) == Option.Some<byte>(1),
  l.At(idx + new BigInteger(1)) == Option.Some<byte>(2)).Solve(Solver.SolverType.Z3);

I assume I must be doing something wrong, or that there must be some parameter like search depth/iterations, that needs adjusting to make this work?

Also, if you have hints for implementing the above mentioned sequences, it will be greatly appreciated ;-)

Best regards,
Andrzej

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.