-
Notifications
You must be signed in to change notification settings - Fork 1
/
circuitanalysis.js
134 lines (113 loc) · 3.61 KB
/
circuitanalysis.js
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var analysisChart = null;
function resetAnalysisData(analysisData)
{
analysisData["steps"] = [];
analysisData["counts"] = [];
analysisData.nrTGates = 0;
analysisData.timesteps = 0;
}
function returnAnalysisAsCSV(steps, nra, analysis)
{
var ret = "step,#A,Look#A\n";
if(steps != undefined && nra != undefined && analysis != undefined) {
for (var i = 0; i < steps.length; i++) {
var line = i + ",";
if (i < nra.length)
line += nra[i] + ",";
else
line += ",";
if (i < analysis.length)
line += analysis[i];
ret += line + "\n";
}
}
return ret;
}
function chartAnalysisData(steps, nra, analysis)
{
if(analysisChart != null) {
analysisChart.destroy();
}
var ctx = document.getElementById("analysisChart").getContext('2d');
analysisChart = new Chart(ctx, {
type: 'line',
data: {
labels: steps,//aStatesData["steps"].slice(0, distillationDepth),
datasets: [
{
label: '# A states',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: nra,
borderWidth: 1,
fill:false,
lineTension: 0
},
{
label: 'Lookahead # A states',
backgroundColor: 'rgb(99, 255, 132)',
borderColor: 'rgb(99, 255, 132)',
data: analysis,
borderWidth: 1,
fill:false,
lineTension: 0
}],
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
integerSteps: true
}
}]
}
}
});
}
/*
Takes a scheduled circuit as input
and not a gate list with relative time delta
*/
function analyseCircuit(schedGateList, windowLength)
{
var analysisData = {};
resetAnalysisData(analysisData);
var accumulator = new Array();
//first three are file header
for(var i=3; i<schedGateList.length; i++)
{
var parsedGate = ScheduledGate.parseScheduledGateString(schedGateList[i]);
if(parsedGate.isComment)
continue;
//continuous update
analysisData.timesteps = Math.max(analysisData.timesteps, parsedGate.timeStep + 1);
while(parsedGate.timeStep >= accumulator.length)
accumulator.push(0);
if(parsedGate.gateType[0] == 't' || parsedGate.gateType[0] == 'a')
{
analysisData.nrTGates += parsedGate.wires.length;
accumulator[parsedGate.timeStep] += parsedGate.wires.length;
}
}
var countAtWindowStart = new Array();
for(var i=0; i<accumulator.length; i++)
{
countAtWindowStart.push (accumulator[i]);
if(i >= windowLength)
{
analysisData["steps"].push(analysisData["counts"].length);
var total = countAtWindowStart.reduce(function(a, b) { return a + b; }, 0);
analysisData["counts"].push(total);
countAtWindowStart.shift();
}
}
while(countAtWindowStart.length > 0)
{
analysisData["steps"].push(analysisData["counts"].length);
var total = countAtWindowStart.reduce(function(a, b) { return a + b; }, 0);
analysisData["counts"].push(total);
countAtWindowStart.shift();
}
return analysisData;
}