data_conv¶
-
libra_py.data_conv.
MATRIX2nparray
(data)[source]¶ Converts both Libra MATRIX ( N, M ) object and CMATRIX ( N, M ) object into a 2D np.array of shape( N, M )
- Parameters
data (Libra MATRIX object of dimension N x M) – data to be converted
- Returns
2D np.array of shape( N, M )
- Return type
2d np.array
-
libra_py.data_conv.
form_block_matrix
(mat_a, mat_b, mat_c, mat_d)[source]¶ This function gets four numpy arrays and concatenate them into a new matrix in a block format. These matrices should have the same shape on each side which they get concatenated.
- S = | |
- Parameters
mat_a (2D numpy arrays) – The matrices which will form the block matrix
mat_b (2D numpy arrays) – The matrices which will form the block matrix
mat_c (2D numpy arrays) – The matrices which will form the block matrix
mat_d (2D numpy arrays) – The matrices which will form the block matrix
- Returns
The block matrix of the four matrices above.
- Return type
block_matrix ( numpy 2D array )
-
libra_py.data_conv.
list2MATRIX
(data)[source]¶ Converts a list of N doubles into a MATRIX(N,1) object
- Parameters
data (list of doubles) – data to be converted
- Returns
a matrix representation of the data
- Return type
MATRIX(N,1)
-
libra_py.data_conv.
make_list
(nitems, value)[source]¶ Creates a list of nitems items, each of which is value
-
libra_py.data_conv.
matrix2list
(q)[source]¶ Converts the MATRIX(ndof, 1) or CMATRIX(ndof, 1) to a list of ndof float/complex numbers
Args:
q ( MATRIX(ndof, 1) or CMATRIX(ndof, 1) ): input matrix
Returns:
list : list representation of the matrix
-
libra_py.data_conv.
nparray2CMATRIX
(data)[source]¶ Converts 2D np.array of shape( N, M ) doubles into a CMATRIX( N, M ) object The numpy array should be complex
- Parameters
data (2D np.array of dimension N x M) – data to be converted
- Returns
a matrix representation of the data
- Return type
MATRIX( N, M )
-
libra_py.data_conv.
nparray2MATRIX
(data)[source]¶ Converts 2D np.array of shape( N, M ) doubles into a MATRIX( N, M ) object The numpy array can contain either complex or real values
- Parameters
data (2D np.array of dimension N x M) – data to be converted
- Returns
a matrix representation of the data
- Return type
MATRIX( N, M )
-
libra_py.data_conv.
scale_NAC
(X, a, b, scaling_factor)[source]¶ Rescales only the matrix elements X_ab by a uniform scaling factor: X_ab(original) -> ( X_ab ) x (scaling_factor),
- Parameters
X (list of lists of CMATRIX(nstates, nstates)) – the original data stored as X[idata][step] - a CMATRIX(nstates, nstates) for the dataset idata and time step step
scaling_factor (double or complex) – the rescaling factor
- Returns
but transforms X input directly, so changes the original input
- Return type
-
libra_py.data_conv.
scale_NACs
(X, scaling_factor)[source]¶ Rescales all the off-diagonal matrix elements X_ab by a uniform scaling factor: X_ab(original) -> ( X_ab ) x (scaling_factor), for all a!=b
- Parameters
X (list of lists of CMATRIX(nstates, nstates)) – the original data stored as X[idata][step] - a CMATRIX(nstates, nstates) for the dataset idata and time step step
scaling_factor (double or complex) – the rescaling factor
- Returns
but transforms X input directly, so changes the original input
- Return type
-
libra_py.data_conv.
scissor
(X, a, dE)[source]¶ Shift the diagonal elements of X : X_ii for all i = a, a+1, … by a constant value dE X_ii(original) -> ( X_ii ) + dE, for all i >= a
- Parameters
X (list of lists of CMATRIX(nstates, nstates)) – the original data stored as X[idata][step] - a CMATRIX(nstates, nstates) for the dataset idata and time step step
dE (double or complex) – the shift magnitude
- Returns
but transforms X input directly, so changes the original input
- Return type
-
libra_py.data_conv.
transform_data
(X, params)[source]¶ This is an auxiliary function to transform the original matrices X (e.g. H_vib) according to: X(original) -> ( X + shift1 ) (x) (scale) + shift2,
Here, (x) indicates the element-wise multiplicaiton, and shift1, shift2, and scale are matrices
- Parameters
X (list of lists of CMATRIX(nstates, nstates)) – the original data stored as X[idata][step] - a CMATRIX(nstates, nstates) for the dataset idata and time step step
params (dictionary) –
parameters controlling the transformation
params[“shift1”] ( CMATRIX(nstates,nstates) ): first shift corrections [units of X], [default: zero]
params[“shift2”] ( CMATRIX(nstates,nstates) ): second shift corrections [units of X], [default: zero]
params[“scale”] ( CMATRIX(nstates,nstates) ): scaling of the X [unitless], [default: 1.0 in all matrix elements]
- Returns
but transforms X input directly, so changes the original input
- Return type
Example
Lets say we have a data set of 2x2 matrices and we want to increase the energy gap by 0.1 units and scale the couplings by a factor of 3. Then, the input is going to be like this:
>>> scl = CMATRIX(2,2); >>> scl.set(0,0, 1.0+0.0j); scl.set(0,1, 3.0+0.0j); >>> scl.set(0,0, 3.0+0.0j); scl.set(0,1, 1.0+0.0j); >>> shi = CMATRIX(2,2); >>> shi.set(0,0, 0.0+0.0j); shi.set(0,1, 0.0+0.0j); >>> shi.set(0,0, 0.0+0.0j); shi.set(0,1, 0.1+0.0j); >>> transform_data(X, {"shift2":shi, "scale":scl })
-
libra_py.data_conv.
unit_conversion
(X, scaling_factor)[source]¶ Rescales the data X uniformly: X(original) -> ( X ) (x) (scaling_factor),
Here, (x) indicates the element-wise multiplicaiton, and shift1, shift2, and scale are matrices
- Parameters
X (list of lists of CMATRIX(nstates, nstates)) – the original data stored as X[idata][step] - a CMATRIX(nstates, nstates) for the dataset idata and time step step
scaling_factor (double or complex) – the rescaling factor
- Returns
but transforms X input directly, so changes the original input
- Return type
-
libra_py.data_conv.
unpack1
(H, i, j, component=2)[source]¶ Converts a list of CMATRIX or MATRIX objects into a list of doubles. These numbers are the time-series of a specifiend component (real of imaginary) of a specified matrix element (i,j) of each matrix: res[k] = H[k].get(i,j).component
- Parameters
H (list of CMATRIX(n, m) or MATRIX(n, m)) – time-series of the matrices
i (int) – row index of the matrix element of interest
j (int) – column index of the matrix element of interest
component (int) –
index selecting real or imaginary component
0: real
1: imaginary
2: the whole thing - use for real matrices [ default ]
- Returns
time-series of a given matrix element’s component
- Return type
list of doubles
-
libra_py.data_conv.
unpack2
(H, i, component=2)[source]¶ Converts a CMATRIX or MATRIX object into a list of doubles. These numbers are the time-series of a specifiend component (real of imaginary) of a specified matrix column
`i`
res[k] = H.get(k,i).component- Parameters
- Returns
time-series of a given matrix column’s components
- Return type
list of doubles