Tomographer  v1.0a
Tomographer C++ Framework Documentation
param_rho_a.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2015 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #ifndef QIT_PARAM_RHO_A_H
28 #define QIT_PARAM_RHO_A_H
29 
37 #include <Eigen/Core>
38 #include <Eigen/StdVector>
39 
40 #include <tomographer/qit/matrq.h>
41 #include <tomographer/qit/util.h>
42 
43 #include <boost/math/constants/constants.hpp>
44 
45 
46 namespace Tomographer
47 {
48 
49 // based on http://mathworld.wolfram.com/GeneralizedGell-MannMatrix.html
50 
51 namespace tomo_internal
52 {
53 
54 template<typename MatrQ_, typename Coeffs>
55 struct GenGellMannFunctor12
56 {
57  typedef MatrQ_ MatrQ;
58  typedef typename MatrQ::MatrixType::Index MatIndex;
59  GenGellMannFunctor12(MatrQ matq_, MatIndex j_, MatIndex k_)
60  : matq(matq_),
61  j(j_),
62  k(k_)
63  {
64  eigen_assert(j < k);
65  eigen_assert(k <= (MatIndex)matq.dim());
66  }
67  MatrQ matq;
68  MatIndex j;
69  MatIndex k;
70 
71  template<typename Index>
72  inline const typename MatrQ::ComplexScalar operator() (Index row, Index col) const
73  {
74  if (row == j && col == k) {
75  return Coeffs::CoeffJK();
76  }
77  if (row == k && col == j) {
78  return Coeffs::CoeffKJ();
79  }
80  return 0;
81  }
82 };
83 
84 template<typename MatrQ>
85 struct coeffs1 {
86  static inline typename MatrQ::ComplexScalar CoeffJK() { return typename MatrQ::ComplexScalar(1, 0); }
87  static inline typename MatrQ::ComplexScalar CoeffKJ() { return typename MatrQ::ComplexScalar(1, 0); }
88 };
89 template<typename MatrQ>
90 struct coeffs2 {
91  static inline typename MatrQ::ComplexScalar CoeffJK() { return typename MatrQ::ComplexScalar(0, -1); }
92  static inline typename MatrQ::ComplexScalar CoeffKJ() { return typename MatrQ::ComplexScalar(0, +1); }
93 };
94 
95 template<typename MatrQ>
96 struct GenGellMannFunctor1
97 {
98  typedef GenGellMannFunctor12<MatrQ, coeffs1<MatrQ> > type;
99 };
100 template<typename MatrQ>
101 struct GenGellMannFunctor2
102 {
103  typedef GenGellMannFunctor12<MatrQ, coeffs2<MatrQ> > type;
104 };
105 
106 
107 template<typename MatrQ_>
108 struct GenGellMannFunctor3
109 {
110  typedef GenGellMannFunctor3<MatrQ_> type;
111 
112  typedef MatrQ_ MatrQ;
113  typedef typename MatrQ::RealScalar RealScalar;
114  typedef typename MatrQ::MatrixType::Index MatIndex;
115 
116  GenGellMannFunctor3(MatrQ matq_, MatIndex l_)
117  : matq(matq_),
118  l(l_)
119  {
120  // remember: l = 0, 1, ..., d-2 and not: 1, ..., d-1
121  normalization = std::sqrt( RealScalar(2) / ((l+1)*(l+2)) );
122  eigen_assert(l < (MatIndex)matq.dim()-1);
123  }
124  MatrQ matq;
125  MatIndex l;
126  RealScalar normalization;
127 
128  template<typename Index>
129  inline const typename MatrQ::ComplexScalar operator() (Index row, Index col) const
130  {
131  if (row != col) {
132  return 0;
133  } else if (row <= l) {
134  return normalization;
135  } else if (row == l+1) {
136  return - (l+1) * normalization;
137  } else {
138  // row > l+1
139  return 0;
140  }
141  }
142 };
143 
144 } // namespace tomo_internal
145 
146 } // namespace Tomographer
147 
148 namespace Eigen { namespace internal {
149 // ---
150 // functor_traits for GenGellMannFunctor12
151 template<typename MatrQ, typename coeffs>
152 struct functor_traits<Tomographer::tomo_internal::GenGellMannFunctor12<MatrQ, coeffs> >
153 {
154  enum { Cost = 4*NumTraits<typename MatrQ::ComplexScalar>::AddCost, PacketAccess = false, IsRepeatable = true };
155 };
156 // functor_has_linear_access for GenGellMannFunctor12
157 template<typename MatrQ, typename coeffs>
158 struct functor_has_linear_access<Tomographer::tomo_internal::GenGellMannFunctor12<MatrQ, coeffs> >
159 { enum { ret = 0 }; };
160 // functor_traits for GenGellMannFunctor3
161 template<typename MatrQ>
162 struct functor_traits<Tomographer::tomo_internal::GenGellMannFunctor3<MatrQ> >
163 { enum { Cost = 4*NumTraits<typename MatrQ::ComplexScalar>::AddCost, PacketAccess = false, IsRepeatable = true }; };
164 // functor_has_linear_access for GenGellMannFunctor3
165 template<typename MatrQ>
166 struct functor_has_linear_access<Tomographer::tomo_internal::GenGellMannFunctor3<MatrQ> >
167 { enum { ret = 0 }; };
168 // ---
169 } } // namespace Eigen::internal, Eigen
170 
171 namespace Tomographer
172 {
173 
174 
182 template<typename MatrQ_>
184 {
185 public:
187  typedef MatrQ_ MatrQ;
189  typedef typename MatrQ::MatrixType MatrixType;
193  typedef typename MatrQ::RealScalar RealScalar;
194 
195 private:
196  MatrQ matq;
197 
200 
201 public:
209  ParamRhoA(MatrQ matq_)
210  : matq(matq_)
211  {
212  // calculate and cache the generalized Gell-Mann matrices
213  lambda.resize(matq.ndof());
214  std::size_t count = 0;
215  // first kind
216  for (std::size_t j = 0; j < matq.dim(); ++j) {
217  for (std::size_t k = j+1; k < matq.dim(); ++k) {
218  lambda[count] = MatrixType::NullaryExpr(
219  matq.dim(),
220  matq.dim(),
221  typename tomo_internal::GenGellMannFunctor1<MatrQ>::type(matq, j, k)
222  );
223  ++count;
224  }
225  }
226  // second kind
227  for (std::size_t j = 0; j < matq.dim(); ++j) {
228  for (std::size_t k = j+1; k < matq.dim(); ++k) {
229  lambda[count] = MatrixType::NullaryExpr(
230  matq.dim(),
231  matq.dim(),
232  typename tomo_internal::GenGellMannFunctor2<MatrQ>::type(matq, j, k)
233  );
234  ++count;
235  }
236  }
237  // third kind
238  for (std::size_t l = 0; l < matq.dim()-1; ++l) {
239  lambda[count] = MatrixType::NullaryExpr(
240  matq.dim(),
241  matq.dim(),
242  typename tomo_internal::GenGellMannFunctor3<MatrQ>::type(matq, l)
243  );
244  ++count;
245  }
246  // got them all?
247  eigen_assert(count == lambda.size());
248  eigen_assert(count == (std::size_t)matq.ndof());
249  }
250 
267  inline const MatrixType & getLambda(std::size_t j) const
268  {
269  eigen_assert(j < matq.ndof());
270  return lambda[j];
271  }
272 
282  {
283  eigen_assert((std::size_t)a.size() == matq.ndof());
284  eigen_assert((std::size_t)rho.rows() == matq.dim());
285  eigen_assert((std::size_t)rho.cols() == matq.dim());
286  for (std::size_t n = 0; n < lambda.size(); ++n) {
287  a(n) = (rho * lambda[n].template selfadjointView<Eigen::Lower>())
288  .real().trace() * boost::math::constants::half_root_two<RealScalar>();
289  }
290  }
291 
298  RealScalar trace = 1.0) const
299  {
300  eigen_assert((std::size_t)a.size() == matq.ndof());
301  eigen_assert((std::size_t)rho.rows() == matq.dim());
302  eigen_assert((std::size_t)rho.cols() == matq.dim());
303  rho = trace * MatrixType::Identity(rho.rows(), rho.cols()) / matq.dim();
304  for (std::size_t n = 0; n < lambda.size(); ++n) {
305  rho += a(n) * lambda[n].template selfadjointView<Eigen::Lower>()
306  * boost::math::constants::half_root_two<RealScalar>();
307  }
308  }
309 
310 }; // class ParamRhoA
311 
312 
313 } // namespace Tomographer
314 
315 #endif
Base namespace for the Tomographer project.
Definition: dmmhrw.h:51
void aToRho(Eigen::Ref< MatrixType > rho, const Eigen::Ref< const VectorParamNdofType > &a, RealScalar trace=1.0) const
Reconstruct a hermitian traceless matrix from its A Parameterization.
Definition: param_rho_a.h:297
Parameterization of density matrices in su(N) generators.
Definition: param_rho_a.h:183
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Index Index
void rhoToA(Eigen::Ref< VectorParamNdofType > a, const Eigen::Ref< const MatrixType > &rho) const
Compute the A Parameterization of a hermitian matrix.
Definition: param_rho_a.h:281
MatrQ::RealScalar RealScalar
The real scalar type. Usually this is double.
Definition: param_rho_a.h:193
T internal(T...args)
MatrQ_ MatrQ
The C++ types for quantum objects and parameterizations.
Definition: param_rho_a.h:187
Define types for quantum objects. See Tomographer::MatrQ.
MatrQ::VectorParamNdofType VectorParamNdofType
The Matrix type to use to describe the A Parameterization of a hermitian matrix.
Definition: param_rho_a.h:191
T resize(T...args)
const MatrixType & getLambda(std::size_t j) const
Generalized Gell-Mann matrices.
Definition: param_rho_a.h:267
tomo_internal::matrq_traits< MatrQ< FixedDim_, FixedMaxParamList_, RealScalar_, IntFreqType_ > >::RealScalar RealScalar
Real scalar type (usually double)
Definition: matrq.h:125
T size(T...args)
STL class.
tomo_internal::matrq_traits< MatrQ< FixedDim_, FixedMaxParamList_, RealScalar_, IntFreqType_ > >::ComplexScalar ComplexScalar
Complex scalar type (usually std::complex)
Definition: matrq.h:127
T sqrt(T...args)
ParamRhoA(MatrQ matq_)
Construct an object which can perform A parameterization transformations.
Definition: param_rho_a.h:209
MatrQ::MatrixType MatrixType
The Matrix type to use to describe hermitian matrices.
Definition: param_rho_a.h:189
Basic utilities for dealing with Eigen matrices and other types.