Open kinianlo opened 2 months ago
There is usually a sqrt(2)
renormalisation term when the cup is converted to a bell effect. Would this solve the issue?
I doubt if any pre-determined renormalisation factor would resolve the issue. See the following example with the sqrt(2)
factors:
from lambeq import BobcatParser
from lambeq import AtomicType, IQPAnsatz
from lambeq import NumpyModel
parser = BobcatParser()
ansatz = IQPAnsatz({AtomicType.NOUN: 1, AtomicType.SENTENCE: 1}, n_layers=1)
sent = "Cats love dogs"
diag = parser.sentence2diagram(sent)
circ = ansatz(diag)
# inner product with itself should produce 1 if everything is properly normalized
inner = circ >> circ.dagger()
inner.draw(figsize=(10, 5))
model = NumpyModel.from_diagrams([inner])
model.initialise_weights()
print(model.get_diagram_output([inner])) # [0.17433632]
I think the exact renormalisation factor needed can only be known by running the circuit in general.
@kinianlo You make a valid point, but we need to think a little what is the best way to fix this. I'll leave this issue open and come back to you.
Problem
Computing the inner product between two circuits with post-selection gives surprising results.
Minimal working example Consider the following two states:
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))
The inner product should be computed by composing state 1 and the dagger of state 2:
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.