quspin.tools.misc.ints_to_array
- quspin.tools.misc.ints_to_array(basis_ints, N=None)[source]
Converts QuSpin basis type integers to a state array with binary elements.
This function takes an array of batched QuSpin basis type integers and converts it to a batched state array with 0/1 elements representing spin-down/up or 0/1 occupation.
- Parameters:
- basis_ints: np.ndarray(int)
- batched integers to be converted
- N: int, optional
number of sites (doubled for spinful fermions), default to be the biggest size
- represented by `basis_ints.dtype`.
- Returns:
- state_array: np.ndarray(np.uint8)
- batched state array with binary entries
Notes
Conversion to higher spins or larger occupation numbers is not yet implemented.
Examples
1from quspin.basis import spin_basis_general 2from quspin.tools.misc import ints_to_array, array_to_ints 3 4N = 10 5basis = spin_basis_general(N, make_basis=False) 6 7# initial states 8num_states = 2 9state_array = np.random.randint(0, 2, (num_states, N), dtype=np.uint8) 10print(f"The {num_states} initial states are") 11print(state_array) 12 13# convert state array to basis integers 14basis_ints = array_to_ints(state_array, basis.dtype) 15 16# apply Sx on site 4 17ME, bra, ket = basis.Op_bra_ket("x", [4], 1.0, np.float64, basis_ints) 18 19# convert outcome back to state array 20bra_array = ints_to_array(bra, N) 21 22print("Applying Sx on site 4, the new states are") 23print(bra_array)