-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
636 lines (537 loc) · 26.2 KB
/
test.py
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
"""Tests of basic functionality"""
from os.path import join
from textwrap import dedent
from copy import copy
from collections import OrderedDict
import numpy as np
import sympy
import scipy
from sympy import Symbol
import QDYN
from QDYN.pulse import blackman
from qnet.algebra.hilbert_space_algebra import LocalSpace, ProductSpace
import pytest
from src.shwrapper_v1 import qdyn_check_config
import src.qdyn_model_v1 as qdyn_model
import src.single_sided_network_v1 as single_sided_network
import src.crossed_cavity_network_v1 as crossed_cavity_network
from src.dicke_half_model_v1 import (
pi_pulse, zero_pulse, write_dicke_half_model)
from src.dicke_half_model_v2 import (
write_dicke_half_model as write_dicke_half_model_v2)
@pytest.fixture
def num_vals_no_fb():
Delta = 5000.0 # MHz
g = 50.0 # MHz
kappa = 0.5 # MHz
num_vals = {
Symbol('Delta_1', real=True): Delta,
Symbol('Delta_2', real=True): Delta,
Symbol('g_2', positive=True): g,
Symbol('g_1', positive=True): g,
Symbol('kappa', positive=True): kappa,
}
return num_vals
@pytest.fixture
def controls_no_fb():
t0 = -4 # microsec
T = 4 # microsec
nt = 2001
E0 = 70.0 # MHz
tgrid = QDYN.pulse.pulse_tgrid(t0=t0, T=T, nt=nt) # microsec
p = QDYN.pulse.Pulse(
tgrid, amplitude=(E0 * blackman(tgrid, t0, T)),
time_unit='microsec', ampl_unit='MHz')
controls = OrderedDict([
(Symbol('Omega_1'), p.copy()),
(Symbol('Omega_2'), p.copy()),
])
return controls
@pytest.fixture
def model_no_fb(num_vals_no_fb, controls_no_fb):
num_vals = num_vals_no_fb
controls = controls_no_fb
slh = single_sided_network.network_slh(
n_cavity=5, n_nodes=2, topology='open')
model = qdyn_model.make_qdyn_model(
slh, num_vals, controls, energy_unit='MHz',
mcwf=False, non_herm=False, states=None)
return model
@pytest.fixture
def model_no_fb_oct_fw(num_vals_no_fb, controls_no_fb):
num_vals = num_vals_no_fb
controls = controls_no_fb
slh = single_sided_network.network_slh(
n_cavity=5, n_nodes=2, topology='open')
model = qdyn_model.make_qdyn_oct_model(
slh, num_vals, controls, energy_unit='MHz',
mcwf=False, non_herm=False, oct_target='excitation_transfer_fw')
return model
@pytest.fixture
def model_no_fb_oct_gate(num_vals_no_fb, controls_no_fb):
num_vals = num_vals_no_fb
controls = controls_no_fb
slh = single_sided_network.network_slh(
n_cavity=5, n_nodes=2, topology='open')
model = qdyn_model.make_qdyn_oct_model(
slh, num_vals, controls, energy_unit='MHz',
mcwf=False, non_herm=False, oct_target='gate')
return model
def test_no_feedback_system(model_no_fb, tmpdir):
model = copy(model_no_fb)
model.write_to_runfolder(str(tmpdir))
config = tmpdir.join('config').read().strip()
expected = dedent(r'''
tgrid: t_start = -4_microsec, t_stop = 4_microsec, nt = 2001
prop: method = newton, use_mcwf = F
pulse: type = file, time_unit = microsec, ampl_unit = MHz, is_complex = F
* id = 1, filename = pulse1.dat
* id = 2, filename = pulse2.dat
ham: type = matrix, real_op = F, n_surf = 100, sparsity_model = indexed
* filename = H0.dat, op_unit = MHz, op_type = potential
* filename = H1.dat, op_unit = dimensionless, op_type = dipole, pulse_id = 1
* filename = H2.dat, op_unit = dimensionless, op_type = dipole, pulse_id = 2
dissipator:
* type = dissipator, filename = D1.dat, real_op = F, op_unit = MHz, &
sparsity_model = indexed
observables: type = matrix, real_op = F, op_type = pot, n_surf = 100, &
time_unit = microsec
* filename = O1.dat, sparsity_model = indexed, outfile = darkstate_cond.dat, &
exp_unit = MHz, is_real = T, column_label = <L^+L>, op_unit = MHz
* filename = O2.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(00), &
op_unit = dimensionless
* filename = O3.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(01), &
op_unit = dimensionless
* filename = O4.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(10), &
op_unit = dimensionless
* filename = O5.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(11), &
op_unit = dimensionless
* filename = O6.dat, sparsity_model = indexed, outfile = 10_01_coherence.dat, &
exp_unit = dimensionless, is_real = F, column_label = |10><01|, &
op_unit = dimensionless
* filename = O7.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = q1, &
op_unit = dimensionless
* filename = O8.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = c1, &
op_unit = dimensionless
* filename = O9.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = q2, &
op_unit = dimensionless
* filename = O10.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = c2, &
op_unit = dimensionless
user_strings: time_unit = microsec, write_jump_record = jump_record.dat, &
write_final_state = psi_final.dat
''').strip()
assert config == expected
p = qdyn_check_config(str(tmpdir.join('config')))
p.wait()
out = p.stdout.read()
assert 'Successfully read config file' in out
def test_no_feedback_oct_fw_system(model_no_fb_oct_fw, tmpdir):
model = copy(model_no_fb_oct_fw)
model.write_to_runfolder(str(tmpdir))
config = tmpdir.join('config').read().strip()
expected = dedent(r'''
tgrid: t_start = -4_microsec, t_stop = 4_microsec, nt = 2001
prop: method = newton, use_mcwf = F
pulse: type = file, time_unit = microsec, ampl_unit = MHz, is_complex = F, &
oct_shape = flattop, shape_t_start = -4_microsec, shape_t_stop = 4_microsec, &
t_rise = 0.8_microsec, t_fall = 0.8_microsec, oct_lambda_a = 1e-05, &
oct_increase_factor = 5, oct_pulse_max = 699.999_MHz, &
oct_pulse_min = -699.999_MHz
* id = 1, filename = pulse1.dat, oct_outfile = pulse1.oct.dat
* id = 2, filename = pulse2.dat, oct_outfile = pulse2.oct.dat
ham: type = matrix, real_op = F, n_surf = 100, sparsity_model = indexed
* filename = H0.dat, op_unit = MHz, op_type = potential
* filename = H1.dat, op_unit = dimensionless, op_type = dipole, pulse_id = 1
* filename = H2.dat, op_unit = dimensionless, op_type = dipole, pulse_id = 2
dissipator:
* type = dissipator, filename = D1.dat, real_op = F, op_unit = MHz, &
sparsity_model = indexed
observables: type = matrix, real_op = F, op_type = pot, n_surf = 100, &
time_unit = microsec
* filename = O1.dat, sparsity_model = indexed, outfile = darkstate_cond.dat, &
exp_unit = MHz, is_real = T, column_label = <L^+L>, op_unit = MHz
* filename = O2.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(00), &
op_unit = dimensionless
* filename = O3.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(01), &
op_unit = dimensionless
* filename = O4.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(10), &
op_unit = dimensionless
* filename = O5.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(11), &
op_unit = dimensionless
* filename = O6.dat, sparsity_model = indexed, outfile = 10_01_coherence.dat, &
exp_unit = dimensionless, is_real = F, column_label = |10><01|, &
op_unit = dimensionless
* filename = O7.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = q1, &
op_unit = dimensionless
* filename = O8.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = c1, &
op_unit = dimensionless
* filename = O9.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = q2, &
op_unit = dimensionless
* filename = O10.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = c2, &
op_unit = dimensionless
psi:
* type = file, filename = psi_00.dat, label = 00
psi:
* type = file, filename = psi_01.dat, label = 01
psi:
* type = file, filename = psi_10.dat, label = 10
psi:
* type = file, filename = psi_11.dat, label = 11
psi:
* type = file, filename = psi_dicke_init_half.dat, label = dicke_init_half
psi:
* type = file, filename = psi_dicke_half.dat, label = dicke_half
psi:
* type = file, filename = psi_dicke_init_full.dat, label = dicke_init_full
psi:
* type = file, filename = psi_dicke_1.dat, label = dicke_1
oct: method = krotovpk, J_T_conv = 0.0001, max_ram_mb = 100000, &
iter_dat = oct_iters.dat, iter_stop = 100, keep_pulses = all, &
limit_pulses = T, params_file = oct_params.dat, tau_dat = oct_tau.dat
user_strings: time_unit = microsec, write_jump_record = jump_record.dat, &
write_final_state = psi_final.dat, initial_states = 10, target_states = 01
''').strip()
assert config == expected
p = qdyn_check_config(str(tmpdir.join('config')))
p.wait()
out = p.stdout.read()
assert 'Successfully read config file' in out
def test_no_feedback_oct_gate_system(model_no_fb_oct_gate, tmpdir):
model = copy(model_no_fb_oct_gate)
model.write_to_runfolder(str(tmpdir))
QDYN.gate2q.sqrt_SWAP.write(str(tmpdir.join('target_gate.dat')))
config = tmpdir.join('config').read().strip()
expected = dedent(r'''
tgrid: t_start = -4_microsec, t_stop = 4_microsec, nt = 2001
prop: method = newton, use_mcwf = F
pulse: type = file, time_unit = microsec, ampl_unit = MHz, is_complex = F, &
oct_shape = flattop, shape_t_start = -4_microsec, shape_t_stop = 4_microsec, &
t_rise = 0.8_microsec, t_fall = 0.8_microsec, oct_lambda_a = 1e-05, &
oct_increase_factor = 5, oct_pulse_max = 699.999_MHz, &
oct_pulse_min = -699.999_MHz
* id = 1, filename = pulse1.dat, oct_outfile = pulse1.oct.dat
* id = 2, filename = pulse2.dat, oct_outfile = pulse2.oct.dat
ham: type = matrix, real_op = F, n_surf = 100, sparsity_model = indexed
* filename = H0.dat, op_unit = MHz, op_type = potential
* filename = H1.dat, op_unit = dimensionless, op_type = dipole, pulse_id = 1
* filename = H2.dat, op_unit = dimensionless, op_type = dipole, pulse_id = 2
dissipator:
* type = dissipator, filename = D1.dat, real_op = F, op_unit = MHz, &
sparsity_model = indexed
observables: type = matrix, real_op = F, op_type = pot, n_surf = 100, &
time_unit = microsec
* filename = O1.dat, sparsity_model = indexed, outfile = darkstate_cond.dat, &
exp_unit = MHz, is_real = T, column_label = <L^+L>, op_unit = MHz
* filename = O2.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(00), &
op_unit = dimensionless
* filename = O3.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(01), &
op_unit = dimensionless
* filename = O4.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(10), &
op_unit = dimensionless
* filename = O5.dat, sparsity_model = indexed, outfile = qubit_pop.dat, &
exp_unit = dimensionless, is_real = T, column_label = P(11), &
op_unit = dimensionless
* filename = O6.dat, sparsity_model = indexed, outfile = 10_01_coherence.dat, &
exp_unit = dimensionless, is_real = F, column_label = |10><01|, &
op_unit = dimensionless
* filename = O7.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = q1, &
op_unit = dimensionless
* filename = O8.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = c1, &
op_unit = dimensionless
* filename = O9.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = q2, &
op_unit = dimensionless
* filename = O10.dat, sparsity_model = banded, outfile = excitation.dat, &
exp_unit = dimensionless, is_real = T, column_label = c2, &
op_unit = dimensionless
psi:
* type = file, filename = psi_00.dat, label = 00
psi:
* type = file, filename = psi_01.dat, label = 01
psi:
* type = file, filename = psi_10.dat, label = 10
psi:
* type = file, filename = psi_11.dat, label = 11
psi:
* type = file, filename = psi_dicke_init_half.dat, label = dicke_init_half
psi:
* type = file, filename = psi_dicke_half.dat, label = dicke_half
psi:
* type = file, filename = psi_dicke_init_full.dat, label = dicke_init_full
psi:
* type = file, filename = psi_dicke_1.dat, label = dicke_1
oct: method = krotovpk, J_T_conv = 0.0001, max_ram_mb = 100000, &
iter_dat = oct_iters.dat, iter_stop = 100, keep_pulses = all, &
limit_pulses = T, params_file = oct_params.dat, tau_dat = oct_tau.dat
user_strings: time_unit = microsec, write_jump_record = jump_record.dat, &
write_final_state = psi_final.dat, basis = 00\,01\,10\,11, &
gate = target_gate.dat
''').strip()
assert config == expected
p = qdyn_check_config(str(tmpdir.join('config')))
p.wait()
out = p.stdout.read()
assert 'Successfully read config file' in out
gate = QDYN.gate2q.Gate2Q.read(str(tmpdir.join('target_gate.dat')))
diff = np.abs(QDYN.linalg.vectorize(gate - QDYN.gate2q.sqrt_SWAP))
assert QDYN.linalg.norm(diff) < 1e-14
@pytest.mark.xfail(reason=r'''
Incompatible change in QNET
The way QNET handles custom identifiers for Create/Destroy changed in
commit f5d759a9bbe844d616e82e621dcd2d773fe08297
Some of the code in this epor requires an older version of QNET (but nothing
critical for publication)
''')
def test_crossed_cavity_slh():
slh = crossed_cavity_network.network_slh(
n_cavity=2, n_nodes=2, topology='FB')
assert slh.S[0, 0] == 1
def test_logical_2q_state():
"""Test construction of logical states"""
from src.qdyn_model_v1 import logical_2q_state, state
from src import single_sided_network_v1 as single_sided_network
slh = single_sided_network.network_slh(
n_cavity=5, n_nodes=2, topology='open')
hs = slh.H.space
assert logical_2q_state(hs, 0, 0) == state(hs, 0, 0, 0, 0)
assert logical_2q_state(hs, 0, 1) == state(hs, 0, 0, 1, 0)
assert logical_2q_state(hs, 1, 0) == state(hs, 1, 0, 0, 0)
assert logical_2q_state(hs, 1, 1) == state(hs, 1, 0, 1, 0)
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('q3', dimension=2), LocalSpace('c3', dimension=2))
assert logical_2q_state(hs, 0, 0) == state(hs, 0, 0, 0, 0, 0, 0)
assert logical_2q_state(hs, 0, 1) == state(hs, 0, 0, 0, 0, 1, 0)
assert logical_2q_state(hs, 1, 0) == state(hs, 1, 0, 0, 0, 0, 0)
assert logical_2q_state(hs, 1, 1) == state(hs, 1, 0, 0, 0, 1, 0)
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('d1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('d2', dimension=2))
assert logical_2q_state(hs, 0, 0) == state(hs, 0, 0, 0, 0, 0, 0)
assert logical_2q_state(hs, 0, 1) == state(hs, 0, 0, 0, 1, 0, 0)
assert logical_2q_state(hs, 1, 0) == state(hs, 1, 0, 0, 0, 0, 0)
assert logical_2q_state(hs, 1, 1) == state(hs, 1, 0, 0, 1, 0, 0)
def test_dicke1_state():
"""Test single-excitation dicke state"""
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('q3', dimension=2), LocalSpace('c3', dimension=2))
dicke_state = (qdyn_model.state(hs, 0, 0, 0, 0, 1, 0) +
qdyn_model.state(hs, 0, 0, 1, 0, 0, 0) +
qdyn_model.state(hs, 1, 0, 0, 0, 0, 0)) / np.sqrt(3)
assert (qdyn_model.dicke_state(hs, excitations=1) -
dicke_state).norm() < 1e-12
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('d1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('d2', dimension=2))
dicke_state = (qdyn_model.state(hs, 0, 0, 0, 1, 0, 0) +
qdyn_model.state(hs, 1, 0, 0, 0, 0, 0)) / np.sqrt(2)
assert (qdyn_model.dicke_state(hs, excitations=1) -
dicke_state).norm() < 1e-12
def test_dicke_init1_state():
"""Test initial state with 1 exctation"""
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('q3', dimension=2), LocalSpace('c3', dimension=2))
init_state = qdyn_model.state(hs, 1, 0, 0, 0, 0, 0)
assert (qdyn_model.dicke_init_state(hs, excitations=1) -
init_state).norm() < 1e-12
def test_dicke_half_state():
"""Test dicke state with N/2 excitations"""
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('q3', dimension=2), LocalSpace('c3', dimension=2),
LocalSpace('q4', dimension=2), LocalSpace('c4', dimension=2))
# q1 q2 q3 q4
dicke_state = (qdyn_model.state(hs, 1, 0, 1, 0, 0, 0, 0, 0) +
qdyn_model.state(hs, 1, 0, 0, 0, 1, 0, 0, 0) +
qdyn_model.state(hs, 1, 0, 0, 0, 0, 0, 1, 0) +
qdyn_model.state(hs, 0, 0, 1, 0, 1, 0, 0, 0) +
qdyn_model.state(hs, 0, 0, 1, 0, 0, 0, 1, 0) +
qdyn_model.state(hs, 0, 0, 0, 0, 1, 0, 1, 0)) / np.sqrt(6)
assert (qdyn_model.dicke_state(hs, excitations=2) -
dicke_state).norm() < 1e-12
def test_dicke_init_half_state():
"""Test initial state with N/2 exctations"""
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('q3', dimension=2), LocalSpace('c3', dimension=2),
LocalSpace('q4', dimension=2), LocalSpace('c4', dimension=2))
init_state = qdyn_model.state(hs, 1, 0, 1, 0, 0, 0, 0, 0)
assert (qdyn_model.dicke_init_state(hs, excitations=2) -
init_state).norm() < 1e-12
def test_dicke_full_state():
"""Test dicke state with N exctations"""
# Note that the dicke state is separable in this case: it is the same as
# the 'init' state
hs = ProductSpace(
LocalSpace('q1', dimension=2), LocalSpace('c1', dimension=2),
LocalSpace('q2', dimension=2), LocalSpace('c2', dimension=2),
LocalSpace('q3', dimension=2), LocalSpace('c3', dimension=2))
assert (qdyn_model.dicke_state(hs, excitations=3) -
qdyn_model.dicke_init_state(hs, excitations=3)).norm() < 1e-12
def test_pi_pulse():
from sympy import pi, cos
a, b, E0, t, T, μ, t_π = sympy.symbols("a b E_0, t, T, mu, t_pi",
positive=True)
B_form = (E0 / 2) * (1 - a - cos(2 * pi * t / T) + a * cos(4 * pi * t / T))
a_blackman = 0.16
Ωeff_form = μ * (sympy.integrate(B_form, (t, 0, T)) / T).simplify()
t_pi_form = pi / (2 * Ωeff_form).subs({1-a: b})
# protect 1-a, so sympy doesn't do weird signs
E_pi_form = sympy.solve(t_pi_form - t_π, E0)[0].subs({b: 1-a})
tgrid_start = -100
tgrid_end = 100
nt = tgrid_end - tgrid_start + 1
tgrid = QDYN.pulse.pulse_tgrid(t0=tgrid_start, T=tgrid_end, nt=nt)
mu_1 = 0.005
E0 = sympy.N(E_pi_form.subs({t_π: 100, μ: mu_1, a: a_blackman}))
p1 = pi_pulse(tgrid, t_start=-50, t_stop=50, mu=float(mu_1), cycles=1)
assert (np.max(p1.amplitude) - E0) < 1e-12
assert p1.t0.unit == 'dimensionless'
assert abs(float(p1.t0) - (-100)) < 1e-12
assert abs(float(p1.T) - (100)) < 1e-12
assert len(p1.amplitude) == 200
p2 = pi_pulse(tgrid, t_start=-50, t_stop=50, mu=float(mu_1), cycles=2)
assert np.max(np.abs(2.0 * p1.amplitude - p2.amplitude)) < 1e-12
assert abs(float(p2.t0) - (-100)) < 1e-12
assert abs(float(p2.T) - (100)) < 1e-12
def test_pi_zero():
tgrid_start = -100
tgrid_end = 100
nt = tgrid_end - tgrid_start + 1
tgrid = QDYN.pulse.pulse_tgrid(t0=tgrid_start, T=tgrid_end, nt=nt)
p = zero_pulse(tgrid)
assert np.max(p.amplitude) == 0.0
assert p.t0.unit == 'dimensionless'
assert abs(float(p.t0) - (-100)) < 1e-12
assert abs(float(p.T) - (100)) < 1e-12
assert len(p.amplitude) == 200
@pytest.mark.parametrize("T,theta,E0_cycles,mcwf,non_herm,lambda_a,n_nodes", [
# T, theta, E0_cycles, mcwf, non_herm, lambda_a, n_nodes
(200, 0, 2, False, False, 1.0, 2),
(200, 0, 2, False, False, 0.01, 2),
(200, 0, 2, False, True, 1.0, 2),
(200, 0, 2, True, False, 1.0, 2),
(200, 0, 2, True, True, 1.0, 2),
(200, 0, 2, True, True, 1.0, 4),
(200, 0, 4, True, True, 1.0, 2),
(1000, 0, 2, True, True, 1.0, 2),
(200, np.pi/4.0, 2, True, True, 1.0, 2),
])
def test_dicke_half_model(
tmpdir, T, theta, E0_cycles, mcwf, non_herm, lambda_a, n_nodes):
"""Test creation of model for dicke state"""
slh = single_sided_network.network_slh(
n_cavity=2, n_nodes=n_nodes, topology='driven_bs_fb')
rf = str(tmpdir)
write_dicke_half_model(
slh, rf, T=T, theta=theta, E0_cycles=E0_cycles, mcwf=mcwf,
non_herm=non_herm, lambda_a=lambda_a)
config = QDYN.config.read_config_file(join(rf, 'config'))
assert config['tgrid']['t_start'] == 0
assert float(config['tgrid']['t_stop']) == float(T)
assert len(config['pulse']) == n_nodes
for pulse_config in config['pulse']:
assert pulse_config['oct_lambda_a'] == lambda_a
if T < 400:
assert float(pulse_config['t_rise']) == 4.0
assert float(pulse_config['t_fall']) == 4.0
else:
assert abs(float(pulse_config['t_rise']) - 0.01 * float(T)) < 1e-10
assert abs(float(pulse_config['t_fall']) - 0.01 * float(T)) < 1e-10
assert not pulse_config['is_complex']
assert len(config['ham']) == n_nodes + 1
for ham_config in config['ham']:
assert ham_config['n_surf'] == 4**n_nodes
assert config['prop']['method'] == 'newton'
assert config['user_strings']['time_unit'] == 'dimensionless'
assert config['user_strings']['initial_states'] == 'dicke_init_half'
assert config['user_strings']['target_states'] == 'dicke_half'
assert config['user_strings']['state_label'] == 'dicke_init_half'
pulse = QDYN.pulse.Pulse.read(join(rf, config['pulse'][0]['filename']))
E0 = E0_cycles * 3.73961292 * 200 / T
assert abs(np.max(pulse.amplitude) - E0) < 1e-3
H0 = QDYN.io.read_indexed_matrix(join(rf, "H0.dat"))
if (mcwf, non_herm) == (False, False):
# density matrix propagation
assert len(config['dissipator']) == 1
assert config['dissipator'][0]['type'] == 'dissipator'
assert not config['prop']['use_mcwf']
assert config['user_logicals']['rho']
assert scipy.sparse.linalg.norm(H0 - H0.H) == 0.0
elif (mcwf, non_herm) == (False, True):
# non-Hermitian Hamiltonian
assert 'dissipator' not in config
assert not config['prop']['use_mcwf']
assert scipy.sparse.linalg.norm(H0 - H0.H) > 0
elif (mcwf, non_herm) == (True, True):
# MCWF with effective Hamiltonian pre-calculated
assert len(config['dissipator']) == 1
assert config['dissipator'][0]['type'] == 'lindblad_ops'
assert not config['dissipator'][0]['conv_to_superop']
assert 'add_to_H_jump' not in config['dissipator'][0]
assert config['prop']['use_mcwf']
assert scipy.sparse.linalg.norm(H0 - H0.H) > 0
L1 = QDYN.io.read_indexed_matrix(join(rf, "L1.dat"))
theta_pi = np.pi * theta
kappa_eff = (np.sqrt(2 * 0.01) * np.cos(theta_pi) /
(1 - np.sin(theta_pi)))
assert (np.linalg.norm(L1.data - kappa_eff * np.ones(len(L1.data))) <
1e-12)
elif (mcwf, non_herm) == (True, False):
# MCWF with effective Hamiltonian calculated in QDYN
assert len(config['dissipator']) == 1
assert config['dissipator'][0]['type'] == 'lindblad_ops'
assert not config['dissipator'][0]['conv_to_superop']
assert config['dissipator'][0]['add_to_H_jump'] == 'indexed'
assert config['prop']['use_mcwf']
assert scipy.sparse.linalg.norm(H0 - H0.H) == 0
def test_complex_dick_half_model(tmpdir):
"""Test that we can create a dicke model with complex pulse amplitudes"""
T = 200
theta = 0
E0_cycles = 2
mcwf = True
non_herm = True
lambda_a = 1.0
n_nodes = 2
slh = single_sided_network.network_slh(
n_cavity=2, n_nodes=n_nodes, topology='driven_bs_fb')
rf = str(tmpdir)
write_dicke_half_model_v2(
slh, rf, T=T, theta=theta, E0_cycles=E0_cycles, mcwf=mcwf,
non_herm=non_herm, lambda_a=lambda_a, complex_pulses=True)
config = QDYN.config.read_config_file(join(rf, 'config'))
for pulse_config in config['pulse']:
assert pulse_config['is_complex']