# epsproc.calc.density_v1 module¶

Density matrix routines

26/08/21 v1 Initial implementation

Dev code:

epsproc.calc.density_v1.densityCalc(da, denDims='LM', sumDims=None, keepDims=None, selDims=None, thres=None, squeeze=True)[source]

General density matrix from Xarray.

Compute density matrix as (outer product) da[denDims]*da[denDims].conj(), where dim specifies the dimension(s) to use. This is, essentially, the density matrix :math:row = |denDims\rangle \langle denDims|:math:

Parameters: da (xarray) – Data array to check & restack denDims (str, list, dict, optional, default = 'LM') – Dimensions to use as “state vector” from da. If a single dim (including stacked dims), which exists, this will be used directly. If multiple dims, will be restacked to a new dimension. Note that this can mix stacked and unstacked dims, and will restack if necessary. sumDims (str, list, bool, optional, default = None) – Set specific dims to sum (“trace”) over. If sumDims = True all dims, apart from denDims and keepDims, will be summed over. keepDims (str, list, optional, default = None) – Define dims to keep (won’t be summed over). Only used if sumDims = True. selDims (str, list, optional, default = None) – Dimensions to subselect from. thres (float, optional, default = None) – Threshold value. If set, used for both input and output datasets. squeeze (bool, optional, default = True) – Squeeze out singleton dims if True.

Notes

selDims, thres and squeeze are passed to the standard matEleSelector() function.

epsproc.calc.density_v1.dimRestack(da, stackDims=[])[source]

General Xarray restacker including multi-indexes.

Check dims in da, and restack according to refDims if necessary

Parameters: da (xarray) – Data array to check & restack stackDims (str, list, dict, optional, default = []) – Dimensions to check in da, and restack along if not already stacked. Note that this can mix stacked and unstacked dims, and will restack if necessary daOut (Xarray) – Data array with restacked dim. stackedDim (str) – Name of new stacked dim rsMap (dict) – Dictionary mapping for new stacked dim dimCheck (dict) – Full output from ep.util.misc.checkDims()

Examples

>>> # Assuming matE is a standard array of matrix elements
>>> daOut, stackedDim, rsMap, dimCheck = dimRestack(matE)  # OK, returns input + dim check results
>>> daOut, stackedDim, rsMap, dimCheck = dimRestack(matE, stackDims='LM')  # OK, returns original dims
>>> daOut, stackedDim, rsMap, dimCheck = dimRestack(matE, stackDims=['LM','mu'])  # OK, restacks dims


Notes

Passing new mappings as stackDims is currently not supported, e.g. dMap = {‘NewDim’:[d1,d2…]} will fail. For this case, just use the native da.stack(dMap).

multiDimXrToPD()
epsproc.calc.density_v1.matPlot(da, kdims=['LMp', 'LM'])[source]