# How to extract the MPS coefficients of an Electron siteset

**URL:** <https://itensor.discourse.group/t/how-to-extract-the-mps-coefficients-of-an-electron-siteset/504>\
**Category:** ITensor C++ Questions\
**Tags:** mps, fermions\
**Created:** [November 7, 2022, 11:18pm UTC](https://itensor.discourse.group/t/how-to-extract-the-mps-coefficients-of-an-electron-siteset/504 "2022-11-07T23:18:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidev](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/davidev/32/168_2.png) [@davidev](https://itensor.discourse.group/u/davidev)\
**Post date:** [November 7, 2022, 11:18pm UTC](https://itensor.discourse.group/t/how-to-extract-the-mps-coefficients-of-an-electron-siteset/504/1 "2022-11-07T23:18:17Z")

</div>

Hi!

I’m writing a snippet for extracting the coefficients of an MPS with siteset Electron by following [this tutorial](https://itensor.org/docs.cgi?vers=cppv3&page=formulas/mps_element). Here it is my attempt:

```auto
double get_MPS_coefficient(MPS psi,
                           Electron sites,
                           std::vector<std::string> conf)
{

// args: psi MPS representing the state psi= \sum c_gamma |gamma>
// conf is a vector of length(psi) containing the indices of the MPS |gamma> to extract: ex: configurations = [Up, Dn, Up, Dn] if length(psi) = 4
// return: coefficients c_gamma

    int N = length(psi);
	auto coeff = ITensor(1.);
    for(auto j : range1(N))
    {
    // sites(j, conf[j-1]) is an IndexVal representing the index of site(j) 
    // corresponding to the internal state given by conf[j-1] \in {Emp, Up, Dn, UpDn}
    // setElt(IndexVal) initializes a zero tensor with an element equal to 1
    // at the index position given by the ival

	IndexVal ival = dag(sites(j, el[j-1]));
    coeff *= psi(j) * setElt(ival);

    }

    double val_coeff = elt(coeff);
    PrintData(val_coeff);

    return val_coeff;
}

```

However, I am having some troubles in understanding what is the implicit order that is assumed for the fermionic operators, because some of the coefficients that I get by an exact diagonalization have flipped signs wrt the ones I get with code above and this is not an overall minus.

My guess is that something like the following happens:

Suppose I construct a state as |\psi\rangle = c^\dag\_{1\uparrow} c^\dag\_{2\downarrow} |0\rangle.

If I assume that my operators are ordered with increasing indices and \uparrow \< \downarrow, then the coefficient in the expansions of |\psi\rangle will be +1, but if I assume a different ordering the coefficient might be -1.

Thanks a lot for any insights/help in advance!  
Best,  
Davide

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [November 9, 2022, 5:35pm UTC](https://itensor.discourse.group/t/how-to-extract-the-mps-coefficients-of-an-electron-siteset/504/2 "2022-11-09T17:35:53Z")

</div>

Hi Davide,  
Good question because fermions and tensor networks can be a subtle thing. Here is an answer that I think could clear things up for you.

You should think of the MPS as representing a tensor of amplitudes in a certain basis, where the basis handles all of the fermionic antisymmetry implicitly, so that the tensor elements can have any sign or value and still represent a valid fermionic state. Specifically, the state is of the form:

\ket{\Psi} = \sum\_{i\_1 i\_2 i\_3 i\_4} \Psi^{i\_1 i\_2 i\_3 i\_4} \ket{i\_1 i\_2 i\_3 i\_4}

and the MPS is a tensor network representation of the tensor \Psi^{i\_1 i\_2 i\_3 i\_4} and for electrons the indices run over the values i\_n = 1,2,3,4.

Then, to map this to the usual fermionic representation you’re used to, you can use the following definition of the basis states \ket{i\_1 i\_2 i\_3 i\_4}:

\ket{i\_1 i\_2 i\_3 i\_4} = \hat{D}\_{i\_1} \hat{D}\_{i\_2} \hat{D}\_{i\_3} \hat{D}\_{i\_4} \ket{0}

where

\hat{D}\_1 = \hat{I} \\ \hat{D}\_2 = \hat{c}^\dagger\_\uparrow \\ \hat{D}\_3 = \hat{c}^\dagger\_\downarrow \\ \hat{D}\_4 = \hat{c}^\dagger\_\uparrow \hat{c}^\dagger\_\downarrow

Does that help answer your question? So in a specific case, if your `el` vector is `{1,1,2,3}` the amplitude you’d be computing is \Psi^{1,1,2,3} and it would be the one that corresponds to the basis state

\hat{I}\_1 \hat{I}\_2 \hat{c}^\dagger\_{\uparrow, 2} \hat{c}^\dagger\_{\downarrow,3} \ket{0} = \hat{c}^\dagger\_{\uparrow, 2} \hat{c}^\dagger\_{\downarrow,3} \ket{0}

---

<div class="post-metadata">

**Author:** ![davidev](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/davidev/32/168_2.png) [@davidev](https://itensor.discourse.group/u/davidev)\
**Post date:** [November 9, 2022, 8:03pm UTC](https://itensor.discourse.group/t/how-to-extract-the-mps-coefficients-of-an-electron-siteset/504/3 "2022-11-09T20:03:43Z")

</div>

Hi Miles,

thanks! That is exactly what I was looking for. Thanks for clarifying that.

Thanks also for the whole ITensor project.

Best,

Davide

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [November 10, 2022, 3:06am UTC](https://itensor.discourse.group/t/how-to-extract-the-mps-coefficients-of-an-electron-siteset/504/4 "2022-11-10T03:06:01Z")

</div>

Hi Davide,  
Great – I hope it helps to check things against the ED calculation & that I’m not off by a sign anywhere, but the above should be correct.

Appreciate the positive feedback!

Miles
