QuantumApplicationLab / vqls-prototype

A Variational Quantum Linear Solver Prototype for Qiskit
Apache License 2.0
12 stars 4 forks source link

Non-unitary matrix ValueError #12

Open soyjdezcurra opened 6 months ago

soyjdezcurra commented 6 months ago

Steps to reproduce the problem

Input non-unitary matrix. I used the following matrix and vector: matrix = [[ 48, 19, 6, 3], [ 35, 5, 1, 0], [ 57, 36, 18, 7], [105, 95, 85, 75]] b = [56.98, 31.83, 12.89, 7.46]

What is the current behavior?

Raises ValueError and doesn't run.

What is the expected behavior?

Solver should work with a non-unitary matrix (decompose into linear combination of unitaries).

NicoRenaud commented 6 months ago

Thanks @soyjdezcurra, for vqls to work the A matrix has to be symmetric (and hermitian if complex). Otherwise the pauli decomposition won't work. There was a test to check if the input matrix is symmetric or not, but it apparently got removed since the error you mentioned was a non-unitary one.

Can you try with a symmetric matrix and let me know if that works for you ?

Thanks

soyjdezcurra commented 6 months ago

It does work with a symmetric matrix. Is there no way for vqls to work with a non-symmetric matrix?

Thanks for your time.

NicoRenaud commented 4 months ago

Hi and sorry for the late reply. You can have a non symmetric matrix but you then need to use a Pauli Decomposition to decompose it over unitaries. That may results in a large number of unitaries depending on your input matrix.

You can use:

vqls = VLQS(estimator, ansatz, optimizer, ..., options={'matrix_decomposition':'pauli'})
vqls.solve(A,b)