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

Quantum natural gradient #35

Open
MatteoRobbiati opened this issue Sep 6, 2024 · 4 comments
Open

Quantum natural gradient #35

MatteoRobbiati opened this issue Sep 6, 2024 · 4 comments

Comments

@MatteoRobbiati
Copy link
Contributor

After closing the dedicated PR in Qibo, this issue exists as a reminder natural gradient is a feature we want to support in the future.

@MatteoRobbiati MatteoRobbiati changed the title Natural gradient implementation Quantum natural gradient Sep 6, 2024
@renatomello
Copy link
Contributor

There is a plan to have a function that calculates the quantum_fisher_information_matrix inside the quantum_info module after qiboteam/qibo#1450 is merged, and ideally, before the v1 of the paper is out (next 6 weeks).

Here is an old issue on qibo about it qiboteam/qibo#657.

The QFIM is essentially the metric tensor needed for the natural gradient. What would be the best way to integrate these two ideas? Because that would introduce a circular dependency between qibo and qiboml.

@alecandido
Copy link
Member

In general, an abstract interface for obtaining gradients from a backend (if provided) should be present in Qibo, since the Backend itself is still part of Qibo (possibly to be moved to qibo-core, at some point).

But no implementation for the gradient extraction should be supported by Qibo backends' themselves, while they should be in those present here.

A higher level interface for accessing gradients may be provided in here, but it should not prevent to access the same information from the bare gradient, and reconstructing the same function somewhere else.

If instead you want to use the PSR or something else to compute a gradient while that is not natively provided, then functions using this feature should be split out of the main qibo package, and depending on both qibo and qiboml, since this is definitely an "advanced" QML support, that has to be in qiboml.
The only other alternative is to give up completely in qiboml and keep everything as part of a unique qibo package, which is the opposite direction wrt the one we are taking.

@renatomello
Copy link
Contributor

renatomello commented Oct 14, 2024

But no implementation for the gradient extraction should be supported by Qibo backends' themselves, while they should be in those present here.

This strict rule will create issues, e.g. qiboteam/qibo#1485. Now what happens when gradient descent is for tomography (or any other quantum info application in the present or future) and not for some variational model?

I do not have a solution to this problem, but contradictions will inevitably happen (e.g. the QFIM function I mentioned and this new PR opened).

As I mentioned to @stavros11 in person, my first idea to implement the QFIM function was to implement an AbstractBackend.calculate_gradients that raises a NotImplementedError for all backends but the ones that support automatic differentiation.

@alecandido
Copy link
Member

As I mentioned to @stavros11 in person, my first idea to implement the QFIM function was to implement an AbstractBackend.calculate_gradients that raises a NotImplementedError for all backends but the ones that support automatic differentiation.

That's exactly what I said above...

an abstract interface for obtaining gradients from a backend (if provided) should be present in Qibo

This would be AbstractBackend.calculate_gradients (I may prefer a different name, but it's not relevant).

But no implementation for the gradient extraction should be supported by Qibo backends' themselves, while they should be in those present here.

This is the NotImplementedError statement.

The only additional part is that will only get native gradients, while others may be available. So, if you use the QibolabBackend (or even just the NumpyBackend), you may obtain the gradient from the PSR. Still, if you will attempt to compute the QFIM with those backends, you'll just receive an error.
This limitation will stay, since the additional gradients will be provided by qiboml, and the only dynamic dependency we will manage it will be the backends (everything else, has to depend statically). This means that code in Qibo will be able to use the qiboml backends (if loaded by the user), and nothing else of qiboml. Otherwise, you have to move this code outside the main qibo package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants