CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing
https://cqcl.github.io/lambeq-docs
Apache License 2.0
449 stars 108 forks source link

Normalisation of quantum state in QuantumModel #37

Closed gamatos closed 2 years ago

gamatos commented 2 years ago

Hi,

I've noticed that the normalisation of the quantum state done in the following lines of the QuantumModel._normalise_vector function

https://github.com/CQCL/lambeq/blob/f6fa5a70d241e3eeff81d8125ce1629bbe94e3be/lambeq/training/quantum_model.py#L70-L71

seems to be missing a square along with the absolute value, i.e. it should be something like

predictions = backend.abs(predictions)**2 + self.SMOOTHING
return predictions / predictions.sum()

so that the resulting probabilities match those one would get from measuring the quantum state in the specified basis.

Thommy257 commented 2 years ago

I totally agree that we should be consistent with the TketModel here. Needs to be changed!

The original reason why we did not square the absolute value of the amplitudes was that they used this as a metric in the "QNLP in practice" paper (if I'm not mistaken).

dimkart commented 2 years ago

As discussed internally, this has meaning only for the NumpyModel (not the TketModel). There will be a fix included in the next release.

The issue will be now closed.