pasqal-io / pyqtorch

PyTorch-based state vector simulator
https://pasqal-io.github.io/pyqtorch/
Apache License 2.0
45 stars 15 forks source link

[Refactor] Batch dimension as first dimension in tensors #11

Open Brogis1 opened 1 year ago

Brogis1 commented 1 year ago

Problem

Right now we have the batch dimension at the back of tensors in PyQ. However, in PyTorch it is in front.

Consequence

This entails reshaping tensors back and forth to make them compatible with PyTorch/PyQ convention. Hence, there are unnecessary code lines just for that.

Suggested Solution

We can make it possible to have both conventions (with a keyword argument) or just one (for instance, the batch dimension is the first and not last in PyQ tensors).

madagra commented 1 year ago

@Brogis1 Could you please add a small code snippets to the description above?

Slimane33 commented 1 year ago

Right now the PyQ convention is made to align with the qubit index (qubit indices between 0, ... n-1 coincide with the dimensions 0, ... n-1 of the tensor).

I think however that changing it would not be too much problematic for the usage. It seems that there is no critical reason for the batch to be last dimension, so I would be in favor to change it as you suggest.

Implementing both conventions seems hard because we would make all functions like _apply_gate being also dependent of theat keyword. This ay slow down perfomances.

RolandMacDoland commented 6 months ago

@dominikandreasseitz Is this still relevant ? I have the feeling it is closeable.

dominikandreasseitz commented 6 months ago

I think long-term it would make sense to make the switch