entropicalabs / openqaoa

Multi-backend SDK for quantum optimisation
MIT License
113 stars 59 forks source link

Implement `as_matrix` method for the `Hamiltonian` class #232

Closed vishal-ph closed 1 year ago

vishal-ph commented 1 year ago

Prerequisites

Before raising this feature request, I made sure:

Is your feature request related to a problem? Please describe.

The class Hamiltonian in OpenQAOA defined in src/openqaoa-src/openqaoa/qaoa_components/ansatz_constructor/operators.py is responsible for constructing the Cost and Mixer Hamiltonians in QAOA. It fundamentally describes the Hamiltonian object via list of PauliOps defined on a set of qubits and a corresponding list of their coefficients. Implicitly, the definition of the Hamiltonian is then assumed as follows: $$H = \sumi \alpha{i} Pi + \sum{ij} J{ij} P{ij},$$ where $\ Pi, P{ij}$ are one-qubit and two-qubit PauliOps respectively.

Implement a method in this class that returns the matrix representation of the Hamiltonian object. This will be a $2^n x 2^n$ dimensional sum over all Pauli entries as shown above.

Describe the solution you'd like

class Hamiltonian:
    def as_matrix(self):
        "Implements a numpy array (sparse where relevant) representation
         of the Hamiltonian object."
        #TODO
        return mat
manulpatel commented 1 year ago

Hello @vishal-ph! I am new to OpenQAOA and woud like to implement this functionality. Could you please assign it to me and if possible show any relavant literature to show matrix rep?

vishal-ph commented 1 year ago

@manulpatel, thanks for taking the initiative! In OpenQAOA, the Hamiltonian object is a sum over the terms of the Pauli and Identity operators set tensored over n-qubits. The goal is to represent the sum of these terms in a matrix form. To get started, you may want to start looking at the matrix representation of the Pauli operators here https://en.wikipedia.org/wiki/Pauli_matrices and think about their tensor products.

vishal-ph commented 1 year ago

@AlexisRalli, thanks for your contribution to OpenQAOA and helping close this issue!

natestemen commented 1 year ago

@AlexisRalli congrats on the nice hack! Don't forget to comment here on this issue so that you can be assigned to the issue!

AlexisRalli commented 1 year ago

Thanks for integrating the code!