lambeq icon indicating copy to clipboard operation
lambeq copied to clipboard

Inner product between two quantum circuits

Open kinianlo opened this issue 5 months ago • 3 comments

Problem

Computing the inner product between two circuits with post-selection gives surprising results.

Minimal working example Consider the following two states:

  1. (state 1) a Bell state with one post-selected qubit
from lambeq.backend.quantum import Ket, H, CX, Id, qubit, Bra, Scalar
from lambeq.backend.drawing import draw_equation

state1 = Ket(0) @ Ket(0)
state1 >>= H @ Id(qubit)
state1 >>= CX
state1 >>= Bra(0) @ Id(qubit)

print(state1.eval()) # [0.70710678 0.        ]

draw_equation(state1, Ket(0) @ Scalar(1/2**0.5))

7e1600d3-139e-4232-bccd-96b268d65344 2. (state 2) the plus state:

state2 = Ket(0) >> H

print(state2.eval()) # [0.70710678 0.70710678]

state2.draw(figsize=(1, 1))

c51149b9-f7be-4f76-88e5-6b9a26a1ae2b

The inner product should be computed by composing state 1 and the dagger of state 2:

inner = state1 >> state2.dagger()

print(inner.eval()) # 0.5000000000000001

draw_equation(inner)

459854e7-8a9a-4981-a55a-cae5422bdad0

That evaluates to $$1/2$$, which is technically correct as state 1 is equal to a zero state with a $$1/\sqrt{2}$$ scalar factor due to the post-selection. However, one would naturally expect the inner product between a zero state and a plus state to be $$1/\sqrt{2}$$. The issue here is that state 1 is not normalised due to the post-selection.

There are circumstances where you would want to compute the inner product between normalised states even if there were post-selected qubits. One example is computing similarity between two sentences, using the inner product between their DisCoCat circuits. This behaviour means that the use of RemoveCupsRewriter would potentially alters the evaluation of an inner product diagram by removing post-selection qubits.

Ideas

It could be helpful to have a mechanism that tracks the (post-selected) Bra's from state 1. The evaluation of the diagram should be normalised by the post-selected Bra's from state 1.

In the above example, the left Bra is post-selected. The corrected evaluation should be $$1/2$$ normalised by the post-selection success fraction $$1/\sqrt{2}$$, resulting in the desired result ($$1/\sqrt{2}$$) as the inner product between a zero state and a plus state.

kinianlo avatar Sep 22 '24 23:09 kinianlo