-
Notifications
You must be signed in to change notification settings - Fork 9
/
logical_cliff_ops.m
189 lines (164 loc) · 6.42 KB
/
logical_cliff_ops.m
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
%% Code to get logical Clifford operators for any stabilizer code
% Examples (where it takes only a short time to enumerate all solutions):
% The [[6,4,2]] CSS code and the [[5,1,3]] perfect code.
% In each cell array produced as output, the first column will contain a
% symplectic solution, the corresponding second column will contain a
% circuit for that solution, and the third column gives the circuit depth.
% For details, please see the paper
% "Synthesis of Logical Clifford Operators via Symplectic Geometry",
% available at https://arxiv.org/abs/1803.06987
% Code: https://github.com/nrenga/symplectic-arxiv18a
% Author: Narayanan Rengaswamy, Date: Mar. 3, 2018
clc
clear
close all
tic;
m = 6;
k = 2; % implies 2^(k*(k+1)/2) solutions for a logical Clifford circuit!
% Stabilizers
S = [ 1 1 1 1 1 1, 0 0 0 0 0 0 ;
0 0 0 0 0 0, 1 1 1 1 1 1 ];
% Logical Paulis
Xbar = [ 1 1 0 0 0 0, 0 0 0 0 0 0 ;
1 0 1 0 0 0, 0 0 0 0 0 0 ;
1 0 0 1 0 0, 0 0 0 0 0 0 ;
1 0 0 0 1 0, 0 0 0 0 0 0 ];
Zbar = [ 0 0 0 0 0 0, 0 1 0 0 0 1 ;
0 0 0 0 0 0, 0 0 1 0 0 1 ;
0 0 0 0 0 0, 0 0 0 1 0 1 ;
0 0 0 0 0 0, 0 0 0 0 1 1 ];
Snorm1 = [ 1 1 1 1 1 1, 0 0 0 0 0 0 ;
0 0 0 0 0 0, 1 1 1 1 1 1 ];
Snorm2 = [ 1 1 1 1 1 1, 0 0 0 0 0 0 ;
1 1 1 1 1 1, 1 1 1 1 1 1 ];
Snorm3 = [ 0 0 0 0 0 0, 1 1 1 1 1 1 ;
1 1 1 1 1 1, 0 0 0 0 0 0 ];
Snorm4 = [ 0 0 0 0 0 0, 1 1 1 1 1 1 ;
1 1 1 1 1 1, 1 1 1 1 1 1 ];
Snorm5 = [ 1 1 1 1 1 1, 1 1 1 1 1 1 ;
1 1 1 1 1 1, 0 0 0 0 0 0 ];
Snorm6 = [ 1 1 1 1 1 1, 1 1 1 1 1 1 ;
0 0 0 0 0 0, 1 1 1 1 1 1 ];
% Phase gate on logical qubit 1
F_all_P1 = find_logical_cliff(S, Xbar, Zbar, {'P', 1}, [], 'all');
% Find cheapest circuit in terms of circuit depth
[P1depth, P1cheap_ind] = min(cellfun(@(a) a(1,1), F_all_P1(:,3)));
F_P1 = F_all_P1(P1cheap_ind, :);
% Controlled-Z gate on logical qubits (1,2)
F_all_CZ12 = find_logical_cliff(S, Xbar, Zbar, {'CZ', [1 2]}, Snorm3, 'all');
% Find cheapest circuit
[CZ12depth, CZ12cheap_ind] = min(cellfun(@(a) a(1,1), F_all_CZ12(:,3)));
F_CZ12 = F_all_CZ12(CZ12cheap_ind, :);
% % CNOT gate where logical qubit 2 controls 1
% F_all_CNOT21 = find_logical_cliff(S, Xbar, Zbar, {'CNOT', [2 1]}, Snorm1, 'all');
% % Find cheapest circuit
% [CNOT21depth, CNOT21cheap_ind] = min(cellfun(@(a) a(1,1), F_all_CNOT21(:,3)));
% F_CNOT21 = F_all_CNOT21(CNOT21cheap_ind, :);
%
% % Targeted Hadamard gate on logical qubit 1
% % Snorm = [S(1,:) + S(2,:); S(2,:)];
% % Snorm = S;
% F_all_H1 = find_logical_cliff(S, Xbar, Zbar, {'H', 1}, Snorm1, 'all');
% % Find cheapest circuit
% [H1depth, H1cheap_ind] = min(cellfun(@(a) a(1,1), F_all_H1(:,3)));
% F_H1 = F_all_H1(H1cheap_ind, :);
%
% % Transversal Hadamard gate
% % Snorm = [S(2,:); S(1,:)];
% F_all_Htrans = find_logical_cliff(S, Xbar, Zbar, {'H', 1:4}, Snorm3, 'all');
% % Find cheapest circuit
% [Htransdepth, Htranscheap_ind] = min(cellfun(@(a) a(1,1), F_all_Htrans(:,3)));
% F_Htran = F_all_Htrans(Htranscheap_ind, :);
%
% % Logical Clifford circuit
% Snorm = S;
% % Snorm = [S(1,:) + S(2,:); S(2,:)];
% % Snorm = [S(2,:); S(1,:)];
% ckt1 = {'P', 2; 'CNOT', [1 3]; 'CZ', [3 4]};
% F_all_ckt1 = find_logical_cliff(S, Xbar, Zbar, ckt1, Snorm, 'all');
% % Find cheapest circuit
% [ckt1depth, ckt1cheap_ind] = min(cellfun(@(a) a(1,1), F_all_ckt1(:,3)));
% F_ckt1 = F_all_Htrans(ckt1cheap_ind, :);
toc;
%% Code to get logical Clifford operators for the [[5,1,3]] perfect code
% clc
% clear
% close all
% tic;
% m = 5;
% k = 4; % implies 2^(k*(k+1)/2) solutions for a logical Clifford circuit!
%
% % Stabilizers
% S = [ 1 0 0 1 0 , 0 1 1 0 0 ;
% 0 1 0 0 1 , 0 0 1 1 0 ;
% 1 0 1 0 0 , 0 0 0 1 1 ;
% 0 1 0 1 0 , 1 0 0 0 1 ];
%
% % Logical Paulis
% Zbar = [ 0 0 0 0 0 , 1 1 1 1 1 ];
% Xbar = [ 1 1 1 1 1 , 0 0 0 0 0 ];
%
% % Phase gate on the logical qubit
% F_all_P = find_logical_cliff(S, Xbar, Zbar, {'P', 1}, [], 'all');
% % Find cheapest circuit
% [Pdepth, Pcheap_ind] = min(cellfun(@(a) a(1,1), F_all_P(:,3)));
% F_P = F_all_P(Pcheap_ind, :);
%
% % Hadamard gate on the logical qubit
% F_all_H = find_logical_cliff(S, Xbar, Zbar, {'H', 1}, [], 'all');
% % Find cheapest circuit
% [Hdepth, Hcheap_ind] = min(cellfun(@(a) a(1,1), F_all_H(:,3)));
% F_H = F_all_H(Hcheap_ind, :);
% toc;
%% The [[9,1,3]] Shor Code
% clc
% clear
% close all
%
% m = 9;
% k = 8; % implies 2^(k*(k+1)/2) solutions for a logical Clifford circuit!
%
% S = [1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0;
% 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0;
% 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0;
% 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0;
% 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0;
% 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0;
% 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0;
% 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1];
%
% Xbar = [zeros(1,9), 1 0 0 1 0 0 1 0 0];
% Zbar = [1 1 1 0 0 0 0 0 0, zeros(1,9)];
%
% % Find one solution for logical Hadamard; it isn't optimal in any way
% Hbar = find_logical_cliff(S, Xbar, Zbar, {'H', 1}, [], 1);
%% The [[15,7,3]] Hamming code
% clc
% clear
% close all
%
% m = 15;
% k = 8; % implies 2^(k*(k+1)/2) solutions for a logical Clifford circuit!
%
% % Parity-check matrix for the [15,11,3] binary Hamming code
% H = de2bi((1:15)',4,'left-msb')';
% S = [ H, zeros(4,m);
% zeros(4,m), H ];
%
% L = [ 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 ;...
% 1 1 0 0 1 0 0 0 0 1 0 1 0 0 0 ;...
% 1 1 0 0 0 1 0 0 0 0 1 0 0 1 0 ;...
% 1 1 0 0 0 0 1 0 1 0 0 0 1 0 0 ;...
% 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 ;...
% 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 ;...
% 1 0 0 0 0 0 0 1 0 1 0 0 1 1 0 ]; % Logical Xs and Zs for [[15,7,3]]
%
% Xbar = [ L, zeros(7,m) ];
% Zbar = [ zeros(7,m), L ];
%
% Snorm = S;
% ckt1 = {'Permute', [2 3 1 4:7]};
% F_all_ckt1 = find_logical_cliff(S, Xbar, Zbar, ckt1, Snorm, 1);
% % Find cheapest circuit
% % [ckt1depth, ckt1cheap_ind] = min(cellfun(@(a) a(1,1), F_all_ckt1(:,3)));
% % F_ckt1 = F_all_Htrans(ckt1cheap_ind, :);