gstenzel / qandle

QANDLE is a fast and simple quantum state-vector simulator for hybrid machine learning using the PyTorch library.
https://gstenzel.github.io/qandle/
MIT License
4 stars 0 forks source link

PyTorch integration #1

Closed wcqc closed 3 months ago

wcqc commented 3 months ago

Hi,

Does this support dynamically structured and defined computation graphs? For example, constructing a quantum circuit on the fly in the forward pass of PyTorch?

Thanks for any clarification.

gstenzel commented 3 months ago

This module draws most of its advantage in runtime speed by optimizing during __init__. Therefore, creating circuits during the forward pass is not recommended with this package. You might rather want look towards PennyLane for such use-case.

wcqc commented 3 months ago

How about reusing a predefined quantum circuit in init but feeding in different inputs in forward?

gstenzel commented 3 months ago

Yes, that is possible using named gates. Check out the docs: define a gate, e.g. RX(qubit=1, name="gate1"), and pass custom values to it during the forward pass of your module circuit(gate1=torch.tensor(1.2)). This should support batched inputs out-of-the-box.

Make sure to use the latest release of qandle (pip install --upgrade qandle), as I just fixed a bug caused by batching.