Skip to content

[RFC] Hilbert space new API

Vicentini Filippo requested to merge PhilipVinc/hilbert_api into master

Created by: PhilipVinc

In general, in netket we do not need to work with graphs, unless we are working with symmetries. Especially to newcomers, but also to make the API more succinct, I think it would bee nice to support an usage like

import netket
# 
>>> netket.hilbert.Spin(1/2)**4
Spin(s=1/2, graph=4)
>>> netket.operator.spin.sigmax(hi, 1)
<netket.operator._local_operator.LocalOperator object at 0x10f84fcd0>

Where basically we can define the local Hilbert space (which implicitly it will be defined on an Edgeless graph with 1 node) and then tensor-exponentiate it to define it on N sites.

Under the hood, pow on an Hilbert space is doing pow on the graph, which corresponds to a disjoint union (or direct sum) of the two graphs, which I believe to be the only sensible operation possible in this case.

Of course, this mainly makes sense when working with Edgeless graphs.

--

To make this kind of api work, we need to switch two arguments: the Spin rational. (1//2, 1, 3//2...) should become the first argument, so that if the graph (now second argument) is unspecified, we can assume it to be an edgeless(1) graph.

I'd propose to change all hilbert spaces to such api.

--

In the future, this should allow us to also define multiplication among hilbert spaces (technically \otimes, but python let's us only use *) and compose non-homogeneeous hilbert spaces together. But that's for a future PR, as it would require some work on the samplers.

If you agree with this new api, then I will also convert the other hilbert spaces (bosons, qubits, and local_operator).

Merge request reports