XanaduAI / thewalrus

A library for the calculation of hafnians, Hermite polynomials and Gaussian boson sampling.
https://the-walrus.readthedocs.io
Apache License 2.0
99 stars 54 forks source link

The Qmat functions is off by a complex conjugate #318

Open nquesada opened 2 years ago

nquesada commented 2 years ago

Before posting a bug report

Expected behavior

from thewalrus.random import random_covariance
from thewalrus.quantum import Qmat
def rmat(l, hbar=2):
    """
    This is the R matrix in https://the-walrus.readthedocs.io/en/latest/gbs.html
    """
    idl = np.identity(l)/np.sqrt(2*hbar)
    return np.block([[idl, 1j*idl],[idl, -1j*idl]])

cov = random_covariance(m)
Q = Qmat(cov)
rr = rmat(m)
Qp = rr @ cov @ (rr.T.conj()) + np.identity(len(cov))*0.5
print(np.allclose(Q, Qp)) # Comes out to be False

Actual behavior

from thewalrus.random import random_covariance
from thewalrus.quantum import Qmat
def rmat(l, hbar=2):
    """
    This is the R matrix in https://the-walrus.readthedocs.io/en/latest/gbs.html
    """
    idl = np.identity(l)/np.sqrt(2*hbar)
    return np.block([[idl, 1j*idl],[idl, -1j*idl]])

cov = random_covariance(m)
Q = Qmat(cov)
rr = rmat(m)
Qp = rr @ cov @ (rr.T.conj()) + np.identity(len(cov))*0.5
print(np.allclose(Q, Qp.conj())) # Comes out to be True

Reproduces how often

Always

System information

Linux

Source code

No response

Tracebacks

No response

Additional information

No response