# Codercise H.6.7 - Interpreting the output plot

At the end of exercise H.6.7, a plot is displayed and we are asked: “Do the results make sense?”. Unfortunately, I have spent quite some time trying to figure out why the plot looks the way it does, but I haven’t been able to figure it out (here’s the output from the codebook):

The green trace is not too difficult to calculate: cos(-t); but when I derive the equation for the first order approximation, I get that the output state (when the |0\rangle state is measured in the aux register) should be:

\frac{1}{\sqrt{t^2 + 1}} \left(|0\rangle + i t|1\rangle \right).

This is already a normalized state, so I expected the coefficient of the |0\rangle to be \frac{1}{\sqrt{t^2 + 1}}, giving the following red trace:

To double check if I had made a mistake, I ran circuit simulations for both the first order and second order approximations where I extract the zero-stat coefficient after measuring the aux register:

The first-order approx result matches my calculation, so I was wondering if perhaps the plot from the codebook is incorrect, or if I am making a mistake somewhere.

Thanks in advance for the help!!

Hey @diemilio! It looks like our plot is indeed incorrect . It makes sense that ours is wrong because the coefficient of \vert 0 \rangle should never be larger than 1 regardless of the approximation!

I corrected our solution and I match your results:

It’s curious to me that the 2nd order approximation is worse than the 1st order one… I verified this algebraically though and it seems like this is the correct result (pink is 2nd order):

I’ll think on this a little more… In the mean time, I will make the correction to codebook.xanadu.ai! Thanks so much for finding this and excellent work!

1 Like

Thank you so much @isaacdevlugt; makes sense.

I hope you don’t mind if I ask a couple of more questions.

I’ve been working on the derivation for the second-order approximation, but I am having a bit of trouble getting it to match my sim results (or even your results).

1. From the textbook, I got the impression that the circuit for the second order approximation would generate a state of the form \left(U^0 + tU^1 + \frac{1}{2}t^2 U^2 \right)|\psi\rangle, up to some normalization factor, but what I actually get is \left((1+\frac{t}{2}) U^0 + tU^1 + \frac{1}{2}t^2 U^2 \right)|\psi\rangle. Is this an error from my part? If not, is there a way to deal with this? Could the presence of this coefficient be the reason why your results for the second-order are worse than the first order?
2. Since the second order approximation of e^{itX} is given by:
\tilde{U} = I + itX + \frac{1}{2}(itX)^2
\tilde{U} = I + itX - \frac{1}{2}t^2I
in order to match the coefficient of state |\psi\rangle with this expression, I would need:
U^2 = -I
U^1 = iX
U^0 = (1+\frac{t}{2})^{-1} I,
making U^0 a non-trivial, non-normalized matrix that depends on t, which doesn’t seem right . Now, even if I just make U^0 = I, I still don’t get the same result as you. In that case, my final state (when |00\rangle is measured in the top qubits) would be:
|\zeta\rangle = \frac{1}{\sqrt{t^4/4 + t^2 + (t/2+1)^2}} \left((1+\frac{t}{2})U^0 + tU^1 + \frac{1}{2}t^2 U^2 \right)|\psi\rangle
|\zeta\rangle = \frac{1}{\sqrt{t^4/4 + t^2 + (t/2+1)^2}} \left((1+\frac{t}{2})I + itX - \frac{1}{2}t^2 I \right)|\psi\rangle
Which, for |\psi\rangle = |0\rangle:
|\zeta\rangle = \frac{1}{\sqrt{t^4/4 + t^2 + (t/2+1)^2}} \left(\left(-t^2/2 + t/2 + 1 \right)|0\rangle + it|1\rangle\right)
The coeff of the |0\rangle would be just this part:
\frac{\left(-t^2/2 + t/2 + 1 \right)}{\sqrt{t^4/4 + t^2 + (t/2+1)^2}}
which decreases a lot faster than your plot (and my sim for that matter).

Any idea on where I might be going wrong? I can also send the complete derivation if that helps.

Thanks!

Hey @diemilio,

The second-order approx should definitely be U^0 + tU^1 + \frac{1}{2}t^2U^2 up to normalization, where the normalization was done before the measurement (measure 0 on both auxiliary qubits), so I’m not 100% certain on where you’ve made a mistake .

Maybe checking out the original paper will help?

Thanks so much, @isaacdevlugt. I will check the original paper.

When you say “the normalization was done before the measurement”, did you mean after measurement? Isn’t the state already normalized before the measurement? Maybe I am missing something here, and this is where I’m going wrong

I have attached my derivation if you are interested in spotting errors other people’s errors lol, but I know you’re busy so I understand if you don’t have time to look into it

Thanks again for all the help!

I found my mistake.

I forgot to add the control to the V_{t/2} and V^\dagger_{t/2} gates!!

I will fix that and see if I finally get my results to match.

Edit: After working on the derivation including the controls for V_{t/2} and V^\dagger_{t/2}, I get the same result. I also just saw from section H.7. of the textbook that this should be in fact the case because V_{t/2} V^\dagger_{t/2} cancel each other out if they’re not applied, so I am still trying to figure out where I went wrong

1 Like

OK, I FINALLY found my mistake. It was in the normalization. I was assuming that the coefficients of the superpositions were real-valued even after applying U^0, U^1, U^2, which is clearly not the case, so my normalization was wrong.

Here’s the correct result:

And here are the calculated and simulated values, which match yours :

The only comment I have is that, we do seem to get this term \left((1+\frac{t}{2}) U^0 + tU^1 + \frac{1}{2}t^2 U^2 \right)|\psi\rangle accompanying state |00\rangle of the auxiliary reg instead of just \left( U^0 + tU^1 + \frac{1}{2}t^2 U^2 \right)|\psi\rangle.

I believe this is the same issue discussed in chapter H.7 of the textbook regarding the unwanted state: \text{SELECT}|11\rangle |\psi\rangle = |11\rangle U^0 |\psi\rangle, but it does make me wonder if this is why the second approximation is worse than the first, since to be able to perfectly match I + itX - \frac{1}{2}t^2I, we would need U^0 = \left(1 + \frac{t}{2} \right)^{-1}I, instead of just I, as I had described above.

Ah! I see a problem with what’s in the codebook here. Excellent work @diemilio. The circuit diagram for the second-order approximation is not correct. The last control operation should be controlled on all auxiliary wires, like what’s depicted in H.7 :

The circuit in H.6 only shows U^0 being controlled on the first auxiliary wire, which leads to the presence of an extra U^0 term — the one with a coefficient of t / 2. So, in your work (excellent notes by the way!) that you attached, in the expression for \vert \xi_3 \rangle you can erase the first U^0.

However, that still doesn’t get rid of that pesky \frac{t}{2}… I’ll get back to you! Need to whip out some pen and paper myself.

1 Like

Hey @diemilio! Just wanted to give a quick update here. I think we may have uncovered more than one issue as a result of your good work here! These things take a little time to double check and re-implement in the codebook. Will keep you updated!

Thanks so much for letting me know @isaacdevlugt! Also, thanks for being so patient and going over my questions; this discussion has been very informative.

I will keep my eyes open for the updates to come

1 Like

Hey @diemilio! A colleague and I figured out what needs to change in H.6. There are definitely a few errors! It would be a long-winded response if I explained everything here, but the long and short of it is that the circuit for the 2nd-order approximation in H.6 isn’t correct. If you’re interested, we found this video helpful: Optimizing Linear Combination of Unitaries for Quantum Chemistry Hamiltonians - YouTube

We are working on revamping some of the codercises and the theory in H.6. When those changes are live, I’ll make sure to notify you here.

Excellent work on exposing this issue!

Thanks so much for letting me know and for sending the video, @isaacdevlugt. Looking forward to seeing how the new version of H.6. looks like!

1 Like

Hi @isaacdevlugt, I finally got to watch the video. Thanks again, it clarified things very well.

Not sure if this is of interest, but I corrected the second-order derivation:

I also ran the sims, and the new expression does get closer to the exact solution. Furthermore, since simulating the third-order approximation required very little changes, I added that one too. As you can see, that trace starts approaching the exact solution very closely:

I haven’t found time to derive the third-order approximation, but it shouldn’t be too difficult.

Thanks again for all the feedback, this has been fun!

Third-order approximation:

Wow! Excellent work!

Hey @diemilio! We’ve finally changed H.6-8 .

Let us know if you see anything else!