|
3 | 3 | """
|
4 | 4 |
|
5 | 5 | import copy
|
| 6 | +import pickle |
6 | 7 | import numpy as np
|
7 | 8 |
|
8 | 9 | # Main C3 objects
|
|
445 | 446 |
|
446 | 447 | opt.set_exp(exp)
|
447 | 448 |
|
448 |
| - |
449 |
| -def run_optim() -> float: |
450 |
| - """ |
451 |
| - Perform the optimization run |
452 |
| - """ |
453 |
| - opt.optimize_controls() |
454 |
| - return (opt.current_best_goal) |
455 |
| - |
| 449 | +with open("test/two_qubit_data.pickle", "rb") as filename: |
| 450 | + test_data = pickle.load(filename) |
456 | 451 |
|
457 | 452 | gen_signal = generator.generate_signals(X90p_q1)
|
458 | 453 | ts = gen_signal["d1"]["ts"]
|
| 454 | +hdrift, hks = model.get_Hamiltonians() |
| 455 | +propagator = exp.propagation(gen_signal, "X90p:Id") |
459 | 456 |
|
460 | 457 |
|
461 |
| -def test_signals_max() -> None: |
462 |
| - """ |
463 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
464 |
| - """ |
465 |
| - assert np.max(gen_signal["d1"]["values"]) - 442864262.3882865 < 1 |
| 458 | +def test_signals() -> None: |
| 459 | + for key in gen_signal: |
| 460 | + assert (gen_signal[key]["values"].numpy() - test_data["signal"][key]["values"].numpy() < 1).all() |
| 461 | + assert (ts.numpy() == test_data["ts"].numpy()).all() |
466 | 462 |
|
467 | 463 |
|
468 |
| -def test_signals_at_0() -> None: |
469 |
| - """ |
470 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
471 |
| - """ |
472 |
| - assert gen_signal["d1"]["values"][0] < 1 |
473 |
| - |
474 |
| - |
475 |
| -def test_signals_at_12() -> None: |
476 |
| - """ |
477 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
478 |
| - """ |
479 |
| - assert gen_signal["d1"]["values"][12] - -18838613.771749068 < 1 |
480 |
| - |
481 |
| - |
482 |
| -def test_signals_at_end() -> None: |
483 |
| - """ |
484 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
485 |
| - """ |
486 |
| - assert gen_signal["d1"]["values"][-1] - 47702706.02427947 < 1 |
487 |
| - |
488 |
| - |
489 |
| -def test_ts_at_0() -> None: |
490 |
| - """ |
491 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
492 |
| - """ |
493 |
| - assert ts[0] == 5e-12 |
494 |
| - |
495 |
| - |
496 |
| -def test_test_ts_at_12() -> None: |
497 |
| - """ |
498 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
499 |
| - """ |
500 |
| - assert ts[12] == 1.25e-10 |
501 |
| - |
502 |
| - |
503 |
| -def test_ts_at_end() -> None: |
504 |
| - """ |
505 |
| - Test if the generated signals are correct at the first and last sample and at sample #12. |
506 |
| - """ |
507 |
| - assert ts[-1] == 6.995e-09 |
508 |
| - |
509 |
| - |
510 |
| -def test_hamiltonian_of_t() -> None: |
511 |
| - cflds_t = gen_signal["d1"]["values"][16] |
512 |
| - hdrift, hks = model.get_Hamiltonians() |
513 |
| - hamiltonian = hdrift.numpy() + cflds_t.numpy() * hks["d1"].numpy() |
514 |
| - precomp_hamiltonian = [ |
515 |
| - [-2.37105674e+05+0.j, -4.39488626e+05+0.j, 6.42557156e-09+0.j, |
516 |
| - -1.39929598e+07+0.j, 4.80420449e-08+0.j, -5.12932000e+01+0.j, |
517 |
| - -9.18583639e-10+0.j, -7.52868617e+02+0.j, -4.60493681e-10+0.j,], |
518 |
| - [-4.39488626e+05+0.j, 3.51895367e+10+0.j, -1.05404930e+06+0.j, |
519 |
| - -4.21166702e-06+0.j, -1.39659734e+07+0.j, -3.38001933e-07+0.j, |
520 |
| - -1.70280246e+05+0.j, -3.42845091e-07+0.j, -1.12262365e+03+0.j,], |
521 |
| - [ 8.21276864e-09+0.j, -1.05404930e+06+0.j, 6.88776096e+10+0.j, |
522 |
| - -2.87659692e+01+0.j, -4.35040944e-06+0.j, -1.40273221e+07+0.j, |
523 |
| - 6.11788641e-06+0.j, -5.67966729e+05+0.j, -5.92691374e-06+0.j,], |
524 |
| - [-1.39929598e+07+0.j, -4.06274727e-06+0.j, -2.87659692e+01+0.j, |
525 |
| - 3.14112585e+10+0.j, -1.97916311e+05+0.j, -2.68973468e-05+0.j, |
526 |
| - -1.97926130e+07+0.j, -5.91563241e-06+0.j, -1.02890811e+02+0.j,], |
527 |
| - [ 5.04042505e-08+0.j, -1.39659734e+07+0.j, -1.84797479e-06+0.j, |
528 |
| - -1.97916311e+05+0.j, 6.65933163e+10+0.j, -2.45595202e+05+0.j, |
529 |
| - 1.03870858e-05+0.j, -1.97587093e+07+0.j, 1.03713136e-05+0.j,], |
530 |
| - [-5.12932000e+01+0.j, -4.57618676e-07+0.j, -1.40273221e+07+0.j, |
531 |
| - -2.68926902e-05+0.j, -2.45595202e+05+0.j, 1.00297674e+11+0.j, |
532 |
| - 3.15118982e+04+0.j, 7.62930650e-06+0.j, -1.97559869e+07+0.j,], |
533 |
| - [-1.21110840e-09+0.j, -1.70280246e+05+0.j, 6.09999393e-06+0.j, |
534 |
| - -1.97926130e+07+0.j, 1.07057873e-05+0.j, 3.15118982e+04+0.j, |
535 |
| - 6.15061801e+10+0.j, 6.36236697e+05+0.j, -2.25524516e-05+0.j,], |
536 |
| - [-7.52868617e+02+0.j, -3.44707736e-07+0.j, -5.67966729e+05+0.j, |
537 |
| - -5.93053357e-06+0.j, -1.97587093e+07+0.j, 8.58298081e-06+0.j, |
538 |
| - 6.36236697e+05+0.j, 9.66811548e+10+0.j, 1.30140463e+06+0.j,], |
539 |
| - [-5.01826729e-10+0.j, -1.12262365e+03+0.j, -5.92318845e-06+0.j, |
540 |
| - -1.02890811e+02+0.j, 1.04309182e-05+0.j, -1.97559869e+07+0.j, |
541 |
| - -2.25571082e-05+0.j, 1.30140463e+06+0.j, 1.30377086e+11+0.j,], |
542 |
| - ] |
543 |
| - |
544 |
| - assert (hamiltonian - precomp_hamiltonian < 1e-15).any() |
| 464 | +def test_hamiltonians() -> None: |
| 465 | + assert (hdrift.numpy() == test_data["hdrift"].numpy()).any() |
| 466 | + for key in hks: |
| 467 | + assert (hks[key].numpy() == test_data["hks"][key].numpy()).all() |
545 | 468 |
|
546 | 469 |
|
547 | 470 | def test_propagation() -> None:
|
548 |
| - propagator = exp.propagation(gen_signal, "X90p:Id") |
549 |
| - precomputed = np.array( |
550 |
| - [ |
551 |
| - [-5.42470209e-02 - 7.55118401e-01j, 1.31475007e-04 - 1.66893081e-04j, |
552 |
| - 5.81482026e-08 + 4.56344704e-08j, 6.51945328e-01 - 3.21728860e-02j, |
553 |
| - 1.20669716e-04 + 5.09331324e-05j, 3.19775048e-08 + 1.04614907e-07j, |
554 |
| - -9.41458634e-03 - 2.63990622e-02j, 3.55609615e-05 - 2.18958182e-04j, |
555 |
| - -6.42952047e-07 - 1.07156481e-06j] |
556 |
| - ] |
557 |
| - ) |
558 |
| - |
559 |
| - assert ((propagator.numpy()[3] - precomputed) < 1e-8).all() |
| 471 | + assert (propagator.numpy() - test_data["propagator"].numpy() < 1e-12).all() |
560 | 472 |
|
561 | 473 |
|
562 | 474 | def test_two_qubits() -> None:
|
563 | 475 | """
|
564 | 476 | check if optimization result is below 1e-2
|
565 | 477 | """
|
566 |
| - assert run_optim() < 0.01 |
| 478 | + opt.optimize_controls() |
| 479 | + assert opt.current_best_goal < 0.01 |
0 commit comments