Grover/Driver.cs
2019-05-20 00:01:16 +02:00

57 lines
1.6 KiB
C#

using System;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kadet.Quantum.Tests;
namespace Kadet.Quantum
{
class Driver
{
delegate T QuantumTest<T>(IOperationFactory simulator);
static string Ket(string thing) {
return $"|{thing}⟩";
}
static void Main(string[] args)
{
var results = new Dictionary<(bool, bool), long>();
var rand = new Random();
var rsim = new ResourcesEstimator();
using (var qsim = new QuantumSimulator())
{
Console.Write("Search QuantumDB: ");
long index = int.Parse(Console.ReadLine());
long[] database = {
7, 44, 24, 2, 55, 35, 53, 4,
17, 3, 58, 21, 15, 28, 50, 19
};
QuantumTest<long> solve =
sim => TestDatabaseSearch.Run(sim, new QArray<long>(database), index).Result;
var result = Enumerable
.Range(1, 100)
.Select(x => solve(qsim))
.OrderBy(x => x)
.GroupBy(x => $"{x}");
foreach (var group in result) {
Console.WriteLine($"{Ket(group.Key.ToString())} ({group.Count()})");
}
solve(rsim);
Console.WriteLine();
Console.WriteLine("Resources usage:");
Console.WriteLine(rsim.ToTSV());
}
}
}
}