-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathloccliff.cpp
More file actions
156 lines (139 loc) · 4.81 KB
/
loccliff.cpp
File metadata and controls
156 lines (139 loc) · 4.81 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// loccliff.cpp
// version v0.10, of 2004-10-28
// Copyright (C) 2004 Simon Anders <sanders@fs.tum.de>
// Institute of Theoretical Physics, University of Innsbruck, Austria
// ----------
// This file is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this file; see the file COPYING. If not, browse to
// http://www.fsf.org/licenses/gpl.html
// ----------
#include "loccliff.h"
#include <iostream>
using namespace std;
string LocCliffOp::get_name (void) const
{
static const char* paulinames[] = {"I", "X", "Y", "Z"};
return string (paulinames[op & 0x03]) + (char) ('A' + op / 4);
}
RightPhase LocCliffOp::conjugate (const LocCliffOp trans) {
//If *this is the identity, we don't have to do anything
if (*this == lco_Id) {
return RightPhase (0);
}
//This is meant to be used only if *this is a Pauli:
assert (op >= lco_X.op && op <= lco_Z.op);
// First the sign:
RightPhase zeta;
if ((trans.op & 0x03) == 0 || (trans.op & 0x03) == op) {
// zeta = + sgn pi
// sgn pi = -1 iff trans.op >= 4 && trans.op <= 15
if (trans.op >= 4 && trans.op <= 15) {
zeta = RightPhase (2);
} else {
zeta = RightPhase (0);
}
} else {
// zeta = - sgn pi
// sgn pi = -1 iff trans.op >= 4 && trans.op <= 15
if (trans.op >= 4 && trans.op <= 15) {
zeta = RightPhase (0);
} else {
zeta = RightPhase (2);
}
}
// Now the operator:
// First check the table (to be removed!):
assert (loccliff_tables::meas_conj_tbl [op-lco_X.op] [trans.op]
== trans * op * trans.herm_adjoint());
op = loccliff_tables::meas_conj_tbl [op-lco_X.op] [trans.op];
return zeta;
}
RightMatrix LocCliffOp::get_matrix (void) const
{
const short matrices[24][2][2] =
{{{0, -1}, {-1, 0}}, {{-1, 0}, {0, -1}}, {{-1, 3}, {1, -1}}, {{0, -1}, {-1,
2}}, {{-1, 0}, {3, -1}}, {{0, -1}, {-1, 3}}, {{0, -1}, {-1, 1}}, {{-1,
0}, {1, -1}}, {{0, 2}, {2, 2}}, {{0, 2}, {0, 0}}, {{0, 0}, {0, 2}}, {{0,
0}, {2, 0}}, {{0, 1}, {3, 2}}, {{0, 3}, {1, 2}}, {{0, 1}, {1, 0}}, {{0,
3}, {3, 0}}, {{0, 3}, {0, 1}}, {{0, 1}, {2, 1}}, {{0, 3}, {2, 3}}, {{0,
1}, {0, 3}}, {{0, 0}, {1, 3}}, {{0, 0}, {3, 1}}, {{0, 2}, {3, 3}}, {{0,
2}, {1, 1}}};
RightMatrix rm;
rm.sqrt2norm = true;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
if (matrices[op][i][j] == -1) {
rm.ampls[i][j] = false;
rm.sqrt2norm = false;
rm.phases[i][j] = RightPhase (0);
} else {
rm.ampls[i][j] = true;
rm.phases[i][j] = RightPhase (matrices[op][i][j]);
}
}
}
return rm;
}
string RightPhase::get_name (void) const
{
const char* names[] = {" ", " i", " -", "-i"};
return string (names[ph & 0x03]);
}
bool RightMatrix::apply_on_state (vector<bool>::reference ampl1,
vector<bool>::reference ampl2, RightPhase& ph1, RightPhase& ph2)
{
vector<bool>::reference amplV[2] = {ampl1, ampl2};
RightPhase *phV[2] = {&ph1, &ph2};
RightMatrix sum;
bool diag[2] = {false, false};
for (int r = 0; r < 2; r++) {
for (int c = 0; c < 2; c++) {
sum.ampls[r][c] = ampls[r][c] && amplV[c];
sum.phases[r][c] = phases[r][c] + *phV[c];
}
}
for (int r = 0; r < 2; r++) {
amplV[r] = sum.ampls[r][0] || sum.ampls[r][1];
if (!amplV[r]) {
continue;
}
if (! (sum.ampls[r][0] && sum.ampls[r][1])) {
// not both ampls present -> just copy from one
*phV[r] = sum.phases[r][sum.ampls[r][0] ? 0: 1];
} else {
// both ampls present. We have to add them
switch ((sum.phases[r][1].ph - sum.phases[r][0].ph + 4) % 4) {
case 0:
// They are the same. Take one:
*phV[r] = sum.phases[r][0];
break;
case 2:
// They cancel
amplV[r] = false;
break;
case 1:
*phV[r] = sum.phases[r][0];
diag[r] = true;
break;
case 3:
*phV[r] = sum.phases[r][1];
diag[r] = true;
break;
default: assert (0);
}
}
}
if (amplV[0] && amplV[1]) {
assert (diag[0] == diag[1]);
}
assert (amplV[0] || amplV[1]);
return amplV[0] ? diag[0] : diag[1];
}