|
| 1 | +/** |
| 2 | + * @file gates.hh |
| 3 | + * @license This file is licensed under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. You may obtain a copy of this license at https://www.gnu.org/licenses/gpl-3.0.en.html. |
| 4 | + * @author Tushar Chaurasia (Dark-CodeX) |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef SIMULATOR_GATES |
| 8 | +#define SIMULATOR_GATES |
| 9 | + |
| 10 | +#include <complex> |
| 11 | +#include <cmath> // for sqrt and M_PI |
| 12 | + |
| 13 | +namespace simulator |
| 14 | +{ |
| 15 | + using complex = std::complex<double>; |
| 16 | + using namespace std::complex_literals; |
| 17 | + |
| 18 | + enum gates : unsigned char |
| 19 | + { |
| 20 | + IDENTITY, // identity-gate |
| 21 | + PAULI_X, // NOT-gate |
| 22 | + PAULI_Y, |
| 23 | + PAULI_Z, // Phase Flip gate |
| 24 | + HADAMARD, // H-gate |
| 25 | + PHASE_PI_2_SHIFT, // pi/2 phase shift |
| 26 | + PHASE_PI_4_SHIFT, // pi/4 phase shift |
| 27 | + PHASE_GENERAL_SHIFT, |
| 28 | + ROTATION_X, |
| 29 | + ROTATION_Y, |
| 30 | + ROTATION_Z |
| 31 | + }; |
| 32 | + |
| 33 | + struct qgate |
| 34 | + { |
| 35 | + gates type; |
| 36 | + complex matrix[2][2]; // 2x2 matrix that stores various types of gates |
| 37 | + }; |
| 38 | + |
| 39 | + inline const constexpr qgate pre_defined_qgates[7] = { |
| 40 | + {IDENTITY, {{1, 0}, {0, 1}}}, |
| 41 | + {PAULI_X, {{0, 1}, {1, 0}}}, |
| 42 | + {PAULI_Y, {{0, {0, -1}}, {{0, 1}, 0}}}, |
| 43 | + {PAULI_Z, {{1, 0}, {0, -1}}}, |
| 44 | + {HADAMARD, {{1.0 / M_SQRT2, 1.0 / M_SQRT2}, {1.0 / M_SQRT2, -1.0 / M_SQRT2}}}, |
| 45 | + {PHASE_PI_2_SHIFT, {{1, 0}, {0, {0, 1}}}}, // e^(i * pi/2) = i |
| 46 | + {PHASE_PI_4_SHIFT, {{1, 0}, {0, {M_SQRT1_2, M_SQRT1_2}}}} // e^(i * pi/4) = (sqrt(2)/2) + i(sqrt(2)/2) |
| 47 | + }; |
| 48 | + |
| 49 | + void apply_predefined_gate(const enum gates &__g_type, complex (&__s)[2]); |
| 50 | + |
| 51 | + qgate &get_theta_gates(qgate &__g, const enum gates &__g_type, const double &theta); |
| 52 | + |
| 53 | + void apply_theta_gates(const enum gates &__g_type, complex (&__s)[2], const double &theta); |
| 54 | +} |
| 55 | + |
| 56 | +#endif |
0 commit comments