forked from shaimach/Dynamo
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_rand_problem.m
More file actions
146 lines (111 loc) · 2.93 KB
/
test_rand_problem.m
File metadata and controls
146 lines (111 loc) · 2.93 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
function dyn = test_rand_problem(task, dim, n_controls)
% Generates a Dynamo instance corresponding to a random optimization problem.
%
% dyn = test_rand_problem(task, dim, n_controls)
% Ville Bergholm 2015
% S dimension
d = dim(1);
% SE total dimension
dSE = prod(dim);
switch task
case {'closed ket', 'closed ket phase'}
% pure state transfer
ini = rand_ket(d);
fin = rand_ket(d);
case 'closed state'
% mixed state transfer
ini = rand_positive(d);
fin = rand_positive(d);
case {'closed gate', 'closed gate phase'}
% unitary gate
ini = eye(d);
fin = rand_U(d);
case 'closed state_partial'
% mixed state transfer on SE, only S matters
ini = rand_positive(dSE);
fin = rand_positive(d);
case 'closed gate_partial'
% unitary gate on SE, only S matters
ini = eye(dSE);
fin = rand_U(d);
case {'open state', 'open state overlap'}
% mixed state transfer
ini = rand_positive(d);
fin = rand_ket(d);
case 'open gate'
% unitary gate
ini = eye(d);
fin = rand_U(d);
case 'open state_partial'
% mixed state transfer on SE, only S matters
ini = rand_positive(dSE);
fin = rand_positive(d);
case 'open gate_partial'
% TODO
error('not finished')
case 'abstract vector'
ini = rand_complex([d,1]);
fin = rand_complex([d,1]);
case 'abstract matrix'
ini = rand_complex(d);
fin = rand_complex(d);
otherwise
error('Unknown task.')
end
H_ctrl = cell(1, n_controls);
switch strtok(task)
case 'abstract'
% abstract linear evolution
H_drift = rand_complex(dSE);
for k=1:n_controls
H_ctrl{k} = rand_complex(dSE);
c_labels{k} = sprintf('C%d', k);
end
case 'closed'
% Hamiltonian evolution
H_drift = rand_hermitian(dSE);
for k=1:n_controls
H_ctrl{k} = rand_hermitian(dSE);
c_labels{k} = sprintf('H%d', k);
end
case 'open'
% Markovian quantum evolution
H_drift = rand_hermitian(dSE);
% Lindblad generators
for k=1:4
A{k} = rand_complex(dSE) * 0.1;
end
H_drift = superop_lindblad(A, H_drift);
for k=1:n_controls
H_ctrl{k} = rand_hermitian(dSE);
c_labels{k} = sprintf('H%d', k);
end
otherwise
error('Unknown case.')
end
% control limits
%control_type = 'mm';
%temp = [-1,2] * 10;
%control_par = {temp, temp};
%% Set up Dynamo
desc = task;
T = 3;
n_bins = 100;
dyn = dynamo(task, ini, fin, H_drift, H_ctrl);
dyn.system.set_labels(desc, dim, c_labels);
dyn.seq_init(n_bins, T * [0.5, 1.5]); %, control_type, control_par);
% random, constant initial controls
dyn.set_controls(0.1 * randn(1, n_controls));
%dyn.ui_open();
%dyn.search(dyn.full_mask(false));
end
function ket = rand_ket(dim)
% Returns a random Haar-distributed ket vector.
ket = zeros(dim, 1);
ket(1) = 1;
ket = rand_U(dim) * ket;
end
function ret = rand_complex(size)
% Returns a random complex matrix.
ret = randn(size) +1i*randn(size);
end