Skip to content

Fix TensorHilbert of non-indexable spaces

Vicentini Filippo requested to merge tensor-hilbert into master

Created by: femtobit

When creating a TensorHilbert from a sequence of component spaces, the constructor was failing when one of the component spaces was non-indexable:

>>> nk.hilbert.Fock(n_max=5, N=40) * nk.hilbert.Fock(n_max=7, N=40)
[...]
RuntimeError: The hilbert space is too large to be indexed.

This happened because the TensorHilbert was pre-computing several attributes that are only relevant if the composite space itself is indexable. This PR fixes the exception by performing the pre-computation only if the product space itself is indexable.

Corresponding tests are also added. This made it necessary to disentangle the tests for DiscreteHilbert and HomogeneousHilbert objects, which where previously treated as equivalent, causing the tests to fail for discrete but non-homogeneous product spaces.

Merge request reports