This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Driver.cs
99 lines (85 loc) · 4.06 KB
/
Driver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace Final_Project
{
class Driver
{
Driver() {
}
static void Main(string[] args)
{
List<List<Int64>> data = load_csv("data_2d_binom_2q.txt");
long[] distances = get_distances(data);
int n = (int) Math.Ceiling(Math.Log(data.Count, 2));
int m = (int) Math.Ceiling(Math.Log(distances.Max(), 2));
using (var qsim = new QuantumSimulator())
{
long[] indices = new long[data.Count];
for (int i = 0; i < data.Count; i++) {
indices[i] = i;
}
// DEMO - Divisive Clustering
// QArray<long> result = divisive_clust.Run(qsim, 4, 5, new QArray<long>(indices), new QArray<long>(distances)).Result;
// Console.WriteLine("Result:");
// Console.Write("[");
// Console.Write(String.Join(", ", result));
// Console.WriteLine("]");
// DEMO - Outlier Detection
QArray<long> result = quantum_detection_outlier.Run(qsim, 2, 5, new QArray<long>(indices), 2, 3, new QArray<long>(distances)).Result;
Console.WriteLine("Result:");
Console.Write("[");
Console.Write(String.Join(", ", result));
Console.WriteLine("]");
// DEMO - Adder Compare etc.
// tests.Run(qsim).Wait();
// Resource Estimator - Backend
// ResourcesEstimator estimator = new ResourcesEstimator();
// tests.Run(estimator).Wait();
// var estimator_data = estimator.Data;
// Console.WriteLine($"QubitCliffords: {estimator_data.Rows.Find("QubitClifford")["Sum"]}");
// Console.WriteLine($"Ts: {estimator_data.Rows.Find("T")["Sum"]}");
// Console.WriteLine($"CNOTs: {estimator_data.Rows.Find("CNOT")["Sum"]}");
// Resource Estimator - Div. Clust. - Taking too long will not finish
// ResourcesEstimator estimator = new ResourcesEstimator();
// QArray<long> result = divisive_clust.Run(estimator, 4, 5, new QArray<long>(indices), new QArray<long>(distances)).Result;
// var estimator_data = estimator.Data;
// Console.WriteLine($"QubitCliffords: {estimator_data.Rows.Find("QubitClifford")["Sum"]}");
// Console.WriteLine($"Ts: {estimator_data.Rows.Find("T")["Sum"]}");
// Console.WriteLine($"CNOTs: {estimator_data.Rows.Find("CNOT")["Sum"]}");
}
}
/// <summary> Method <c>load_csv</c>
/// loads a csv file given path to the file,
/// and stores it in class.</summary>
static List<List<Int64>> load_csv(string file_path) {
List<List<Int64>> data = new List<List<Int64>>();
using(var reader = new StreamReader(file_path))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
data.Add(Array.ConvertAll(values, Int64.Parse).ToList());
}
}
return data;
}
static Int64[] get_distances(List<List<Int64>> arr) {
long[] result = new long[arr.Count * arr.Count];
for(int i = 0; i < arr.Count; i++) {
for(int j = 0; j < arr.Count; j++) {
long dist = 0;
for(int idx = 0; idx < arr[i].Count; idx++) {
dist += (arr[i][idx] - arr[j][idx]) * (arr[i][idx] - arr[j][idx]);
}
result[arr.Count * i + j] = (long) Math.Sqrt(dist);
}
}
return result;
}
}
}