Quantum++  v0.7
C++11 quantum computing library
codes.h
Go to the documentation of this file.
1 /*
2  * Quantum++
3  *
4  * Copyright (c) 2013 - 2015 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_CODES_H_
28 #define CLASSES_CODES_H_
29 
30 namespace qpp
31 {
32 
37 class Codes : public internal::Singleton<const Codes> // const Singleton
38 {
39  friend class internal::Singleton<const Codes>;
40 
41 public:
46  enum class Type // exception types
47  {
48  FIVE_QUBIT = 1,
51  };
52 
53 private:
57  Codes() = default;
58 
62  ~Codes() = default;
63 
64 public:
73  ket codeword(Type type, idx i) const
74  {
75  ket result;
76  switch (type)
77  {
78  // [[5,1,3]] Five qubit code according to Nielsen and Chuang)
79  case Type::FIVE_QUBIT:
80  switch (i)
81  {
82  case 0:
83  result = (mket({0, 0, 0, 0, 0}) +
84  mket({1, 0, 0, 1, 0}) +
85  mket({0, 1, 0, 0, 1}) +
86  mket({1, 0, 1, 0, 0}) +
87  mket({0, 1, 0, 1, 0}) -
88  mket({1, 1, 0, 1, 1}) -
89  mket({0, 0, 1, 1, 0}) -
90  mket({1, 1, 0, 0, 0}) -
91  mket({1, 1, 1, 0, 1}) -
92  mket({0, 0, 0, 1, 1}) -
93  mket({1, 1, 1, 1, 0}) -
94  mket({0, 1, 1, 1, 1}) -
95  mket({1, 0, 0, 0, 1}) -
96  mket({0, 1, 1, 0, 0}) -
97  mket({1, 0, 1, 1, 1}) +
98  mket({0, 0, 1, 0, 1}))
99  / 4.;
100  break;
101  case 1:
102  result = (mket({1, 1, 1, 1, 1}) +
103  mket({0, 1, 1, 0, 1}) +
104  mket({1, 0, 1, 1, 0}) +
105  mket({0, 1, 0, 1, 1}) +
106  mket({1, 0, 1, 0, 1}) -
107  mket({0, 0, 1, 0, 0}) -
108  mket({1, 1, 0, 0, 1}) -
109  mket({0, 0, 1, 1, 1}) -
110  mket({0, 0, 0, 1, 0}) -
111  mket({1, 1, 1, 0, 0}) -
112  mket({0, 0, 0, 0, 1}) -
113  mket({1, 0, 0, 0, 0}) -
114  mket({0, 1, 1, 1, 0}) -
115  mket({1, 0, 0, 1, 1}) -
116  mket({0, 1, 0, 0, 0}) +
117  mket({1, 1, 0, 1, 0}))
118  / 4.;
119  break;
120  default:
121  throw Exception("qpp::Codes::codeword()",
123  }
124  break;
125  // [[7,1,3]] Steane code according to Nielsen and Chuang)
127  switch (i)
128  {
129  case 0:
130  result = (mket({0, 0, 0, 0, 0, 0, 0}) +
131  mket({1, 0, 1, 0, 1, 0, 1}) +
132  mket({0, 1, 1, 0, 0, 1, 1}) +
133  mket({1, 1, 0, 0, 1, 1, 0}) +
134  mket({0, 0, 0, 1, 1, 1, 1}) +
135  mket({1, 0, 1, 1, 0, 1, 0}) +
136  mket({0, 1, 1, 1, 1, 0, 0}) +
137  mket({1, 1, 0, 1, 0, 0, 1})) /
138  std::sqrt(8.);
139 
140  break;
141  case 1:
142  result = (mket({1, 1, 1, 1, 1, 1, 1}) +
143  mket({0, 1, 0, 1, 0, 1, 0}) +
144  mket({1, 0, 0, 1, 1, 0, 0}) +
145  mket({0, 0, 1, 1, 0, 0, 1}) +
146  mket({1, 1, 1, 0, 0, 0, 0}) +
147  mket({0, 1, 0, 0, 1, 0, 1}) +
148  mket({1, 0, 0, 0, 0, 1, 1}) +
149  mket({0, 0, 1, 0, 1, 1, 0})) /
150  std::sqrt(8.);
151  break;
152  default:
153  throw Exception("qpp::Codes::codeword()",
155  }
156  break;
157  // [[9,1,3]] Shor code
159  ket shora, shorb;
160  shora = mket({0, 0, 0}) + mket({1, 1, 1,});
161  shorb = mket({0, 0, 0}) - mket({1, 1, 1,});
162  switch (i)
163  {
164  case 0:
165  result = kron(shora, kron(shora, shora))
166  / std::sqrt(8.);
167  break;
168  case 1:
169  result = kron(shorb, kron(shorb, shorb))
170  / std::sqrt(8.);
171  break;
172  default:
173  throw Exception("qpp::Codes::codeword()",
175  }
176  }
177 
178  return result;
179  }
180 }; /* class Codes */
181 
182 } /* namespace qpp */
183 
184 #endif /* CLASSES_CODES_H_ */
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:46
Quantum++ main namespace.
Definition: codes.h:30
Type
Code types, add more codes here if needed.
Definition: codes.h:46
const Singleton class that defines quantum error correcting codes
Definition: codes.h:37
[[7,1,3]] Steane qubit code
dyn_mat< typename T::Scalar > kron(const T &head)
Kronecker product.
Definition: functions.h:798
[[9,1,3]] Shor qubit code
Generates custom exceptions, used when validating function parameters.
Definition: exception.h:39
ket mket(const std::vector< idx > &mask, const std::vector< idx > &dims)
Multi-partite qudit ket.
Definition: functions.h:1333
std::size_t idx
Non-negative integer index.
Definition: types.h:36
ket codeword(Type type, idx i) const
Returns the codeword of the specified code type.
Definition: codes.h:73
[[5,1,3]] qubit code