Tomographer  v5.4
Tomographer C++ Framework Documentation
tspacefigofmerit.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) 2016 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  * Copyright (c) 2017 Caltech, Institute for Quantum Information and Matter, Philippe Faist
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 
29 #ifndef TOMOGRAPHER_DENSEDM_TSPACEFIGOFMERIT_H
30 #define TOMOGRAPHER_DENSEDM_TSPACEFIGOFMERIT_H
31 
32 
33 #include <boost/serialization/serialization.hpp>
34 
39 
40 
48 namespace Tomographer {
49 namespace DenseDM {
50 namespace TSpace {
51 
52 
61 template<typename DMTypes_, typename ValueType_ = double>
62 class TOMOGRAPHER_EXPORT FidelityToRefCalculator
63  : public virtual Tools::NeedOwnOperatorNew<typename DMTypes_::MatrixType>::ProviderType
64 {
65 public:
66  typedef DMTypes_ DMTypes;
67  typedef typename DMTypes::MatrixType MatrixType;
69 
71  typedef ValueType_ ValueType;
72 
73 private:
74  MatrixType _ref_T;
75 
76 public:
78  FidelityToRefCalculator(MatrixTypeConstRef T_ref)
79  : _ref_T(T_ref)
80  {
81  }
82 
84  inline ValueType getValue(MatrixTypeConstRef T) const
85  {
86  return fidelityT<ValueType>(T, _ref_T);
87  }
88 
89 
91  FidelityToRefCalculator() : _ref_T() { }
92 private:
93  friend boost::serialization::access;
94  template<typename Archive>
95  void serialize(Archive & a, unsigned int /* version */)
96  {
97  a & _ref_T;
98  }
99 
100 };
101 
102 
103 
104 
114 template<typename DMTypes_, typename ValueType_ = double>
115 class TOMOGRAPHER_EXPORT PurifDistToRefCalculator
116  : public virtual Tools::NeedOwnOperatorNew<typename DMTypes_::MatrixType>::ProviderType
117 {
118 public:
119  typedef DMTypes_ DMTypes;
120  typedef typename DMTypes::MatrixType MatrixType;
122 
124  typedef ValueType_ ValueType;
125 
126 private:
127  MatrixType _ref_T;
128 
129 public:
131  PurifDistToRefCalculator(MatrixTypeConstRef T_ref)
132  : _ref_T(T_ref)
133  {
134  }
135 
137  inline ValueType getValue(MatrixTypeConstRef T) const
138  {
139  ValueType F = fidelityT<ValueType>(T, _ref_T);
140  if (F >= ValueType(1)) {
141  return 0;
142  }
143  return std::sqrt(ValueType(1) - F*F);
144  }
145 
146 
148  PurifDistToRefCalculator() : _ref_T() { }
149 private:
150  friend boost::serialization::access;
151  template<typename Archive>
152  void serialize(Archive & a, unsigned int /* version */)
153  {
154  a & _ref_T;
155  }
156 };
157 
163 template<typename DMTypes_, typename ValueType_ = double>
164 class TOMOGRAPHER_EXPORT TrDistToRefCalculator
165  : public virtual Tools::NeedOwnOperatorNew<typename DMTypes_::MatrixType>::ProviderType
166 {
167 public:
168  typedef DMTypes_ DMTypes;
169  typedef typename DMTypes::MatrixType MatrixType;
171 
173  typedef ValueType_ ValueType;
174 
175 private:
176  MatrixType _ref_rho;
177 
178 public:
180  TrDistToRefCalculator(MatrixTypeConstRef rho_ref)
181  : _ref_rho(rho_ref)
182  {
183  }
184 
186  inline ValueType getValue(MatrixTypeConstRef T) const
187  {
188  return traceDistance<ValueType>(T*T.adjoint(), _ref_rho);
189  }
190 
192  TrDistToRefCalculator() : _ref_rho() { }
193 private:
194  friend boost::serialization::access;
195  template<typename Archive>
196  void serialize(Archive & a, unsigned int /* version */)
197  {
198  a & _ref_rho;
199  }
200 };
201 
202 
203 
209 template<typename DMTypes_>
210 class TOMOGRAPHER_EXPORT ObservableValueCalculator
211  : public virtual Tools::NeedOwnOperatorNew<typename DMTypes_::VectorParamType>::ProviderType
212 {
213 public:
214  typedef DMTypes_ DMTypes;
215  typedef typename DMTypes::MatrixType MatrixType;
217  typedef typename DMTypes::VectorParamType VectorParamType;
219 
221  typedef typename DMTypes::RealScalar ValueType;
222 
223 private:
225  ParamX<DMTypes> _param_x;
226 
228  VectorParamType _A_x;
229 
230 public:
234  ObservableValueCalculator(DMTypes dmt, MatrixTypeConstRef A)
235  : _param_x(dmt), _A_x(_param_x.HermToX(A))
236  {
237  }
241  ObservableValueCalculator(DMTypes dmt, VectorParamTypeConstRef A_x)
242  : _param_x(dmt), _A_x(A_x)
243  {
244  }
245 
247  inline ValueType getValue(MatrixTypeConstRef T) const
248  {
249  return _A_x.transpose() * _param_x.HermToX(T*T.adjoint());
250  }
251 
252 
254  ObservableValueCalculator() : _param_x(), _A_x() { }
255 private:
256  friend boost::serialization::access;
257  template<typename Archive>
258  void serialize(Archive & a, unsigned int /* version */)
259  {
260  a & _param_x;
261  a & _A_x;
262  }
263 };
264 
265 
266 } // namespace TSpace
267 } // namespace DenseDM
268 } // namespace Tomographer
269 
270 
271 #endif
FidelityToRefCalculator()
Construct an invalid object – ONLY for use with Boost.serialization.
ValueType getValue(MatrixTypeConstRef T) const
Calculate the trace distance of the state represented by T to the reference state.
Base namespace for the Tomographer project.
Definition: densellh.h:45
ObservableValueCalculator(DMTypes dmt, MatrixTypeConstRef A)
Constructor directly accepting A as a hermitian matrix.
ValueType getValue(MatrixTypeConstRef T) const
Calculate the purified distance of the state represented by T to the reference state.
ObservableValueCalculator()
Construct an invalid object – ONLY for use with Boost.serialization.
TrDistToRefCalculator()
Construct an invalid object – ONLY for use with Boost.serialization.
C++ types for describing dense density matrices in various parameterizations.
ValueType_ ValueType
For ValueCalculator interface : value type.
Provide appropriate operator new() definitions for a structure which has a member of the given stored...
Calculate the trace distance to a reference state for each sample.
Distance measures in quantum information for states represented as dense matrices.
ValueType getValue(MatrixTypeConstRef T) const
Calculate the fidelity of the state represented by T to the reference state.
PurifDistToRefCalculator(MatrixTypeConstRef T_ref)
Constructor, the reference state is T_ref (in T Parameterization)
Calculate expectation value of an observable for each sample.
DMTypes::RealScalar ValueType
For ValueCalculator interface : value type.
ObservableValueCalculator(DMTypes dmt, VectorParamTypeConstRef A_x)
Constructor directly accepting the X parameterization of A.
ValueType getValue(MatrixTypeConstRef T) const
Calculate the expectation value of the observable for the state represented by T. ...
FidelityToRefCalculator(MatrixTypeConstRef T_ref)
Constructor, the reference state is T_ref (in T Parameterization)
Calculate the "purified distance" to a reference state for each sample.
Tools for parameterizing hermitian matrices with the X Parameterization.
VectorParamType HermToX(MatrixTypeConstRef Herm) const
Get the X-parameterization corresponding to a given hermitian matrix.
Definition: param_herm_x.h:82
Calculate the fidelity to a reference state for each sample.
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
ValueType_ ValueType
For ValueCalculator interface : value type.
T sqrt(T... args)
ValueType_ ValueType
For ValueCalculator interface : value type.
PurifDistToRefCalculator()
Construct an invalid object – ONLY for use with Boost.serialization.
TrDistToRefCalculator(MatrixTypeConstRef rho_ref)
Constructor, the reference state is rho_ref.
RealScalar_ RealScalar
Real scalar type, given in template parameter. Usually double is fine.
Definition: dmtypes.h:121