qiboteam / qibo

A full-stack framework for quantum computing.
https://qibo.science
Apache License 2.0
297 stars 61 forks source link

Dense form of a symbolic Hamiltonian is memory inefficient #966

Open bertacasas opened 1 year ago

bertacasas commented 1 year ago

Hi! I want to implement some code using the Ising model and I have this function here:

from qibo import hamiltonians
from qibo.symbols import X, Z

def Ising(lam, nqubits):

    symbolic_ham = sum(Z(i) * Z(i + 1) for i in range(nqubits-1))
    if nqubits>2:
        symbolic_ham += Z(nqubits-1) * Z(0)
    symbolic_ham += lam*sum(X(i) for i in range(nqubits))
    ham = hamiltonians.SymbolicHamiltonian(symbolic_ham)
    return ham

In this way, I can extract the ground state with ham.ground_state(). However, every time that I run my code, it appears the following warning:

Calculating the dense form of a symbolic Hamiltonian. This operation is memory inefficient.

I'm interested to know if there are any methods to enhance the efficiency of constructing Hamiltonians while maintaining certain functionalities of symbolic Hamiltonians, such as the ability to compute the ground state. I'm using qibo version 0.1.16.

renatomello commented 1 year ago

People can correct me if I'm wrong, but I think this issue is inherent in Symbolic representation.

Also, it is a general hard problem to solve without exploring any structure of the particular Hamiltonian you're trying to create. By definition, creating dense matrices representing Hamiltonians will create exponentially large matrices that consume a lot of memory + finding the ground state involves diagonalizing said matrix, which is $\mathcal{O}(2^{3n}) = \mathcal{O}(8^{n})$ in computational time, where $n$ is the number of qubits.

So, without exploring any structure (e.g. sparsity, symmetry, etc), this problem is inevitably memory and time inefficient.