@@ -411,6 +411,153 @@ void testApplyIsingXX() {
411
411
}
412
412
PENNYLANE_RUN_TEST (IsingXX);
413
413
414
+ template <typename PrecisionT, typename ParamT, class GateImplementation >
415
+ void testApplyIsingXY () {
416
+ using ComplexPrecisionT = std::complex<PrecisionT>;
417
+ using std::cos ;
418
+ using std::sin ;
419
+
420
+ DYNAMIC_SECTION (GateImplementation::name
421
+ << " , IsingXY0,1 |000> -> a|000> - "
422
+ << PrecisionToName<PrecisionT>::value) {
423
+ const size_t num_qubits = 3 ;
424
+ const auto ini_st = createZeroState<PrecisionT>(num_qubits);
425
+ ParamT angle = 0.312 ;
426
+
427
+ const std::vector<ComplexPrecisionT> expected_results{
428
+ ComplexPrecisionT{1.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
429
+ ComplexPrecisionT{0.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
430
+ ComplexPrecisionT{0.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
431
+ ComplexPrecisionT{0.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
432
+ };
433
+
434
+ auto st = ini_st;
435
+ GateImplementation::applyIsingXY (st.data (), num_qubits, {0 , 1 }, false ,
436
+ angle);
437
+ REQUIRE (st == approx (expected_results).margin (1e-7 ));
438
+ }
439
+ DYNAMIC_SECTION (GateImplementation::name
440
+ << " , IsingXY0,1 |100> -> a|100> + b|010> - "
441
+ << PrecisionToName<PrecisionT>::value) {
442
+ const size_t num_qubits = 3 ;
443
+ const auto ini_st = createProductState<PrecisionT>(" 100" );
444
+ ParamT angle = 0.312 ;
445
+
446
+ const std::vector<ComplexPrecisionT> expected_results{
447
+ ComplexPrecisionT{0.0 , 0.0 },
448
+ ComplexPrecisionT{0.0 , 0.0 },
449
+ ComplexPrecisionT{0.0 , sin (angle / 2 )},
450
+ ComplexPrecisionT{0.0 , 0.0 },
451
+ ComplexPrecisionT{cos (angle / 2 ), 0.0 },
452
+ ComplexPrecisionT{0.0 , 0.0 },
453
+ ComplexPrecisionT{0.0 , 0.0 },
454
+ ComplexPrecisionT{0.0 , 0.0 },
455
+ };
456
+
457
+ auto st = ini_st;
458
+ GateImplementation::applyIsingXY (st.data (), num_qubits, {0 , 1 }, false ,
459
+ angle);
460
+ REQUIRE (st == approx (expected_results).margin (1e-7 ));
461
+ }
462
+
463
+ DYNAMIC_SECTION (GateImplementation::name
464
+ << " , IsingXY0,1 |010> -> a|010> + b|100> - "
465
+ << PrecisionToName<PrecisionT>::value) {
466
+ const size_t num_qubits = 3 ;
467
+ const auto ini_st = createProductState<PrecisionT>(" 010" );
468
+ ParamT angle = 0.312 ;
469
+
470
+ const std::vector<ComplexPrecisionT> expected_results{
471
+ ComplexPrecisionT{0.0 , 0.0 },
472
+ ComplexPrecisionT{0.0 , 0.0 },
473
+ ComplexPrecisionT{cos (angle / 2 ), 0.0 },
474
+ ComplexPrecisionT{0.0 , 0.0 },
475
+ ComplexPrecisionT{0.0 , sin (angle / 2 )},
476
+ ComplexPrecisionT{0.0 , 0.0 },
477
+ ComplexPrecisionT{0.0 , 0.0 },
478
+ ComplexPrecisionT{0.0 , 0.0 },
479
+ };
480
+
481
+ auto st = ini_st;
482
+ GateImplementation::applyIsingXY (st.data (), num_qubits, {0 , 1 }, false ,
483
+ angle);
484
+ REQUIRE (st == approx (expected_results).margin (1e-7 ));
485
+ }
486
+
487
+ DYNAMIC_SECTION (GateImplementation::name
488
+ << " , IsingXY0,1 |110> -> a|110> - "
489
+ << PrecisionToName<PrecisionT>::value) {
490
+ const size_t num_qubits = 3 ;
491
+ const auto ini_st = createProductState<PrecisionT>(" 110" );
492
+ ParamT angle = 0.312 ;
493
+
494
+ const std::vector<ComplexPrecisionT> expected_results{
495
+ ComplexPrecisionT{0.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
496
+ ComplexPrecisionT{0.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
497
+ ComplexPrecisionT{0.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
498
+ ComplexPrecisionT{1.0 , 0.0 }, ComplexPrecisionT{0.0 , 0.0 },
499
+ };
500
+
501
+ auto st = ini_st;
502
+ GateImplementation::applyIsingXY (st.data (), num_qubits, {0 , 1 }, false ,
503
+ angle);
504
+ REQUIRE (st == approx (expected_results).margin (1e-7 ));
505
+ }
506
+
507
+ DYNAMIC_SECTION (GateImplementation::name
508
+ << " , IsingXY0,1 - "
509
+ << PrecisionToName<PrecisionT>::value) {
510
+ const size_t num_qubits = 4 ;
511
+
512
+ std::vector<ComplexPrecisionT> ini_st{
513
+ ComplexPrecisionT{0.267462841882 , 0.010768564798 },
514
+ ComplexPrecisionT{0.228575129706 , 0.010564590956 },
515
+ ComplexPrecisionT{0.099492749900 , 0.260849823392 },
516
+ ComplexPrecisionT{0.093690204310 , 0.189847108173 },
517
+ ComplexPrecisionT{0.033390732374 , 0.203836830144 },
518
+ ComplexPrecisionT{0.226979395737 , 0.081852150975 },
519
+ ComplexPrecisionT{0.031235505729 , 0.176933497281 },
520
+ ComplexPrecisionT{0.294287602843 , 0.145156781198 },
521
+ ComplexPrecisionT{0.152742706049 , 0.111628061129 },
522
+ ComplexPrecisionT{0.012553863703 , 0.120027860480 },
523
+ ComplexPrecisionT{0.237156555364 , 0.154658769755 },
524
+ ComplexPrecisionT{0.117001120872 , 0.228059505033 },
525
+ ComplexPrecisionT{0.041495873225 , 0.065934827444 },
526
+ ComplexPrecisionT{0.089653239407 , 0.221581340372 },
527
+ ComplexPrecisionT{0.217892322429 , 0.291261296999 },
528
+ ComplexPrecisionT{0.292993251871 , 0.186570798697 },
529
+ };
530
+
531
+ const std::vector<size_t > wires = {0 , 1 };
532
+ const ParamT angle = 0.312 ;
533
+
534
+ std::vector<ComplexPrecisionT> expected{
535
+ ComplexPrecisionT{0.267462849617 , 0.010768564418 },
536
+ ComplexPrecisionT{0.228575125337 , 0.010564590804 },
537
+ ComplexPrecisionT{0.099492751062 , 0.260849833488 },
538
+ ComplexPrecisionT{0.093690201640 , 0.189847111702 },
539
+ ComplexPrecisionT{0.015641822883 , 0.225092900621 },
540
+ ComplexPrecisionT{0.205574608177 , 0.082808663337 },
541
+ ComplexPrecisionT{0.006827173322 , 0.211631480575 },
542
+ ComplexPrecisionT{0.255280800811 , 0.161572331669 },
543
+ ComplexPrecisionT{0.119218164572 , 0.115460377284 },
544
+ ComplexPrecisionT{-0.000315789761 , 0.153835664378 },
545
+ ComplexPrecisionT{0.206786872079 , 0.157633689097 },
546
+ ComplexPrecisionT{0.093027614553 , 0.271012980118 },
547
+ ComplexPrecisionT{0.041495874524 , 0.065934829414 },
548
+ ComplexPrecisionT{0.089653238654 , 0.221581339836 },
549
+ ComplexPrecisionT{0.217892318964 , 0.291261285543 },
550
+ ComplexPrecisionT{0.292993247509 , 0.186570793390 },
551
+ };
552
+
553
+ auto st = ini_st;
554
+ GateImplementation::applyIsingXY (st.data (), num_qubits, wires, false ,
555
+ angle);
556
+ REQUIRE (st == approx (expected).margin (1e-5 ));
557
+ }
558
+ }
559
+ PENNYLANE_RUN_TEST (IsingXY);
560
+
414
561
template <typename PrecisionT, typename ParamT, class GateImplementation >
415
562
void testApplyIsingYY () {
416
563
using ComplexPrecisionT = std::complex<PrecisionT>;
0 commit comments