Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid measurement_outcomes during optimization #155

Open
quosta opened this issue Dec 20, 2022 · 1 comment
Open

Avoid measurement_outcomes during optimization #155

quosta opened this issue Dec 20, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@quosta
Copy link

quosta commented Dec 20, 2022

I like the openQAOA ecosystem and I am trying to integrate a tensor network based backend (using cuQuantum SDK), which does not calculate the explicit wf as statevec. I can use qiskit circuits as starting point before converting them to perform TN contractions, so I adapted a backend from qiskit_sim. However the optimization fails at the first cycle without measurement_outcomes.

Here is the kernel code from the backend, is there a way to bypass measurement_outcomes?

    def expectation(self,
                    params: QAOAVariationalBaseParams) -> float:

        ckt = self.qaoa_circuit(params)

        ## QISKIT VERSION
        # output_wf = Statevector(ckt)
        # self.measurement_outcomes = output_wf.data
        # cost = np.real(output_wf.expectation_value(self.qiskit_cost_hamil))
         
        ## CUQUANTUM VERSION
        einsum = CircuitToEinsum(ckt, dtype='complex128', backend=cp)
        cost = 0
        for pauli_term_list in self.qiskit_cost_hamil:
            pauli_term = str(pauli_term_list).split(' * ')
            expression, operands = einsum.expectation(pauli_term[1], lightcone=True)
            expec = contract(expression, *operands)
            cost += np.real(expec * float(pauli_term[0]))
        return cost
@vishal-ph
Copy link
Collaborator

Hi @quosta, thanks for trying out OpenQAOA; we are glad you like it! Your proposition to add cuQuantum simulator in OpenQAOA sounds quite exciting!
So, backends that are non-conventional and do not produce either a wavefunction or some measurement counts as the output of the quantum circuit need to be handled separately. We have been working internally to add one such backend in PR #147.
The process I encourage you to follow to add a new backend to OpenQAOA is as follows:

  • Decide which base backend classes should your backed inherit from. (You can find them in openqaoa/basebackend.py
  • In this case, since cuQuantum simulator does not support any measurement outcomes, you can set the attribute self.measurement_outcomes = {} (an empty dictionary) in the __init__ of the backend.
  • You would also like to raise, for instance, a NotImplementedError for unsupported methods for this backend like the get_counts function.

Once you have added and tested your new backend class in OpenQAOA, we can proceed to add it as a supported backend in get_qaoa_backend.

Feel free to ask more questions, and we will be happy to help you!

P.S. One important workflow comment -- The best way to contribute would be to fork the dev branch

@Q-lds Q-lds added the enhancement New feature or request label Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants