qiboteam / qiboml

Quantum Machine Learning using Qibo
Apache License 2.0
8 stars 2 forks source link

Define a `set_interface` function to replace the conceptual Qibo's `set_backend` #24

Open MatteoRobbiati opened 3 months ago

MatteoRobbiati commented 3 months ago

As the title says, if needed.

alecandido commented 3 months ago

What if we start phasing out global objects?

In this case in particular, since the gradient will be computed independently on the interface, and that will be just used by the downstream to consume it, maybe you don't need to specify the interface at all, until you will actually use it. I.e. just specify it in the expectation() call :)

(In principle, you don't even need a backend until you execute, but that would require passing one in every circuit call - unless you cache a backend in the Circuit object itself)

MatteoRobbiati commented 3 months ago

(In principle, you don't even need a backend until you execute, but that would require passing one in every circuit call - unless you cache a backend in the Circuit object itself)

This is probably true. I'll try to drop the interface definition and test all the interfaces implementing algorithms directly.

MatteoRobbiati commented 3 months ago

In this case in particular, since the gradient will be computed independently on the interface, and that will be just used by the downstream to consume it, maybe you don't need to specify the interface at all, until you will actually use it. I.e. just specify it in the expectation() call :)

Step back: the Hamiltonian object right now is backend (interface 🙈) dependent. E.g. ham.matrix is a torch.tensor if initialized after setting qibo.set_backend("pytorch"). This is required if you want to run a symbolical_with_torch. Same if you want to run the symbolical_with_jax. The interface has to be jax friendly,