Quantum++  v1.0.0-beta3
C++11 quantum computing library
states.h
Go to the documentation of this file.
1 /*
2  * Quantum++
3  *
4  * Copyright (c) 2013 - 2017 Vlad Gheorghiu (vgheorgh@gmail.com)
5  *
6  * This file is part of Quantum++.
7  *
8  * Quantum++ is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Quantum++ is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Quantum++. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 #ifndef CLASSES_STATES_H_
28 #define CLASSES_STATES_H_
29 
30 namespace qpp
31 {
32 
37 class States final : public internal::Singleton<const States> // const Singleton
38 {
39  friend class internal::Singleton<const States>;
40 
41 public:
42  // Pauli eigen-states
43  ket x0{ket::Zero(2)};
44  ket x1{ket::Zero(2)};
45  ket y0{ket::Zero(2)};
46  ket y1{ket::Zero(2)};
47  ket z0{ket::Zero(2)};
48  ket z1{ket::Zero(2)};
49 
50  // projectors onto Pauli eigen-states
51  cmat px0{cmat::Zero(2, 2)};
53  cmat px1{cmat::Zero(2, 2)};
55  cmat py0{cmat::Zero(2, 2)};
57  cmat py1{cmat::Zero(2, 2)};
59  cmat pz0{cmat::Zero(2, 2)};
61  cmat pz1{cmat::Zero(2, 2)};
63 
64  // Bell states
65  ket b00{ket::Zero(4)};
67  ket b01{ket::Zero(4)};
69  ket b10{ket::Zero(4)};
71  ket b11{ket::Zero(4)};
73 
74  // projectors onto Bell states
75  cmat pb00{cmat::Zero(4, 4)};
76  cmat pb01{cmat::Zero(4, 4)};
77  cmat pb10{cmat::Zero(4, 4)};
78  cmat pb11{cmat::Zero(4, 4)};
79 
80  // W and GHZ states
81  ket GHZ{ket::Zero(8)};
82  ket W{ket::Zero(8)};
83 
84  // projectors onto GHZ and W
85  cmat pGHZ{cmat::Zero(8, 8)};
86  cmat pW{cmat::Zero(8, 8)};
87 
95  ket mes(idx d = 2) const
96  {
97  // EXCEPTION CHECKS
98 
99  // check valid dims
100  if (d == 0)
101  throw Exception("qpp::States::mes()",
103  // END EXCEPTION CHECKS
104 
105  ket psi = mket({0, 0}, {d, d});
106  for(idx i = 1; i < d; ++i)
107  {
108  psi += mket({i, i}, {d, d});
109  }
110 
111  return psi/std::sqrt(d);
112  }
113 
114 private:
119  {
120  // initialize
121  x0 << 1 / std::sqrt(2.), 1 / std::sqrt(2.);
122  x1 << 1 / std::sqrt(2.), -1 / std::sqrt(2.);
123  y0 << 1 / std::sqrt(2.), 1_i / std::sqrt(2.);
124  y1 << 1 / std::sqrt(2.), -1_i / std::sqrt(2.);
125  z0 << 1, 0;
126  z1 << 0, 1;
127  px0 = x0 * x0.adjoint();
128  px1 = x1 * x1.adjoint();
129  py0 = y0 * y0.adjoint();
130  py1 = y1 * y1.adjoint();
131  pz0 = z0 * z0.adjoint();
132  pz1 = z1 * z1.adjoint();
133 
134  // Bell states, following convention from Nielsen & Chuang
135  // |ij> -> |b_{ij}> by the CNOT*(H x Id) circuit
136 
137  b00 << 1 / std::sqrt(2.), 0, 0, 1 / std::sqrt(2.);
138  // (|00> + |11>) / sqrt(2)
139  b01 << 0, 1 / std::sqrt(2.), 1 / std::sqrt(2.), 0;
140  // (|01> + |10>) / sqrt(2)
141  b10 << 1 / std::sqrt(2.), 0, 0, -1 / std::sqrt(2.);
142  // (|00> - |11>) / sqrt(2)
143  b11 << 0, 1 / std::sqrt(2.), -1 / std::sqrt(2.), 0;
144  // (|01> - |10>) / sqrt(2)
145 
146  pb00 = b00 * b00.adjoint();
147  pb01 = b01 * b01.adjoint();
148  pb10 = b10 * b10.adjoint();
149  pb11 = b11 * b11.adjoint();
150 
151  GHZ << 1, 0, 0, 0, 0, 0, 0, 1;
152  GHZ = GHZ / std::sqrt(2.);
153  W << 0, 1, 1, 0, 1, 0, 0, 0;
154  W = W / std::sqrt(3.);
155 
156  pGHZ = GHZ * GHZ.adjoint();
157  pW = W * W.adjoint();
158  }
159 
163  ~States() = default;
164 }; /* class States */
165 
166 } /* namespace qpp */
167 
168 #endif /* CLASSES_STATES_H_ */
ket W
W state.
Definition: states.h:82
cmat pb01
Projector onto the Bell-01 state.
Definition: states.h:76
ket GHZ
GHZ state.
Definition: states.h:81
cmat pb11
Projector onto the Bell-11 state.
Definition: states.h:78
Singleton policy class, used internally to implement the singleton pattern via CRTP (Curiously recurr...
Definition: singleton.h:77
Eigen::VectorXcd ket
Complex (double precision) dynamic Eigen column vector.
Definition: types.h:51
ket y0
Pauli Sigma-Y 0-eigenstate |y+>
Definition: states.h:45
Quantum++ main namespace.
Definition: codes.h:30
const Singleton class that implements most commonly used states
Definition: states.h:37
cmat pb00
Projector onto the Bell-00 state.
Definition: states.h:75
ket z1
Pauli Sigma-Z 1-eigenstate |1>
Definition: states.h:48
ket b01
Bell-01 state (following the convention in Nielsen and Chuang)
Definition: states.h:67
ket b00
Bell-00 state (following the convention in Nielsen and Chuang)
Definition: states.h:65
ket mes(idx d=2) const
Maximally entangled state of 2 qudits.
Definition: states.h:95
cmat pb10
Projector onto the Bell-10 state.
Definition: states.h:77
cmat pW
Projector onto the W state.
Definition: states.h:86
~States()=default
Default destructor.
cmat py0
Projector onto the Pauli Sigma-Y 0-eigenstate |y+>
Definition: states.h:55
Generates custom exceptions, used when validating function parameters.
Definition: exception.h:39
cmat px0
Projector onto the Pauli Sigma-X 0-eigenstate |+><+|.
Definition: states.h:51
ket x1
Pauli Sigma-X 1-eigenstate |->
Definition: states.h:44
ket y1
Pauli Sigma-Y 1-eigenstate |y->
Definition: states.h:46
ket z0
Pauli Sigma-Z 0-eigenstate |0>
Definition: states.h:47
ket b11
Bell-11 state (following the convention in Nielsen and Chuang)
Definition: states.h:71
cmat pz0
Projector onto the Pauli Sigma-Z 0-eigenstate |0><0|.
Definition: states.h:59
cmat pGHZ
Projector onto the GHZ state.
Definition: states.h:85
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:61
ket mket(const std::vector< idx > &mask, const std::vector< idx > &dims)
Multi-partite qudit ket.
Definition: functions.h:1464
std::size_t idx
Non-negative integer index.
Definition: types.h:36
ket b10
Bell-10 state (following the convention in Nielsen and Chuang)
Definition: states.h:69
ket x0
Pauli Sigma-X 0-eigenstate |+>
Definition: states.h:43
cmat py1
Projector onto the Pauli Sigma-Y 1-eigenstate |y->
Definition: states.h:57
cmat px1
Projector onto the Pauli Sigma-X 1-eigenstate |-><-|.
Definition: states.h:53
cmat pz1
Projector onto the Pauli Sigma-Z 1-eigenstate |1><1|.
Definition: states.h:61
States()
Definition: states.h:118