forked from shaimach/Dynamo
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.m
100 lines (75 loc) · 1.87 KB
/
test.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
function test(d)
% Unit tests for DYNAMO.
%
% d is a Dynamo instance containing the optimization problem used.
% If no d is given, uses one of the test suite problems.
% Ville Bergholm 2015-2016
% tolerance for numerical errors
tol = 1e-10;
if nargin < 1
d = test_suite(1);
end
n_timeslots = d.seq.n_timeslots();
X = d.X();
temp = d.seq.tau;
%% export, then import a sequence
in_polar = false;
% no TU defined, do not try to use it
[A, desc] = d.export(in_polar, false);
desc
d.import(A, in_polar);
assert_equal(d.seq.tau, temp, tol);
assert_equal(d.X(), X, tol);
d.system.set_TU(1e-3);
% TU defined, get rid of it
[A, desc] = d.export(in_polar, false);
desc
d.import(A, in_polar);
assert_equal(d.seq.tau, temp, tol);
assert_equal(d.X(), X, tol);
% TU defined, keep it
[A, desc] = d.export(in_polar, true);
desc
d.import(A, in_polar, 1e-3);
assert_equal(d.seq.tau, temp, tol);
assert_equal(d.X(), X, tol);
%% split some random bins, this must not change the effect of the sequence
bins = find(rand(1, n_timeslots) < 0.5);
n = randi([2, 5]);
d.split(bins, n);
assert_equal(d.X(), X, tol);
disp('All unit tests passed.')
%% test all the tasks
if 1
disp('Now testing all the optimization tasks.');
pause
demo_tasks('abstract vector')
demo_tasks('abstract matrix')
demo_tasks('closed ket')
demo_tasks('closed ket phase')
demo_tasks('closed state')
demo_tasks('closed gate')
demo_tasks('closed gate phase')
%demo_tasks('closed state_partial')
demo_tasks('closed gate_partial')
demo_tasks('open state')
demo_tasks('open state overlap')
demo_tasks('open gate')
demo_tasks('open state_partial')
%demo_tasks('open gate_partial')
end
%% test all the demos
if 1
disp('Now running all the demos.');
pause
demo_coop_gates()
demo_ensemble()
demo_fmo()
demo_resonance()
demo_tau()
end
end
function assert_equal(a, b, tol)
% Are a and b equal up to tolerance tol?
assert(norm(a-b) <= tol);
end