quimb.operator.hilbertspace¶
Tools for defining and manipulating Hilbert spaces.
Classes¶
Take a set of 'sites' (any sequence of sortable, hashable objects), and |
Functions¶
|
Given a list of edges, return a sorted list of unique sites and edges. |
|
Check if the given sector is valid for Z2 symmetry. |
|
Check if the given sector is valid for U1 symmetry. |
|
Check if the given sector is valid for U1U1 symmetry. |
|
|
|
Parse a site and dimension specification. |
Module Contents¶
- quimb.operator.hilbertspace.parse_edges_to_unique(edges)[source]¶
Given a list of edges, return a sorted list of unique sites and edges.
- Parameters:
edges (Iterable[tuple[hashable, hashable]]]) – The edges to parse.
- Returns:
sites (list of hashable) – The unique sites in the edges, sorted.
edges (list of (hashable, hashable)) – The unique edges, sorted.
- quimb.operator.hilbertspace.valid_z2_sector(sector)[source]¶
Check if the given sector is valid for Z2 symmetry.
- quimb.operator.hilbertspace.valid_u1_sector(sector, nsites)[source]¶
Check if the given sector is valid for U1 symmetry.
- quimb.operator.hilbertspace.valid_u1u1_sector(sector, nsites)[source]¶
Check if the given sector is valid for U1U1 symmetry.
- quimb.operator.hilbertspace.parse_sites_dims(sites, dims)[source]¶
Parse a site and dimension specification.
- Parameters:
- Returns:
parsed_sites (list of hashable) – The parsed list of sites (as yet unsorted).
parsed_dims (dict[hashable, int]) – A dictionary mapping each site to its dimension.
dims_used (set[int]) – The set of unique dimensions used.
- class quimb.operator.hilbertspace.HilbertSpace(sites, dims=2, order=None, sector=None, symmetry=None)[source]¶
Take a set of ‘sites’ (any sequence of sortable, hashable objects), and map this into a ‘register’ or linearly indexed range, optionally using a particular ordering. A symmetry and sector can also be specified, which will change the size of the Hilbert space and how the valid configurations are enumerated.
Some nomenclature:
site: a hashable label for a site in the Hilbert space. This can be any python object (e.g. tuple[str | int]).
register: a linear index for a site in the Hilbert space. This is an integer in the range [0, nsites), and requires an ordering of the sites.
configuration: a mapping from sites to their occupation number or spin state. This is a dictionary mapping from site to int.
flat configuration: a flat array of the occupation number or spin state of each site in the order given by this Hilbert space (i.e. a mapping of register to int). This is a 1D array of length nsites with dtype np.uint8, for efficient manipulation with numba and numpy.
rank: a linear index for a configuration in the Hilbert space, taking into account any symmetries and sectors. This is an integer in the range [0, size), where size is the size of the Hilbert space given the symmetry and sector.
- Parameters:
sites (int, sequence of hashable objects, or dict) – The sites to map into a linear register. If an integer, simply use
range(sites). If a dict, the keys are the sites and the values are the dimensions, in which case the dims argument is ignored.dims (int or sequence of int, optional) – The local dimensions of each site. If an integer, all sites have the same dimension. If a sequence, it should be the same length as sites. You can also provide the dimensions as part of the sites argument by passing a dict, in which case this argument is ignored.
order (bool, sequence[hashable] or callable, optional) – How to order the sites. If None or False (default), the sites are kept in the order supplied. If True, the sites are sorted. If a sequence, it should be a permutation of the sites, and this will be used to order them. If a callable, it should be a sorting key function which will be used to order the sites.
sector ({None, str, int, ((int, int), (int, int))}, optional) – The sector of the Hilbert space. If None, no sector is assumed.
symmetry ({None, "Z2", "U1", "U1U1"}, optional) – The symmetry of the Hilbert space if any. If None and a sector is provided, the symmetry will be inferred from the sector if possible.
- _size = None¶
- _sizes = None¶
- _strides = None¶
- _pt = None¶
- set_ordering(order)[source]¶
Set the ordering of the sites in this Hilbert space.
- Parameters:
order (bool, sequence[hashable] or callable, optional) – How to order the sites. If None or False (default), the sites are kept in the order supplied. If True, the sites are sorted. If a sequence, it should be a permutation of the sites, and this will be used to order them. If a callable, it should be a sorting key function which will be used to order the sites.
- classmethod from_edges(edges, order=None)[source]¶
Construct a HilbertSpace from a set of edges, which are pairs of sites.
- Parameters:
edges (Iterable[tuple[hashable, hashable]]]) – The edges to parse.
order (bool, sequence[hashable] or callable, optional) – How to order the sites. If None or False (default), the sites are kept in the order supplied. If True, the sites are sorted. If a sequence, it should be a permutation of the sites, and this will be used to order them. If a callable, it should be a sorting key function which will be used to order the sites.
- property sites¶
The ordered tuple of all sites in the Hilbert space.
- property sector¶
The sector of the Hilbert space.
- get_sector_numba(sector=None, symmetry=None)[source]¶
The sector of the Hilbert space, in ‘numba form’. A non-default symmetry and sector can be provided.
- Parameters:
sector ({None, str, int, ((int, int), (int, int))}, optional) – The sector of the Hilbert space. If None, the default sector is used.
symmetry ({None, "Z2", "U1", "U1U1"}, optional) – The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible.
- Returns:
sector (ndarray[int64]) – The sector of the Hilbert space, in ‘numba form’. This is a 1D array of length 1, 2 or 4, depending on the symmetry.
symmetry (str) – The symmetry of the Hilbert space. This is one of “None”, “Z2”, “U1”, or “U1U1”.
- property symmetry¶
The symmetry of the Hilbert space.
- property nsites¶
The total number of sites in the Hilbert space.
- property sizes¶
Get a numpy array of the ordered sizes of each site in the Hilbert space.
- property strides¶
Get the strides for each site in the Hilbert space.
- get_size(sector=None, symmetry=None)[source]¶
Get the size of the Hilbert space, optionally given a non-default symmetry and sector.
- Parameters:
sector ({None, str, int, ((int, int), (int, int))}, optional) – The sector of the Hilbert space. If None, the default sector is used.
symmetry ({None, "Z2", "U1", "U1U1"}, optional) – The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible.
- property size¶
Get the size of this Hilbert space, taking into account the default symmetry and sector.
- rank_to_flatconfig(rank)[source]¶
Convert a rank (linear index) into a flat configuration.
- Parameters:
rank (int) – The rank (linear index) to convert.
- Returns:
flatconfig – A flat configuration, with the occupation number or spin state of each site in the order given by this
HilbertSpace.- Return type:
ndarray[uint8]
- flatconfig_to_rank(flatconfig)[source]¶
Convert a flat configuration into a rank (linear index).
- Parameters:
flatconfig (ndarray[uint8]) – A flat configuration, with the occupation number or spin state of each site in the order given by this
HilbertSpace.- Returns:
rank – The rank (linear index) of the flat configuration in the Hilbert space.
- Return type:
- config_to_flatconfig(config)[source]¶
Turn a configuration into a flat configuration, assuming the order given by this
HilbertSpace.
- flatconfig_to_config(flatconfig)[source]¶
Turn a flat configuration into a configuration, assuming the order given by this
HilbertSpace.
- rand_rank(seed=None)[source]¶
Get a random rank (linear index) in the Hilbert space.
- Parameters:
seed (None, int or numpy.random.Generator, optional) – The random seed or generator to use. If None, a new generator will be created with default settings.
- Returns:
rank – A random rank in the Hilbert space.
- Return type:
int64
- rand_flatconfig(seed=None)[source]¶
Get a random flat configuration.
- Parameters:
seed (None, int or numpy.random.Generator, optional) – The random seed or generator to use. If None, a new generator will be created with default settings.
- Returns:
flatconfig – A flat configuration, with the occupation number or spin state of each site in the order given by this
HilbertSpace.- Return type:
ndarray[uint8]
- rand_config(seed=None)[source]¶
Get a random configuration.
- Parameters:
seed (None, int or numpy.random.Generator, optional) – The random seed or generator to use. If None, a new generator will be created with default settings.
- Returns:
config – A dictionary mapping sites to their occupation number / spin state.
- Return type:
dict[hashable, np.uint8]