CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing
https://cqcl.github.io/lambeq/
Apache License 2.0
435 stars 106 forks source link

UnitaryHACK: Implement and test gradient free optimizer for circuit models #85

Closed Thommy257 closed 1 year ago

Thommy257 commented 1 year ago

Task description

To enhance the performance of our quantum models, we are currently investigating new optimizers for lambeq. One promising candidate is the Rotosolve algorithm (Ostaszewski et al.). Rotosolve is a gradient-free optimizer that leverages the fact that the expectation value of circuit measurements are sinusoidal with respect to the circuit parameters. Hence, Rotosolve can find the optimal parameters without the need for calculating gradients, making it particularly well-suited for optimization in the context of variational quantum algorithms in the NISQ era.

Your task is to implement the Rotosolve algorithm in lambeq, using the Optimizer interface. The following steps can be used as a guideline:

  1. Familiarise yourself with the theory behind Rotosolve by reading the paper by Ostaszewski et al.
  2. Investigate other optimizers in lambeq, e.g. the SPSAOptimizer
  3. Implement a new class called RotosolveOptimizer which inherits from Optimizer.
  4. Write unit tests to validate the functionality and performance of the Rotosolve optimizer.
  5. Provide clear documentation and examples on how to use the Rotosolve optimizer within lambeq.

Notes

Resources

Alternative

If you don't manage to implement and test the RotosolveOptimizer, you can also implement a different (gradient-free) optimizer of your choice. Some ideas are COBYLA, Nelder-Mead, Conjugate-Gradient...

Thommy257 commented 1 year ago

Hi everyone, please use the following notebook to test your optimiser. Please add it to the PR after you've ran it using your own optimiser (replacing SPSA). The notebook will need to be removed before merging, but it's important to visualise the performance first.

https://drive.google.com/file/d/1AT8q_crTWUFJ2hS2bNSrnc5T8WrinSnv/view?usp=share_link

Use jax==0.4.6 and jaxlib==0.4.6. There is currently a problem with newer versions of jax.

vivek-kumar9696 commented 1 year ago

Hi, is this issue still open. I have an implementation of CMA-ES optimizer. Is it of value for the project?

Thommy257 commented 1 year ago

Hi @vivek-kumar9696, of course! Feel free to submit a PR, I'd be happy to have a look at it.

RamAIbot commented 1 year ago

Hi @Thommy257 I would like to work on adding Rotosolve algorithm for unitary hack.

dimkart commented 1 year ago

@RamAIbot Hi and thanks for your interest. Since there is already a PR open for Rotosolve (#93) , it might be better to work on some other gradient-free optimiser, see some alternatives in Issue #85. If you open a PR we would be happy to review.

Gopal-Dahale commented 1 year ago

Hi @Thommy257, how about designing an interface namely ScipyOptimizer with which we can use Scipy's methods for optimization (scipy.optimise.minimise)?

dimkart commented 1 year ago

This is now completed. Thank you all for your work!