pyqtorch
pyqtorch copied to clipboard
[Performance] Mutate state instead of using einsum for non-parametric operations
For non-parametric operations, we use tensordot/einsum to apply the operator. However, it could be more computationally efficient to simply mutate the existing state tensor
Prototype in: https://github.com/pasqal-io/pyqtorch/pull/125
Edit by @jpmoutinho :
The ideas behind this are described in https://arxiv.org/pdf/2303.01493
An example (which was what we initially did in the prototype above) is the X
gate: it should target all the state amplitudes where the target qubit is 0 and exchange their place with the ones where it is 1. Other rules for each gate have to be implemented.
The implementation should essentially amount to overriding the forward
method of each gate in pyqtorch.primitives.primitive_gates
and pyqtorch.primitives.parametric_gates
(well, the ones for which a rule can be added).
Testing it should be easy: just comparing the result to the normal usage of the apply_operator
. The function calc_mat_vec_wavefunction
in tests.helpers
would be useful. It is used extensively in the test_tensor.py
.
Overall, this could be interesting to explore, but it is not clear if we can make it efficient in torch (Spinoza does it in Rust). It should only be implemented if there is some clear performance gain over the normal apply_operator
.