Related to H.6. How to find the expectation value of LCU?

So after finishing H.6, we got to know that we can use LCU for simulating time evolution. But how to find the expectation value of the LCU, for example, U+V? I am planning to use it on quantum signal processing, so it can approximate arbitrary function (not just odd or even function), but I don’t know how to code it. Can anyone help me?

Hello @verstrikt

Welcome to the forum, this is a great question! If I understand your question correctly, the postselect option for mid-circuit measurements might be just what you need.

Let’s say your circuit with two wires looks like this:

dev = qml.device("default.qubit", wires = [0,1])

@qml.qnode(dev)
def lcu_circuit():
Your LCU circuit calculating U + V
return qml.expval(qml.PauliZ(1))


But that’s not what you want, since you only want the state when we have already measured 0 in wire = 0. This means you have to add a mid circuit measurement that selects only the results that end up with a \vert 0 \rangle state in the first wire. You can do this as follows

dev = qml.device("default.qubit", wires = [0,1])

@qml.qnode(dev)
def lcu_circuit():
m0 = qml.measure(0, postselect = 0)
return qml.expval(qml.PauliZ(1))


You won’t be able to return qml.state() in this case, but you can also return qml.density_matrix(wires = 1) if you want to debug! That’ll return the state in the last wires when the first wire is measured to be \vert 0 \rangle.

I hope this helps, let me know if you have any follow-up questions .

Cheers,

Alvaro

Alright, thank you @Alvaro_Ballon. I will try it!

2 Likes