# Help with Trotter gates and ancilla purification - SwapGate

I am trying to write code to represent a thermal state using the ancilla purification technique. I want to implement the cooling step using Trotter gates, since 'toExpH' does not seem to give me the desired accuracy. I am using the XX Hamiltonian.

I believe I have to use swapgates, since the time evolution gates are not on adjacent sites. I was just wondering if there is some example code to do this?

Effectively what I am doing now, is if say I have a gate 'hterm' that acts on sites 1 and 3,

vector<BondGate> gates();
auto s1 = BondGate(sites,2,3);
gates.push_back(s1);
auto g = BondGate(sites,1,3,BondGate::tImag,tau,hterm);
gates.push_back(g);
gates.push_back(s1);


So I swap 2&3, then have my gate on sites 1&3, and then I swap back sites 2&3.

However, I get the error

b+2 < r_orth_lim_


when gateTEvol hits the second gate, the actual gate that time evolves.

I am just wondering what I should be doing? I can send more code if necessary, but the full code is over several files, so hopefully this is enough.

Best,
Nick