Maestro 0.2.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
QuantumGates.h
Go to the documentation of this file.
1
14
15#pragma once
16
17#ifndef _QUANTUM_GATES_H_
18#define _QUANTUM_GATES_H_
19
20#include "Operations.h"
21#include "QuantumGate.h"
22
23namespace Circuits {
24
62
72template <typename Time = Types::time_type>
73class IQuantumGate : public IGateOperation<Time> {
74 public:
82 IQuantumGate(Time delay = 0) : IGateOperation<Time>(delay) {}
83
91 virtual QuantumGateType GetGateType() const = 0;
92
100 virtual std::vector<double> GetParams() const { return {}; }
101
108 virtual Eigen::MatrixXcd GetMatrix() const = 0;
109};
110
121template <typename Time = Types::time_type>
122class SingleQubitGate : public IQuantumGate<Time> {
123 public:
133 SingleQubitGate(Types::qubit_t qubit = 0, Time delay = 0)
134 : IQuantumGate<Time>(delay), qubit(qubit) {}
135
142 virtual ~SingleQubitGate() {}
143
151 unsigned int GetNumQubits() const override { return 1; }
152
161 void SetQubit(Types::qubit_t q, unsigned long index = 0) override {
162 qubit = q;
163 }
164
174 Types::qubit_t GetQubit(unsigned int index = 0) const override {
175 return qubit;
176 }
177
185 Types::qubits_vector AffectedQubits() const override { return {qubit}; }
186
197 std::shared_ptr<IOperation<Time>> Remap(
198 const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
199 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
200 const override {
201 auto newGate = this->Clone();
202
203 const auto qubitit = qubitsMap.find(qubit);
204 if (qubitit != qubitsMap.end())
205 std::static_pointer_cast<SingleQubitGate<Time>>(newGate)->SetQubit(
206 qubitit->second);
207 // else throw std::invalid_argument("Qubit not found in qubits map to remap
208 // the gate.");
209
210 return newGate;
211 }
212
213 private:
214 Types::qubit_t qubit;
215};
216
226template <typename Time = Types::time_type>
227class TwoQubitsGate : public IQuantumGate<Time> {
228 public:
241 Time delay = 0)
242 : IQuantumGate<Time>(delay), qubit1(qubit1), qubit2(qubit2) {}
243
250 virtual ~TwoQubitsGate() {}
251
259 unsigned int GetNumQubits() const override { return 2; }
260
269 void SetQubit(Types::qubit_t q, unsigned long index = 0) override {
270 if (index == 0)
271 qubit1 = q;
272 else if (index == 1)
273 qubit2 = q;
274 }
275
285 Types::qubit_t GetQubit(unsigned int index = 0) const override {
286 if (index == 0)
287 return qubit1;
288 else if (index == 1)
289 return qubit2;
290
291 return UINT_MAX;
292 }
293
301 return {qubit1, qubit2};
302 }
303
314 std::shared_ptr<IOperation<Time>> Remap(
315 const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
316 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
317 const override {
318 auto newGate = this->Clone();
319
320 const auto qubitit1 = qubitsMap.find(qubit1);
321 if (qubitit1 != qubitsMap.end())
322 std::static_pointer_cast<TwoQubitsGate<Time>>(newGate)->SetQubit(
323 qubitit1->second, 0);
324
325 const auto qubitit2 = qubitsMap.find(qubit2);
326 if (qubitit2 != qubitsMap.end())
327 std::static_pointer_cast<TwoQubitsGate<Time>>(newGate)->SetQubit(
328 qubitit2->second, 1);
329
330 return newGate;
331 }
332
333 private:
334 Types::qubit_t qubit1;
336 qubit2;
337};
338
348template <typename Time = Types::time_type>
349class ThreeQubitsGate : public IQuantumGate<Time> {
350 public:
364 Types::qubit_t qubit3 = 0, Time delay = 0)
365 : IQuantumGate<Time>(delay),
366 qubit1(qubit1),
367 qubit2(qubit2),
368 qubit3(qubit3) {}
369
376 virtual ~ThreeQubitsGate() {}
377
385 unsigned int GetNumQubits() const override { return 3; }
386
395 void SetQubit(Types::qubit_t q, unsigned long index = 0) override {
396 if (index == 0)
397 qubit1 = q;
398 else if (index == 1)
399 qubit2 = q;
400 else if (index == 2)
401 qubit3 = q;
402 }
403
413 Types::qubit_t GetQubit(unsigned int index = 0) const override {
414 if (index == 0)
415 return qubit1;
416 else if (index == 1)
417 return qubit2;
418 else if (index == 2)
419 return qubit3;
420
421 return UINT_MAX;
422 }
423
432 return {qubit1, qubit2, qubit3};
433 }
434
445 std::shared_ptr<IOperation<Time>> Remap(
446 const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
447 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
448 const override {
449 auto newGate = this->Clone();
450
451 const auto qubitit1 = qubitsMap.find(qubit1);
452 if (qubitit1 != qubitsMap.end())
453 std::static_pointer_cast<ThreeQubitsGate<Time>>(newGate)->SetQubit(
454 qubitit1->second, 0);
455
456 const auto qubitit2 = qubitsMap.find(qubit2);
457 if (qubitit2 != qubitsMap.end())
458 std::static_pointer_cast<ThreeQubitsGate<Time>>(newGate)->SetQubit(
459 qubitit2->second, 1);
460
461 const auto qubitit3 = qubitsMap.find(qubit3);
462 if (qubitit3 != qubitsMap.end())
463 std::static_pointer_cast<ThreeQubitsGate<Time>>(newGate)->SetQubit(
464 qubitit3->second, 2);
465
466 return newGate;
467 }
468
469 private:
470 Types::qubit_t qubit1;
472 qubit2;
473 Types::qubit_t qubit3;
474};
475
476//**********************************************************************************************
477// Single Qubit Gates
478//**********************************************************************************************
479
488template <typename Time = Types::time_type>
489class PhaseGate : public SingleQubitGate<Time> {
490 public:
501 PhaseGate(Types::qubit_t qubit = 0, double lambda = 0, Time delay = 0)
502 : SingleQubitGate<Time>(qubit, delay), lambda(lambda) {}
503
514 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
515 OperationState &state) const override {
516 sim->ApplyP(SingleQubitGate<Time>::GetQubit(), lambda);
517 }
518
525 void SetLambda(double l) { lambda = l; }
526
533 double GetLambda() const { return lambda; }
534
542 QuantumGateType GetGateType() const override {
544 }
545
552 std::shared_ptr<IOperation<Time>> Clone() const override {
553 return std::make_shared<PhaseGate<Time>>(SingleQubitGate<Time>::GetQubit(),
554 lambda,
556 }
557
564 std::vector<double> GetParams() const override { return {lambda}; }
565
575 bool IsClifford() const override {
576 if (std::abs(lambda - M_PI_2) > 1e-10) return false;
577
578 return true;
579 }
580
587 Eigen::MatrixXcd GetMatrix() const override {
588 const QC::Gates::PhaseShiftGate<> pgate(lambda);
589
590 return pgate.getRawOperatorMatrix();
591 }
592
593 private:
594 double lambda;
595};
596
605template <typename Time = Types::time_type>
606class XGate : public SingleQubitGate<Time> {
607 public:
617 XGate(Types::qubit_t qubit = 0, Time delay = 0)
618 : SingleQubitGate<Time>(qubit, delay) {}
619
630 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
631 OperationState &state) const override {
632 sim->ApplyX(SingleQubitGate<Time>::GetQubit());
633 }
634
642 QuantumGateType GetGateType() const override {
644 }
645
652 std::shared_ptr<IOperation<Time>> Clone() const override {
653 return std::make_shared<XGate<Time>>(SingleQubitGate<Time>::GetQubit(),
655 }
656
666 bool IsClifford() const override { return true; }
667
674 Eigen::MatrixXcd GetMatrix() const override {
675 static const QC::Gates::PauliXGate<> xgate;
676
677 return xgate.getRawOperatorMatrix();
678 }
679};
680
689template <typename Time = Types::time_type>
690class YGate : public SingleQubitGate<Time> {
691 public:
701 YGate(Types::qubit_t qubit = 0, Time delay = 0)
702 : SingleQubitGate<Time>(qubit, delay) {}
703
714 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
715 OperationState &state) const override {
716 sim->ApplyY(SingleQubitGate<Time>::GetQubit());
717 }
718
726 QuantumGateType GetGateType() const override {
728 }
729
736 std::shared_ptr<IOperation<Time>> Clone() const override {
737 return std::make_shared<YGate<Time>>(SingleQubitGate<Time>::GetQubit(),
739 }
740
750 bool IsClifford() const override { return true; }
751
758 Eigen::MatrixXcd GetMatrix() const override {
759 static const QC::Gates::PauliYGate<> ygate;
760
761 return ygate.getRawOperatorMatrix();
762 }
763};
764
773template <typename Time = Types::time_type>
774class ZGate : public SingleQubitGate<Time> {
775 public:
785 ZGate(Types::qubit_t qubit = 0, Time delay = 0)
786 : SingleQubitGate<Time>(qubit, delay) {}
787
798 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
799 OperationState &state) const override {
800 sim->ApplyZ(SingleQubitGate<Time>::GetQubit());
801 }
802
810 QuantumGateType GetGateType() const override {
812 }
813
820 std::shared_ptr<IOperation<Time>> Clone() const override {
821 return std::make_shared<ZGate<Time>>(SingleQubitGate<Time>::GetQubit(),
823 }
824
834 bool IsClifford() const override { return true; }
835
842 Eigen::MatrixXcd GetMatrix() const override {
843 static const QC::Gates::PauliZGate<> zgate;
844
845 return zgate.getRawOperatorMatrix();
846 }
847};
848
857template <typename Time = Types::time_type>
858class HadamardGate : public SingleQubitGate<Time> {
859 public:
869 HadamardGate(Types::qubit_t qubit = 0, Time delay = 0)
870 : SingleQubitGate<Time>(qubit, delay) {}
871
882 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
883 OperationState &state) const override {
884 sim->ApplyH(SingleQubitGate<Time>::GetQubit());
885 }
886
897
904 std::shared_ptr<IOperation<Time>> Clone() const override {
905 return std::make_shared<HadamardGate<Time>>(
907 }
908
918 bool IsClifford() const override { return true; }
919
928 bool IsBranching() const override { return true; }
929
936 Eigen::MatrixXcd GetMatrix() const override {
937 static const QC::Gates::HadamardGate<> hgate;
938
939 return hgate.getRawOperatorMatrix();
940 }
941};
942
951template <typename Time = Types::time_type>
952class SGate : public SingleQubitGate<Time> {
953 public:
963 SGate(Types::qubit_t qubit = 0, Time delay = 0)
964 : SingleQubitGate<Time>(qubit, delay) {}
965
976 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
977 OperationState &state) const override {
978 sim->ApplyS(SingleQubitGate<Time>::GetQubit());
979 }
980
988 QuantumGateType GetGateType() const override {
990 }
991
998 std::shared_ptr<IOperation<Time>> Clone() const override {
999 return std::make_shared<SGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1001 }
1002
1012 bool IsClifford() const override { return true; }
1013
1020 Eigen::MatrixXcd GetMatrix() const override {
1021 static const QC::Gates::SGate<> sgate;
1022
1023 return sgate.getRawOperatorMatrix();
1024 }
1025};
1026
1035template <typename Time = Types::time_type>
1036class SdgGate : public SingleQubitGate<Time> {
1037 public:
1047 SdgGate(Types::qubit_t qubit = 0, Time delay = 0)
1048 : SingleQubitGate<Time>(qubit, delay) {}
1049
1060 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1061 OperationState &state) const override {
1062 sim->ApplySDG(SingleQubitGate<Time>::GetQubit());
1063 }
1064
1072 QuantumGateType GetGateType() const override {
1074 }
1075
1082 std::shared_ptr<IOperation<Time>> Clone() const override {
1083 return std::make_shared<SdgGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1085 }
1086
1096 bool IsClifford() const override { return true; }
1097
1104 Eigen::MatrixXcd GetMatrix() const override {
1105 static const QC::Gates::SDGGate<> sdggate;
1106
1107 return sdggate.getRawOperatorMatrix();
1108 }
1109};
1110
1119template <typename Time = Types::time_type>
1120class TGate : public SingleQubitGate<Time> {
1121 public:
1131 TGate(Types::qubit_t qubit = 0, Time delay = 0)
1132 : SingleQubitGate<Time>(qubit, delay) {}
1133
1144 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1145 OperationState &state) const override {
1146 sim->ApplyT(SingleQubitGate<Time>::GetQubit());
1147 }
1148
1156 QuantumGateType GetGateType() const override {
1158 }
1159
1166 std::shared_ptr<IOperation<Time>> Clone() const override {
1167 return std::make_shared<TGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1169 }
1170
1177 Eigen::MatrixXcd GetMatrix() const override {
1178 static const QC::Gates::TGate<> tgate;
1179
1180 return tgate.getRawOperatorMatrix();
1181 }
1182};
1183
1192template <typename Time = Types::time_type>
1193class TdgGate : public SingleQubitGate<Time> {
1194 public:
1204 TdgGate(Types::qubit_t qubit = 0, Time delay = 0)
1205 : SingleQubitGate<Time>(qubit, delay) {}
1206
1217 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1218 OperationState &state) const override {
1219 sim->ApplyTDG(SingleQubitGate<Time>::GetQubit());
1220 }
1221
1229 QuantumGateType GetGateType() const override {
1231 }
1232
1239 std::shared_ptr<IOperation<Time>> Clone() const override {
1240 return std::make_shared<TdgGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1242 }
1243
1250 Eigen::MatrixXcd GetMatrix() const override {
1251 static const QC::Gates::TDGGate<> tdggate;
1252
1253 return tdggate.getRawOperatorMatrix();
1254 }
1255};
1256
1265template <typename Time = Types::time_type>
1266class SxGate : public SingleQubitGate<Time> {
1267 public:
1277 SxGate(Types::qubit_t qubit = 0, Time delay = 0)
1278 : SingleQubitGate<Time>(qubit, delay) {}
1279
1290 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1291 OperationState &state) const override {
1292 sim->ApplySx(SingleQubitGate<Time>::GetQubit());
1293 }
1294
1302 QuantumGateType GetGateType() const override {
1304 }
1305
1312 std::shared_ptr<IOperation<Time>> Clone() const override {
1313 return std::make_shared<SxGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1315 }
1316
1326 bool IsClifford() const override { return true; }
1327
1336 bool IsBranching() const override { return true; }
1337
1344 Eigen::MatrixXcd GetMatrix() const override {
1345 static const QC::Gates::SquareRootNOTGate<> sxgate;
1346 return sxgate.getRawOperatorMatrix();
1347 }
1348 };
1349
1358template <typename Time = Types::time_type>
1359class SxDagGate : public SingleQubitGate<Time> {
1360 public:
1370 SxDagGate(Types::qubit_t qubit = 0, Time delay = 0)
1371 : SingleQubitGate<Time>(qubit, delay) {}
1372
1383 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1384 OperationState &state) const override {
1385 sim->ApplySxDAG(SingleQubitGate<Time>::GetQubit());
1386 }
1387
1395 QuantumGateType GetGateType() const override {
1397 }
1398
1405 std::shared_ptr<IOperation<Time>> Clone() const override {
1406 return std::make_shared<SxDagGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1408 }
1409
1419 bool IsClifford() const override { return true; }
1420
1429 bool IsBranching() const override { return true; }
1430
1437 Eigen::MatrixXcd GetMatrix() const override {
1438 static const QC::Gates::SquareRootNOTDagGate<> sxdggate;
1439 return sxdggate.getRawOperatorMatrix();
1440 }
1441 };
1442
1451template <typename Time = Types::time_type>
1452class KGate : public SingleQubitGate<Time> {
1453 public:
1463 KGate(Types::qubit_t qubit = 0, Time delay = 0)
1464 : SingleQubitGate<Time>(qubit, delay) {}
1465
1476 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1477 OperationState &state) const override {
1478 sim->ApplyK(SingleQubitGate<Time>::GetQubit());
1479 }
1480
1488 QuantumGateType GetGateType() const override {
1490 }
1491
1498 std::shared_ptr<IOperation<Time>> Clone() const override {
1499 return std::make_shared<KGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1501 }
1502
1512 bool IsClifford() const override { return true; }
1513
1522 bool IsBranching() const override { return true; }
1523
1530 Eigen::MatrixXcd GetMatrix() const override {
1531 static const QC::Gates::HyGate<> hygate;
1532 return hygate.getRawOperatorMatrix();
1533 }
1534};
1535
1544template <typename Time = Types::time_type>
1545class RotationGate : public SingleQubitGate<Time> {
1546 public:
1558 RotationGate(Types::qubit_t qubit = 0, double theta = 0, Time delay = 0)
1559 : SingleQubitGate<Time>(qubit, delay), theta(theta) {}
1560
1567 void SetTheta(double t) { theta = t; }
1568
1575 double GetTheta() const { return theta; }
1576
1583 std::vector<double> GetParams() const override { return {theta}; }
1584
1585 private:
1586 double theta;
1587};
1588
1598template <typename Time = Types::time_type>
1599class RxGate : public RotationGate<Time> {
1600 public:
1611 RxGate(Types::qubit_t qubit = 0, double theta = 0, Time delay = 0)
1612 : RotationGate<Time>(qubit, theta, delay) {}
1613
1624 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1625 OperationState &state) const override {
1626 sim->ApplyRx(SingleQubitGate<Time>::GetQubit(),
1628 }
1629
1637 QuantumGateType GetGateType() const override {
1639 }
1640
1647 std::shared_ptr<IOperation<Time>> Clone() const override {
1648 return std::make_shared<RxGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1651 }
1652
1661 bool IsBranching() const override { return true; }
1662
1669 Eigen::MatrixXcd GetMatrix() const override {
1670 const QC::Gates::RxGate<> rxgate(RotationGate<Time>::GetTheta());
1671 return rxgate.getRawOperatorMatrix();
1672 }
1673};
1674
1684template <typename Time = Types::time_type>
1685class RyGate : public RotationGate<Time> {
1686 public:
1697 RyGate(Types::qubit_t qubit = 0, double theta = 0, Time delay = 0)
1698 : RotationGate<Time>(qubit, theta, delay) {}
1699
1710 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1711 OperationState &state) const override {
1712 sim->ApplyRy(SingleQubitGate<Time>::GetQubit(),
1714 }
1715
1723 QuantumGateType GetGateType() const override {
1725 }
1726
1733 std::shared_ptr<IOperation<Time>> Clone() const override {
1734 return std::make_shared<RyGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1737 }
1738
1747 bool IsBranching() const override { return true; }
1748
1755 Eigen::MatrixXcd GetMatrix() const override {
1756 const QC::Gates::RyGate<> rygate(RotationGate<Time>::GetTheta());
1757 return rygate.getRawOperatorMatrix();
1758 }
1759};
1760
1770template <typename Time = Types::time_type>
1771class RzGate : public RotationGate<Time> {
1772 public:
1783 RzGate(Types::qubit_t qubit = 0, double theta = 0, Time delay = 0)
1784 : RotationGate<Time>(qubit, theta, delay) {}
1785
1796 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1797 OperationState &state) const override {
1798 sim->ApplyRz(SingleQubitGate<Time>::GetQubit(),
1800 }
1801
1809 QuantumGateType GetGateType() const override {
1811 }
1812
1819 std::shared_ptr<IOperation<Time>> Clone() const override {
1820 return std::make_shared<RzGate<Time>>(SingleQubitGate<Time>::GetQubit(),
1823 }
1824
1831 Eigen::MatrixXcd GetMatrix() const override {
1832 const QC::Gates::RzGate<> rzgate(RotationGate<Time>::GetTheta());
1833 return rzgate.getRawOperatorMatrix();
1834 }
1835};
1836
1845template <typename Time = Types::time_type>
1846class UGate : public SingleQubitGate<Time> {
1847 public:
1858 UGate(Types::qubit_t qubit = 0, double theta = 0, double phi = 0,
1859 double lambda = 0, double gamma = 0, Time delay = 0)
1860 : SingleQubitGate<Time>(qubit, delay),
1861 theta(theta),
1862 phi(phi),
1863 lambda(lambda),
1864 gamma(gamma) {}
1865
1876 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
1877 OperationState &state) const override {
1878 sim->ApplyU(SingleQubitGate<Time>::GetQubit(), theta, phi, lambda, gamma);
1879 }
1880
1888 QuantumGateType GetGateType() const override {
1890 }
1891
1898 std::shared_ptr<IOperation<Time>> Clone() const override {
1899 return std::make_shared<UGate<Time>>(
1902 }
1903
1910 void SetTheta(double t) { theta = t; }
1911
1918 double GetTheta() const { return theta; }
1919
1926 void SetPhi(double p) { phi = p; }
1927
1934 double GetPhi() const { return phi; }
1935
1942 void SetLambda(double l) { lambda = l; }
1943
1950 double GetLambda() const { return lambda; }
1951
1958 void SetGamma(double g) { gamma = g; }
1959
1966 double GetGamma() const { return gamma; }
1967
1974 std::vector<double> GetParams() const override {
1975 return {theta, phi, lambda, gamma};
1976 }
1977
1987 bool IsClifford() const override { return false; }
1988
1997 bool IsBranching() const override { return true; }
1998
2005 Eigen::MatrixXcd GetMatrix() const override {
2006 const QC::Gates::UGate<> ugate(theta, phi, lambda, gamma);
2007 return ugate.getRawOperatorMatrix();
2008 }
2009
2010 private:
2011 double theta;
2012 double phi;
2013 double lambda;
2014 double gamma;
2015};
2016
2017//**********************************************************************************************
2018// Two Qubit Gates
2019//**********************************************************************************************
2020
2021// this one should be replaced - for example with three qnots - to be able to
2022// distribute it
2023
2032template <typename Time = Types::time_type>
2033class SwapGate : public TwoQubitsGate<Time> {
2034 public:
2045 SwapGate(Types::qubit_t qubit1 = 0, Types::qubit_t qubit2 = 1, Time delay = 0)
2046 : TwoQubitsGate<Time>(qubit1, qubit2, delay) {}
2047
2058 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2059 OperationState &state) const override {
2060 sim->ApplySwap(TwoQubitsGate<Time>::GetQubit(0),
2062 }
2063
2071 QuantumGateType GetGateType() const override {
2073 }
2074
2081 std::shared_ptr<IOperation<Time>> Clone() const override {
2082 return std::make_shared<SwapGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
2085 }
2086
2096 bool IsClifford() const override { return true; }
2097
2104 Eigen::MatrixXcd GetMatrix() const override {
2105 static const QC::Gates::SwapGate<> swapgate;
2106 return swapgate.getRawOperatorMatrix();
2107 }
2108};
2109
2110// the others are all controlled gates
2111
2120template <typename Time = Types::time_type>
2121class CXGate : public TwoQubitsGate<Time> {
2122 public:
2133 CXGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, Time delay = 0)
2134 : TwoQubitsGate<Time>(ctrl, target, delay) {}
2135
2146 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2147 OperationState &state) const override {
2148 sim->ApplyCX(TwoQubitsGate<Time>::GetQubit(0),
2150 }
2151
2159 QuantumGateType GetGateType() const override {
2161 }
2162
2169 std::shared_ptr<IOperation<Time>> Clone() const override {
2170 return std::make_shared<CXGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
2173 }
2174
2184 bool IsClifford() const override { return true; }
2185
2192 Eigen::MatrixXcd GetMatrix() const override {
2193 static const QC::Gates::CNOTGate<> cnotgate;
2194 return cnotgate.getRawOperatorMatrix();
2195 }
2196};
2197
2206template <typename Time = Types::time_type>
2207class CYGate : public TwoQubitsGate<Time> {
2208 public:
2219 CYGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, Time delay = 0)
2220 : TwoQubitsGate<Time>(ctrl, target, delay) {}
2221
2232 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2233 OperationState &state) const override {
2234 sim->ApplyCY(TwoQubitsGate<Time>::GetQubit(0),
2236 }
2237
2245 QuantumGateType GetGateType() const override {
2247 }
2248
2255 std::shared_ptr<IOperation<Time>> Clone() const override {
2256 return std::make_shared<CYGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
2259 }
2260
2270 bool IsClifford() const override { return true; }
2271
2278 Eigen::MatrixXcd GetMatrix() const override {
2279 static const QC::Gates::ControlledYGate<> cygate;
2280 return cygate.getRawOperatorMatrix();
2281 }
2282};
2283
2292template <typename Time = Types::time_type>
2293class CZGate : public TwoQubitsGate<Time> {
2294 public:
2305 CZGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, Time delay = 0)
2306 : TwoQubitsGate<Time>(ctrl, target, delay) {}
2307
2318 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2319 OperationState &state) const override {
2320 sim->ApplyCZ(TwoQubitsGate<Time>::GetQubit(0),
2322 }
2323
2331 QuantumGateType GetGateType() const override {
2333 }
2334
2341 std::shared_ptr<IOperation<Time>> Clone() const override {
2342 return std::make_shared<CZGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
2345 }
2346
2356 bool IsClifford() const override { return true; }
2357
2364 Eigen::MatrixXcd GetMatrix() const override {
2365 static const QC::Gates::ControlledZGate<> czgate;
2366 return czgate.getRawOperatorMatrix();
2367 }
2368};
2369
2378template <typename Time = Types::time_type>
2379class CPGate : public TwoQubitsGate<Time> {
2380 public:
2392 CPGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, double lambda = 0,
2393 Time delay = 0)
2394 : TwoQubitsGate<Time>(ctrl, target, delay), lambda(lambda) {}
2395
2406 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2407 OperationState &state) const override {
2408 sim->ApplyCP(TwoQubitsGate<Time>::GetQubit(0),
2410 }
2411
2418 void SetLambda(double l) { lambda = l; }
2419
2426 double GetLambda() const { return lambda; }
2427
2435 QuantumGateType GetGateType() const override {
2437 }
2438
2445 std::shared_ptr<IOperation<Time>> Clone() const override {
2446 return std::make_shared<CPGate<Time>>(
2449 }
2450
2457 std::vector<double> GetParams() const override { return {lambda}; }
2458
2465 Eigen::MatrixXcd GetMatrix() const override {
2466 const QC::Gates::ControlledPhaseShiftGate<> cpgate(lambda);
2467 return cpgate.getRawOperatorMatrix();
2468 }
2469
2470 private:
2471 double lambda;
2472};
2473
2482template <typename Time = Types::time_type>
2484 public:
2498 double theta = 0, Time delay = 0)
2499 : TwoQubitsGate<Time>(ctrl, target, delay), theta(theta) {}
2500
2507 void SetTheta(double t) { theta = t; }
2508
2515 double GetTheta() const { return theta; }
2516
2523 std::vector<double> GetParams() const override { return {theta}; }
2524
2525 private:
2526 double theta;
2527};
2528
2537template <typename Time = Types::time_type>
2538class CRxGate : public ControlledRotationGate<Time> {
2539 public:
2551 CRxGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, double theta = 0,
2552 Time delay = 0)
2553 : ControlledRotationGate<Time>(ctrl, target, theta, delay) {}
2554
2565 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2566 OperationState &state) const override {
2567 sim->ApplyCRx(TwoQubitsGate<Time>::GetQubit(0),
2570 }
2571
2579 QuantumGateType GetGateType() const override {
2581 }
2582
2589 std::shared_ptr<IOperation<Time>> Clone() const override {
2590 return std::make_shared<CRxGate<Time>>(
2593 }
2594
2603 bool IsBranching() const override { return true; }
2604
2611 Eigen::MatrixXcd GetMatrix() const override {
2612 const QC::Gates::ControlledRxGate<> crxgate(ControlledRotationGate<Time>::GetTheta());
2613 return crxgate.getRawOperatorMatrix();
2614 }
2615};
2616
2625template <typename Time = Types::time_type>
2626class CRyGate : public ControlledRotationGate<Time> {
2627 public:
2639 CRyGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, double theta = 0,
2640 Time delay = 0)
2641 : ControlledRotationGate<Time>(ctrl, target, theta, delay) {}
2642
2653 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2654 OperationState &state) const override {
2655 sim->ApplyCRy(TwoQubitsGate<Time>::GetQubit(0),
2658 }
2659
2667 QuantumGateType GetGateType() const override {
2669 }
2670
2677 std::shared_ptr<IOperation<Time>> Clone() const override {
2678 return std::make_shared<CRyGate<Time>>(
2681 }
2682
2691 bool IsBranching() const override { return true; }
2692
2699 Eigen::MatrixXcd GetMatrix() const override {
2700 const QC::Gates::ControlledRyGate<> crygate(ControlledRotationGate<Time>::GetTheta());
2701 return crygate.getRawOperatorMatrix();
2702 }
2703};
2704
2713template <typename Time = Types::time_type>
2714class CRzGate : public ControlledRotationGate<Time> {
2715 public:
2727 CRzGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, double theta = 0,
2728 Time delay = 0)
2729 : ControlledRotationGate<Time>(ctrl, target, theta, delay) {}
2730
2741 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2742 OperationState &state) const override {
2743 sim->ApplyCRz(TwoQubitsGate<Time>::GetQubit(0),
2746 }
2747
2755 QuantumGateType GetGateType() const override {
2757 }
2758
2765 std::shared_ptr<IOperation<Time>> Clone() const override {
2766 return std::make_shared<CRzGate<Time>>(
2769 }
2770
2777 Eigen::MatrixXcd GetMatrix() const override {
2778 const QC::Gates::ControlledRzGate<> crzgate(ControlledRotationGate<Time>::GetTheta());
2779 return crzgate.getRawOperatorMatrix();
2780 }
2781};
2782
2791template <typename Time = Types::time_type>
2792class CHGate : public TwoQubitsGate<Time> {
2793 public:
2804 CHGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, Time delay = 0)
2805 : TwoQubitsGate<Time>(ctrl, target, delay) {}
2806
2817 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2818 OperationState &state) const override {
2819 sim->ApplyCH(TwoQubitsGate<Time>::GetQubit(0),
2821 }
2822
2830 QuantumGateType GetGateType() const override {
2832 }
2833
2840 std::shared_ptr<IOperation<Time>> Clone() const override {
2841 return std::make_shared<CHGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
2844 }
2845
2854 bool IsBranching() const override { return true; }
2855
2862 Eigen::MatrixXcd GetMatrix() const override {
2863 static const QC::Gates::ControlledHadamardGate<> chgate;
2864 return chgate.getRawOperatorMatrix();
2865 }
2866 };
2867
2876template <typename Time = Types::time_type>
2877class CSxGate : public TwoQubitsGate<Time> {
2878 public:
2889 CSxGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, Time delay = 0)
2890 : TwoQubitsGate<Time>(ctrl, target, delay) {}
2891
2902 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2903 OperationState &state) const override {
2904 sim->ApplyCSx(TwoQubitsGate<Time>::GetQubit(0),
2906 }
2907
2915 QuantumGateType GetGateType() const override {
2917 }
2918
2925 std::shared_ptr<IOperation<Time>> Clone() const override {
2926 return std::make_shared<CSxGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
2929 }
2930
2939 bool IsBranching() const override { return true; }
2940
2947 Eigen::MatrixXcd GetMatrix() const override {
2948 static const QC::Gates::ControlledSquareRootNOTGate<> csxgate;
2949 return csxgate.getRawOperatorMatrix();
2950 }
2951 };
2952
2961template <typename Time = Types::time_type>
2962class CSxDagGate : public TwoQubitsGate<Time> {
2963 public:
2974 CSxDagGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, Time delay = 0)
2975 : TwoQubitsGate<Time>(ctrl, target, delay) {}
2976
2987 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
2988 OperationState &state) const override {
2989 sim->ApplyCSxDAG(TwoQubitsGate<Time>::GetQubit(0),
2991 }
2992
3000 QuantumGateType GetGateType() const override {
3002 }
3003
3010 std::shared_ptr<IOperation<Time>> Clone() const override {
3011 return std::make_shared<CSxDagGate<Time>>(TwoQubitsGate<Time>::GetQubit(0),
3014 }
3015
3024 bool IsBranching() const override { return true; }
3025
3032 Eigen::MatrixXcd GetMatrix() const override {
3033 static const QC::Gates::ControlledSquareRootNOTDagGate<> csxdaggate;
3034 return csxdaggate.getRawOperatorMatrix();
3035 }
3036};
3037
3046template <typename Time = Types::time_type>
3047class CUGate : public TwoQubitsGate<Time> {
3048 public:
3063 CUGate(Types::qubit_t ctrl = 0, Types::qubit_t target = 1, double theta = 0,
3064 double phi = 0, double lambda = 0, double gamma = 0, Time delay = 0)
3065 : TwoQubitsGate<Time>(ctrl, target, delay),
3066 theta(theta),
3067 phi(phi),
3068 lambda(lambda),
3069 gamma(gamma) {}
3070
3081 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
3082 OperationState &state) const override {
3083 sim->ApplyCU(TwoQubitsGate<Time>::GetQubit(0),
3085 GetLambda(), GetGamma());
3086 }
3087
3095 QuantumGateType GetGateType() const override {
3097 }
3098
3105 void SetTheta(double t) { theta = t; }
3106
3113 double GetTheta() const { return theta; }
3114
3121 void SetPhi(double p) { phi = p; }
3122
3129 double GetPhi() const { return phi; }
3130
3137 void SetLambda(double l) { lambda = l; }
3138
3145 double GetLambda() const { return lambda; }
3146
3153 void SetGamma(double g) { gamma = g; }
3154
3161 double GetGamma() const { return gamma; }
3162
3169 std::shared_ptr<IOperation<Time>> Clone() const override {
3170 return std::make_shared<CUGate<Time>>(
3172 GetTheta(), GetPhi(), GetLambda(), GetGamma(),
3174 }
3175
3182 std::vector<double> GetParams() const override {
3183 return {theta, phi, lambda, gamma};
3184 }
3185
3194 bool IsBranching() const override { return true; }
3195
3202 Eigen::MatrixXcd GetMatrix() const override {
3203 const QC::Gates::ControlledUGate<> cugate(theta, phi, lambda, gamma);
3204 return cugate.getRawOperatorMatrix();
3205 }
3206
3207 private:
3208 double theta;
3209 double phi;
3210 double lambda;
3211 double gamma;
3212};
3213
3214//**********************************************************************************************
3215// Three Qubit Gates
3216// those should be replaced by sets of gates with less qubits, to be able to
3217// distribute them
3218//**********************************************************************************************
3219
3228template <typename Time = Types::time_type>
3229class CCXGate : public ThreeQubitsGate<Time> {
3230 public:
3243 Types::qubit_t target = 2, Time delay = 0)
3244 : ThreeQubitsGate<Time>(ctrl1, ctrl2, target, delay) {}
3245
3256 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
3257 OperationState &state) const override {
3258 sim->ApplyCCX(ThreeQubitsGate<Time>::GetQubit(0),
3261 }
3262
3270 QuantumGateType GetGateType() const override {
3272 }
3273
3280 std::shared_ptr<IOperation<Time>> Clone() const override {
3281 return std::make_shared<CCXGate<Time>>(
3284 }
3285
3292 Eigen::MatrixXcd GetMatrix() const override {
3293 static const QC::Gates::ToffoliGate<> ccxaggate;
3294 return ccxaggate.getRawOperatorMatrix();
3295 }
3296};
3297
3306template <typename Time = Types::time_type>
3307class CSwapGate : public ThreeQubitsGate<Time> {
3308 public:
3321 Types::qubit_t target2 = 2, Time delay = 0)
3322 : ThreeQubitsGate<Time>(ctrl, target1, target2, delay) {}
3323
3334 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
3335 OperationState &state) const override {
3336 sim->ApplyCSwap(ThreeQubitsGate<Time>::GetQubit(0),
3339 }
3340
3348 QuantumGateType GetGateType() const override {
3350 }
3351
3358 std::shared_ptr<IOperation<Time>> Clone() const override {
3359 return std::make_shared<CSwapGate<Time>>(
3362 }
3363
3370 Eigen::MatrixXcd GetMatrix() const override {
3371 static const QC::Gates::FredkinGate<> cswapgate;
3372 return cswapgate.getRawOperatorMatrix();
3373 }
3374};
3375
3376} // namespace Circuits
3377
3378#endif // !_QUANTUM_GATES_H_
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
CCXGate(Types::qubit_t ctrl1=0, Types::qubit_t ctrl2=1, Types::qubit_t target=2, Time delay=0)
CCXGate constructor.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsBranching() const override
Checks if the operation is a branching one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
CHGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, Time delay=0)
CHGate constructor.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void SetLambda(double l)
Set the lambda parameter for the controlled phase gate.
double GetLambda() const
Get the lambda parameter for the controlled phase gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
CPGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, double lambda=0, Time delay=0)
CPGate constructor.
std::vector< double > GetParams() const override
Get the gate parameters.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
CRxGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, double theta=0, Time delay=0)
CRxGate constructor.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
bool IsBranching() const override
Checks if the operation is a branching one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
CRyGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, double theta=0, Time delay=0)
CRyGate constructor.
bool IsBranching() const override
Checks if the operation is a branching one.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
CRzGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, double theta=0, Time delay=0)
CRzGate constructor.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
CSwapGate(Types::qubit_t ctrl=0, Types::qubit_t target1=1, Types::qubit_t target2=2, Time delay=0)
CSwapGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
bool IsBranching() const override
Checks if the operation is a branching one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
CSxDagGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, Time delay=0)
CSxDagGate constructor.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
bool IsBranching() const override
Checks if the operation is a branching one.
CSxGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, Time delay=0)
CSxGate constructor.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void SetLambda(double l)
Set the lambda parameter for the controlled U gate.
double GetLambda() const
Get the lambda parameter for the controlled U gate.
CUGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, double theta=0, double phi=0, double lambda=0, double gamma=0, Time delay=0)
CUGate constructor.
double GetPhi() const
Get the phi parameter for the controlled U gate.
void SetPhi(double p)
Set the phi parameter for the controlled U gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
bool IsBranching() const override
Checks if the operation is a branching one.
double GetTheta() const
Get the theta parameter for the controlled U gate.
void SetTheta(double t)
Set the theta parameter for the controlled U gate.
std::vector< double > GetParams() const override
Get the gate parameters.
double GetGamma() const
Get the gamma parameter for the controlled U gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
void SetGamma(double g)
Set the gamma parameter for the controlled U gate.
CXGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, Time delay=0)
CXGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
CYGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, Time delay=0)
CYGate constructor.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
CZGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, Time delay=0)
CZGate constructor.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
ControlledRotationGate(Types::qubit_t ctrl=0, Types::qubit_t target=1, double theta=0, Time delay=0)
ControlledRotationGate constructor.
double GetTheta() const
Get the theta angle for the controlled rotation gate.
void SetTheta(double t)
Set the theta angle for the controlled rotation gate.
std::vector< double > GetParams() const override
Get the gate parameters.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
HadamardGate(Types::qubit_t qubit=0, Time delay=0)
HadamardGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsBranching() const override
Checks if the operation is a branching one.
bool IsClifford() const override
Checks if the operation is a Clifford one.
IGateOperation(Types::time_type delay=0)
Definition Operations.h:622
Time GetDelay() const
Get the delay of the operation.
Definition Operations.h:497
virtual std::shared_ptr< IOperation< Types::time_type > > Clone() const =0
IQuantumGate(Time delay=0)
IQuantumGate constructor.
virtual QuantumGateType GetGateType() const =0
Get the type of the quantum gate.
virtual Eigen::MatrixXcd GetMatrix() const =0
Get the matrix representation of the quantum gate.
virtual std::vector< double > GetParams() const
Get the gate parameters.
bool IsClifford() const override
Checks if the operation is a Clifford one.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
bool IsBranching() const override
Checks if the operation is a branching one.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
KGate(Types::qubit_t qubit=0, Time delay=0)
KGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:63
double GetLambda() const
Get the lambda parameter for the phase gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
std::vector< double > GetParams() const override
Get the gate parameters.
void SetLambda(double l)
Set the lambda parameter for the phase gate.
PhaseGate(Types::qubit_t qubit=0, double lambda=0, Time delay=0)
PhaseGate constructor.
bool IsClifford() const override
Checks if the operation is a Clifford one.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
RotationGate(Types::qubit_t qubit=0, double theta=0, Time delay=0)
RotationGate constructor.
double GetTheta() const
Get the theta angle for the rotation gate.
std::vector< double > GetParams() const override
Get the gate parameters.
void SetTheta(double t)
Set the theta angle for the rotation gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
RxGate(Types::qubit_t qubit=0, double theta=0, Time delay=0)
RxGate constructor.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsBranching() const override
Checks if the operation is a branching one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
bool IsBranching() const override
Checks if the operation is a branching one.
RyGate(Types::qubit_t qubit=0, double theta=0, Time delay=0)
RyGate constructor.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
RzGate(Types::qubit_t qubit=0, double theta=0, Time delay=0)
RzGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
SGate(Types::qubit_t qubit=0, Time delay=0)
SGate constructor.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
SdgGate(Types::qubit_t qubit=0, Time delay=0)
SdgGate constructor.
void SetQubit(Types::qubit_t q, unsigned long index=0) override
Set the qubit the quantum gate is applied to.
SingleQubitGate(Types::qubit_t qubit=0, Time delay=0)
SingleQubitGate constructor.
virtual ~SingleQubitGate()
The SingleQubitGate destructor.
Types::qubits_vector AffectedQubits() const override
Get the qubits the quantum gate is applied to.
unsigned int GetNumQubits() const override
Get the number of qubits the quantum gate is applied to.
Types::qubit_t GetQubit(unsigned int index=0) const override
Get the qubit the quantum gate is applied to.
std::shared_ptr< IOperation< Time > > Remap(const std::unordered_map< Types::qubit_t, Types::qubit_t > &qubitsMap, const std::unordered_map< Types::qubit_t, Types::qubit_t > &bitsMap={}) const override
Get a shared pointer to a remapped operation.
SwapGate(Types::qubit_t qubit1=0, Types::qubit_t qubit2=1, Time delay=0)
SwapGate constructor.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
bool IsBranching() const override
Checks if the operation is a branching one.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
SxDagGate(Types::qubit_t qubit=0, Time delay=0)
SxDagGate constructor.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
bool IsBranching() const override
Checks if the operation is a branching one.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
SxGate(Types::qubit_t qubit=0, Time delay=0)
SxGate constructor.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
TGate(Types::qubit_t qubit=0, Time delay=0)
TGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
TdgGate(Types::qubit_t qubit=0, Time delay=0)
TdgGate constructor.
Types::qubits_vector AffectedQubits() const override
Get the qubits the quantum gate is applied to.
Types::qubit_t GetQubit(unsigned int index=0) const override
Get the qubit the quantum gate is applied to.
unsigned int GetNumQubits() const override
Get the number of qubits the quantum gate is applied to.
std::shared_ptr< IOperation< Time > > Remap(const std::unordered_map< Types::qubit_t, Types::qubit_t > &qubitsMap, const std::unordered_map< Types::qubit_t, Types::qubit_t > &bitsMap={}) const override
Get a shared pointer to a remapped operation.
ThreeQubitsGate(Types::qubit_t qubit1=0, Types::qubit_t qubit2=0, Types::qubit_t qubit3=0, Time delay=0)
ThreeQubitsGate constructor.
virtual ~ThreeQubitsGate()
The ThreeQubitsGate destructor.
void SetQubit(Types::qubit_t q, unsigned long index=0) override
Set the qubit the quantum gate is applied to.
Types::qubit_t GetQubit(unsigned int index=0) const override
Get the qubit the quantum gate is applied to.
std::shared_ptr< IOperation< Time > > Remap(const std::unordered_map< Types::qubit_t, Types::qubit_t > &qubitsMap, const std::unordered_map< Types::qubit_t, Types::qubit_t > &bitsMap={}) const override
Get a shared pointer to a remapped operation.
virtual ~TwoQubitsGate()
The TwoQubitsGate destructor.
void SetQubit(Types::qubit_t q, unsigned long index=0) override
Set the qubit the quantum gate is applied to.
TwoQubitsGate(Types::qubit_t qubit1=0, Types::qubit_t qubit2=0, Time delay=0)
TwoQubitsGate constructor.
unsigned int GetNumQubits() const override
Get the number of qubits the quantum gate is applied to.
Types::qubits_vector AffectedQubits() const override
Get the qubits the quantum gate is applied to.
double GetGamma() const
Get the gamma parameter for the gate.
void SetLambda(double l)
Set the lambda parameter for the gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
bool IsBranching() const override
Checks if the operation is a branching one.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void SetPhi(double p)
Set the phi parameter for the gate.
double GetLambda() const
Get the lambda parameter for the gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
void SetTheta(double t)
Set the theta parameter for the gate.
UGate(Types::qubit_t qubit=0, double theta=0, double phi=0, double lambda=0, double gamma=0, Time delay=0)
UGate constructor.
std::vector< double > GetParams() const override
Get the gate parameters.
double GetTheta() const
Get the theta parameter for the gate.
double GetPhi() const
Get the phi parameter for the gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
void SetGamma(double g)
Set the gamma parameter for the gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
XGate(Types::qubit_t qubit=0, Time delay=0)
XGate constructor.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
YGate(Types::qubit_t qubit=0, Time delay=0)
YGate constructor.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
bool IsClifford() const override
Checks if the operation is a Clifford one.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the quantum gate.
QuantumGateType GetGateType() const override
Get the type of the quantum gate.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
bool IsClifford() const override
Checks if the operation is a Clifford one.
ZGate(Types::qubit_t qubit=0, Time delay=0)
ZGate constructor.
QuantumGateType
The type of quantum gates.
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
Definition Types.h:22
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:21