@@ -490,15 +490,27 @@ void ITensorMPSVisitor::visit(Rz &gate) {
490
490
execTime += singleQubitTime;
491
491
}
492
492
493
- void ITensorMPSVisitor::visit (U& u) {
494
- Rz z1 (u.bits ()[0 ], ipToDouble (u.getParameter (0 )));
495
- Ry y (u.bits ()[0 ], ipToDouble (u.getParameter (1 )));
496
- Rz z2 (u.bits ()[0 ], ipToDouble (u.getParameter (2 )));
497
-
498
- visit (z1);
499
- visit (y);
500
- visit (z2);
493
+ void ITensorMPSVisitor::visit (U &u) {
494
+ auto iqbit_in = u.bits ()[0 ];
495
+ if (verbose) {
496
+ std::cout << " applying " << u.name () << " @ " << iqbit_in << std::endl;
501
497
}
498
+ const double theta = ipToDouble (u.getParameter (0 ));
499
+ const double phi = ipToDouble (u.getParameter (1 ));
500
+ const double lambda = ipToDouble (u.getParameter (2 ));
501
+ auto ind_in = ind_for_qbit (iqbit_in);
502
+ auto ind_out = itensor::Index (u.name (), 2 );
503
+ auto tGate = itensor::ITensor (ind_in, ind_out);
504
+ tGate.set (ind_in (1 ), ind_out (1 ), std::cos (theta / 2.0 ));
505
+ tGate.set (ind_in (1 ), ind_out (2 ), -std::exp (std::complex<double >(0 , lambda)) *
506
+ std::sin (theta / 2.0 ));
507
+ tGate.set (ind_in (2 ), ind_out (1 ), std::exp (std::complex<double >(0 , phi)) * std::sin (theta / 2.0 ));
508
+ tGate.set (ind_in (2 ), ind_out (2 ), std::exp (std::complex<double >(0 , phi + lambda)) *
509
+ std::cos (theta / 2.0 ));
510
+ legMats[iqbit_in] = tGate * legMats[iqbit_in];
511
+ printWavefunc ();
512
+ execTime += singleQubitTime;
513
+ }
502
514
503
515
void ITensorMPSVisitor::visit (CPhase &cp) {
504
516
xacc::error (" ITensorMPS Visitor CPhase visit unimplemented." );
0 commit comments