ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
coherent_init.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * ALPS MPS DMRG Project
4  *
5  * Copyright (C) 2013 Institute for Theoretical Physics, ETH Zurich
6  * 2013-2013 by Michele Dolfi <dolfim@phys.ethz.ch>
7  *
8  * This software is part of the ALPS Applications, published under the ALPS
9  * Application License; you can use, redistribute it and/or modify it under
10  * the terms of the license, either version 1 or (at your option) any later
11  * version.
12  *
13  * You should have received a copy of the ALPS Application License along with
14  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
15  * available from http://alps.comp-phys.org/.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  *****************************************************************************/
26 
27 #ifndef MAQUIS_DMRG_COHERENT_INIT_H
28 #define MAQUIS_DMRG_COHERENT_INIT_H
29 
30 #include "dmrg/mp_tensors/mps.h"
33 
34 #include <boost/tuple/tuple.hpp>
35 
36 template <class SymmGroup>
37 double coherent_weight(std::vector<double> const& coeff, std::vector<boost::tuple<typename SymmGroup::charge, size_t> > const& state)
38 {
39  using std::exp; using std::sqrt; using std::pow;
40  using boost::math::factorial;
41 
42  double w = 1.;
43  for (int p=0; p<state.size(); ++p) {
44  int n = boost::get<1>(state[p]);
45  w *= pow(coeff[p], n) * sqrt(factorial<double>(n)) / factorial<double>(n);
46  }
47  return w;
48 }
49 
50 template <class Matrix, class SymmGroup>
51 MPS<Matrix,SymmGroup> coherent_init_join(std::vector<double> const& coeff, Index<SymmGroup> const& phys,
52  typename SymmGroup::charge initc=SymmGroup::IdentityCharge)
53 {
54  typedef typename SymmGroup::charge charge;
55  typedef boost::tuple<charge, size_t> local_state;
56 
57  size_t L = coeff.size();
58 
60  double prev_weight;
61  bool first = true;
63  for (boost::tie(it,end)=basis_sector_iterators(L, phys, initc); it!=end; ++it)
64  {
65  std::vector<local_state> const& state = *it;
66  double weight = coherent_weight<SymmGroup>(coeff, state);
67  if (mps.length() == 0) {
68  mps = state_mps<Matrix>(state, phys);
69  } else {
70  if (first)
71  mps = join(mps, state_mps<Matrix>(state, phys), prev_weight, weight);
72  else
73  mps = join(mps, state_mps<Matrix>(state, phys), 1., weight);
74 
75  first = false;
76  }
77  prev_weight = weight;
78  }
79 
80  return mps;
81 }
82 
83 template <class Matrix, class SymmGroup>
84 MPS<Matrix,SymmGroup> coherent_init(std::vector<double> const& coeff, Index<SymmGroup> const& phys)
85 {
86  assert(phys.size() == 1); // only for TrivialGroup
87  // TODO: require mapping phys --> dens
88 
89  typedef typename SymmGroup::charge charge;
90 
91  using std::exp; using std::sqrt; using std::pow;
92  using boost::math::factorial;
93 
94  size_t L = coeff.size();
95 
96  Index<SymmGroup> trivial_i;
97  trivial_i.insert(std::make_pair(SymmGroup::IdentityCharge, 1));
98 
100  for (int p=0; p<L; ++p) {
101  int s=0;
102  Matrix m(phys[s].second, 1, 0.);
103  for (int ss=0; ss<phys[s].second; ++ss) {
104  m(ss, 0) = pow(coeff[p], ss) * sqrt(factorial<double>(ss)) / factorial<double>(ss);
105  }
107  block.insert_block(m, SymmGroup::IdentityCharge, SymmGroup::IdentityCharge);
108 
109  MPSTensor<Matrix, SymmGroup> t(phys, trivial_i, trivial_i);
110  t.data() = block;
111 
112  mps[p] = t;
113  }
114  return mps;
115 }
116 
117 
118 template <class Matrix, class SymmGroup>
119 MPS<Matrix,SymmGroup> coherent_init_dm_join(std::vector<double> const& coeff, Index<SymmGroup> const& phys_psi, Index<SymmGroup> const& phys_rho)
120 {
121  typedef typename SymmGroup::charge charge;
122  typedef boost::tuple<charge, size_t> local_state;
123 
124  size_t L = coeff.size();
125 
127  double prev_weight;
128  bool first = true;
129  basis_sector_iterator_<SymmGroup> it1,it2,end1,end2;
130  for (boost::tie(it1,end1)=basis_sector_iterators(L, phys_psi, SymmGroup::IdentityCharge); it1!=end1; ++it1)
131  for (boost::tie(it2,end2)=basis_sector_iterators(L, phys_psi, SymmGroup::IdentityCharge); it2!=end2; ++it2)
132  {
133  std::vector<local_state> const& state1 = *it1;
134  std::vector<local_state> const& state2 = *it2;
135  std::vector<local_state> state_rho(L);
136 
137  for (int p=0; p<L; ++p) {
138  boost::get<0>(state_rho[p]) = SymmGroup::IdentityCharge;
139  boost::get<1>(state_rho[p]) = boost::get<1>(state1[p])*phys_psi.size_of_block(boost::get<0>(state2[p])) + boost::get<1>(state2[p]);
140  }
141 
142  double weight = coherent_weight<SymmGroup>(coeff, state1)*coherent_weight<SymmGroup>(coeff, state2);
143  if (mps.length() == 0) {
144  mps = state_mps<Matrix>(state_rho, phys_rho);
145  } else {
146  if (first)
147  mps = join(mps, state_mps<Matrix>(state_rho, phys_rho), prev_weight, weight);
148  else
149  mps = join(mps, state_mps<Matrix>(state_rho, phys_rho), 1., weight);
150 
151  first = false;
152  }
153  prev_weight = weight;
154  }
155 
156  return mps;
157 }
158 
159 template <class Matrix, class SymmGroup>
160 MPS<Matrix,SymmGroup> coherent_init_dm(std::vector<double> const& coeff, Index<SymmGroup> const& phys_psi, Index<SymmGroup> const& phys_rho)
161 {
162  assert(phys_psi.size() == 1); // only for TrivialGroup
163  // TODO: require mapping phys --> dens
164 
165  typedef typename SymmGroup::charge charge;
166 
167  using std::exp; using std::sqrt; using std::pow;
168  using boost::math::factorial;
169 
170  size_t L = coeff.size();
171 
172  Index<SymmGroup> trivial_i;
173  trivial_i.insert(std::make_pair(SymmGroup::IdentityCharge, 1));
174 
175  MPS<Matrix, SymmGroup> mps(L);
176  for (int p=0; p<L; ++p) {
177  int s=0;
178  Matrix m(phys_rho[s].second, 1, 0.);
179  for (int ss1=0; ss1<phys_psi[s].second; ++ss1)
180  for (int ss2=0; ss2<phys_psi[s].second; ++ss2) {
181  m(ss1*phys_psi[s].second+ss2, 0) = pow(coeff[p], ss1) * sqrt(factorial<double>(ss1)) / factorial<double>(ss1);
182  m(ss1*phys_psi[s].second+ss2, 0) *= pow(coeff[p], ss2) * sqrt(factorial<double>(ss2)) / factorial<double>(ss2);
183  }
185  block.insert_block(m, SymmGroup::IdentityCharge, SymmGroup::IdentityCharge);
186 
187  MPSTensor<Matrix, SymmGroup> t(phys_rho, trivial_i, trivial_i);
188  t.data() = block;
189 
190  mps[p] = t;
191  }
192  return mps;
193 }
194 
195 
196 #endif
declaration of the MPS class (vector of MPSTensor)
MPS< Matrix, SymmGroup > coherent_init(std::vector< double > const &coeff, Index< SymmGroup > const &phys)
Definition: coherent_init.h:84
std::pair< basis_sector_iterator_< SymmGroup >, basis_sector_iterator_< SymmGroup > > basis_sector_iterators(size_t L, Index< SymmGroup > const &phys, typename SymmGroup::charge initc=SymmGroup::IdentityCharge)
convert a basis state into MPS
size_type insert_block(Matrix const &, charge, charge)
std::size_t size_of_block(charge c) const
MPS< Matrix, SymmGroup > coherent_init_dm_join(std::vector< double > const &coeff, Index< SymmGroup > const &phys_psi, Index< SymmGroup > const &phys_rho)
block_matrix< Matrix, SymmGroup > sqrt(block_matrix< Matrix, SymmGroup > m)
MPS< Matrix, SymmGroup > coherent_init_dm(std::vector< double > const &coeff, Index< SymmGroup > const &phys_psi, Index< SymmGroup > const &phys_rho)
Definition: mps.h:40
MPS< Matrix, SymmGroup > coherent_init_join(std::vector< double > const &coeff, Index< SymmGroup > const &phys, typename SymmGroup::charge initc=SymmGroup::IdentityCharge)
Definition: coherent_init.h:51
size_t length() const
Definition: mps.h:58
double coherent_weight(std::vector< double > const &coeff, std::vector< boost::tuple< typename SymmGroup::charge, size_t > > const &state)
Definition: coherent_init.h:37
std::size_t insert(std::pair< charge, std::size_t > const &x)
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
std::size_t size() const
MPSTensor< Matrix, SymmGroup > join(MPSTensor< Matrix, SymmGroup > const &m1, MPSTensor< Matrix, SymmGroup > const &m2, boundary_flag_t boundary_f=no_boundary_f)
Definition: joins.hpp:33
iterators through all allowed sectors in the system