32 #ifndef CLASSES_STATES_H_ 33 #define CLASSES_STATES_H_ 40 class States final :
public internal::Singleton<const States>
42 friend class internal::Singleton<const States>;
54 cmat px0{cmat::Zero(2, 2)};
56 cmat px1{cmat::Zero(2, 2)};
58 cmat py0{cmat::Zero(2, 2)};
60 cmat py1{cmat::Zero(2, 2)};
62 cmat pz0{cmat::Zero(2, 2)};
64 cmat pz1{cmat::Zero(2, 2)};
68 ket b00{ket::Zero(4)};
70 ket b01{ket::Zero(4)};
72 ket b10{ket::Zero(4)};
74 ket b11{ket::Zero(4)};
78 cmat pb00{cmat::Zero(4, 4)};
79 cmat pb01{cmat::Zero(4, 4)};
80 cmat pb10{cmat::Zero(4, 4)};
81 cmat pb11{cmat::Zero(4, 4)};
84 ket GHZ{ket::Zero(8)};
88 cmat pGHZ{cmat::Zero(8, 8)};
89 cmat pW{cmat::Zero(8, 8)};
98 ket mes(idx d = 2)
const {
103 throw exception::DimsInvalid(
"qpp::States::mes()");
106 ket psi = mket({0, 0}, {d, d});
107 for (idx i = 1; i < d; ++i) {
108 psi += mket({i, i}, {d, d});
111 return psi / std::sqrt(d);
121 ket zero(idx n, idx d = 2)
const {
126 throw exception::OutOfRange(
"qpp::States::zero()");
129 throw exception::DimsInvalid(
"qpp::States::zero()");
132 idx D =
static_cast<idx
>(std::llround(std::pow(d, n)));
133 ket result = ket::Zero(D);
146 ket one(idx n, idx d = 2)
const {
151 throw exception::OutOfRange(
"qpp::States::one()");
154 throw exception::DimsInvalid(
"qpp::States::one()");
157 ket result = ket::Zero(static_cast<ket::Index>(std::pow(d, n)));
158 result(multiidx2n(std::vector<idx>(n, 1), std::vector<idx>(n, d))) = 1;
171 ket jn(idx j, idx n, idx d = 2)
const {
176 throw exception::OutOfRange(
"qpp::States::jn()");
179 throw exception::SubsysMismatchDims(
"qpp::States::jn()");
183 throw exception::DimsInvalid(
"qpp::States::jn()");
186 ket result = ket::Zero(static_cast<ket::Index>(std::pow(d, n)));
187 result(multiidx2n(std::vector<idx>(n, j), std::vector<idx>(n, d))) = 1;
198 ket plus(idx n)
const {
203 throw exception::OutOfRange(
"qpp::States::plus()");
206 idx D =
static_cast<idx
>(std::llround(std::pow(2, n)));
207 ket result = ket::Ones(D);
209 return result / std::sqrt(D);
218 ket minus(idx n)
const {
223 throw exception::OutOfRange(
"qpp::States::minus()");
226 return kronpow(x1, n);
235 x0 << 1 / std::sqrt(2.), 1 / std::sqrt(2.);
236 x1 << 1 / std::sqrt(2.), -1 / std::sqrt(2.);
237 y0 << 1 / std::sqrt(2.), 1_i / std::sqrt(2.);
238 y1 << 1 / std::sqrt(2.), -1_i / std::sqrt(2.);
241 px0 = x0 * x0.adjoint();
242 px1 = x1 * x1.adjoint();
243 py0 = y0 * y0.adjoint();
244 py1 = y1 * y1.adjoint();
245 pz0 = z0 * z0.adjoint();
246 pz1 = z1 * z1.adjoint();
251 b00 << 1 / std::sqrt(2.), 0, 0, 1 / std::sqrt(2.);
253 b01 << 0, 1 / std::sqrt(2.), 1 / std::sqrt(2.), 0;
255 b10 << 1 / std::sqrt(2.), 0, 0, -1 / std::sqrt(2.);
257 b11 << 0, 1 / std::sqrt(2.), -1 / std::sqrt(2.), 0;
260 pb00 = b00 * b00.adjoint();
261 pb01 = b01 * b01.adjoint();
262 pb10 = b10 * b10.adjoint();
263 pb11 = b11 * b11.adjoint();
265 GHZ << 1, 0, 0, 0, 0, 0, 0, 1;
266 GHZ = GHZ / std::sqrt(2.);
267 W << 0, 1, 1, 0, 1, 0, 0, 0;
268 W = W / std::sqrt(3.);
270 pGHZ = GHZ * GHZ.adjoint();
271 pW = W * W.adjoint();
Quantum++ main namespace.
Definition: circuits.h:35