-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdecomposition.cpp
68 lines (60 loc) · 1.22 KB
/
decomposition.cpp
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
#include <stdio.h>
#include "decomposition.h"
/**
* Counts the CNOTs if this is a non-ICM decomposition, e.g. the Toffoli.
* It is assumed that in a correct decomposition, a single CNOT per decomposition
* column appears. A CNOT is allowed to have multiple targets, and
* as a result on a column will be at most one control.
* Therefore, the number of controls is counted.
*/
int decomposition::getNumberOfCnots()
{
if(type == DecompType::icm || type == DecompType::disticm)
return cnots.size();
int height = gates.size();
int length = gates.at(0).size();
int nrcnots = 0;
for(int i=0; i<height; i++)
{
for(int j=0; j<length; j++)
{
if(gates[i][j] == CTRL)
{
nrcnots++;
}
}
}
return nrcnots;
}
void decomposition::toString()
{
printf("name: %s\n", name.c_str());
}
size_t decomposition::getMaxCols()
{
size_t max = 0;
if(!isicm())
{
for(size_t i=0; i < gates.size(); i++)
{
if (max < gates[i].size())
{
max = gates[i].size();
}
}
}
else
{
max = cnots.size();
max++;//the measurements
}
return max;
}
bool decomposition::isicm()
{
return (type == DecompType::icm) || (type == DecompType::disticm);
}
bool decomposition::isdist()
{
return type == DecompType::disticm;
}