bitbasis¶
Functions¶
|
Given global size n, and a rank in [0, world_size), return the size of |
|
Given global size n, and a rank in [0, world_size), return the range of |
|
Get the nth bit of val. |
|
Flip the nth bit of val. |
|
|
Get every flat configuration of length n with k bits set. |
|
|
Given a flat configuration, return the corresponding bitstring. |
|
Compute the binomial coefficient n choose k. |
|
Get an array of all 'bits' (integers), with n bits, and k of them set. |
|
Given a bitstring b, return the rank of the bitstring in the |
|
Given a rank r, return the bitstring of length n with k bits set |
|
Get the outer product of two bit arrays. |
|
Create a bit basis with number conservation. |
|
Build of map of bits to linear indices, suitable for use with numba. |
|
|
|
|
|
Build an operator in COO form, using the basis |
|
Encode a 'configuration' as a bit. |
|
Decode a bit to a configuration. |
Module Contents¶
- bitbasis.get_local_size(n, rank, world_size)¶
Given global size n, and a rank in [0, world_size), return the size of the portion assigned to this rank.
- bitbasis.get_local_range(n, rank, world_size)¶
Given global size n, and a rank in [0, world_size), return the range of indices assigned to this rank.
- bitbasis.get_nth_bit(val, n)¶
Get the nth bit of val.
Examples
>>> get_nth_bit(0b101, 1) 0
- bitbasis.flip_nth_bit(val, n)¶
Flip the nth bit of val.
Examples
>>> bin(flip_nth_bit(0b101, 1)) 0b111
- bitbasis._recursively_fill_flatconfigs(flatconfigs, n, k, c, r)¶
- bitbasis.get_all_equal_weight_flatconfigs(n, k)¶
Get every flat configuration of length n with k bits set.
- bitbasis.flatconfig_to_bit(flatconfig)¶
Given a flat configuration, return the corresponding bitstring.
- bitbasis.comb(n, k)¶
Compute the binomial coefficient n choose k.
- bitbasis.get_all_equal_weight_bits(n, k, dtype=np.int64)¶
Get an array of all ‘bits’ (integers), with n bits, and k of them set.
- bitbasis.bit_to_rank(b, n, k)¶
Given a bitstring b, return the rank of the bitstring in the basis of all bitstrings of length n with k bits set. Adapted from https://dlbeer.co.nz/articles/kwbs.html.
- bitbasis.rank_to_bit(r, n, k)¶
Given a rank r, return the bitstring of length n with k bits set that has rank r in the basis of all bitstrings of length n with k bits set. Adapted from https://dlbeer.co.nz/articles/kwbs.html.
- bitbasis.product_of_bits(b1, b2, n2, dtype=np.int64)¶
Get the outer product of two bit arrays.
- bitbasis.get_number_bitbasis(*nk_pairs, dtype=np.int64)¶
Create a bit basis with number conservation.
- Parameters:
nk_pairs (sequence of (int, int)) – Each element is a pair (n, k) where n is the number of bits, and k is the number of bits that are set. The basis will be the product of all supplied pairs.
- Returns:
basis – An array of integers, each representing a bit string. The size will be
prod(comb(n, k) for n, k in nk_pairs).- Return type:
ndarray
Examples
A single number conserving basis:
>>> for i, b in enumerate(get_number_bitbasis((4, 2))): >>> print(f"{i}: {b:0>4b}") 0: 0011 1: 0101 2: 0110 3: 1001 4: 1010 5: 1100
A product of two number conserving bases, e.g. n_up and n_down:
>>> for b in get_number_bitbasis((3, 2), (3, 1)): >>> print(f"{b:0>6b}") 011001 011010 011100 101001 101010 101100 110001 110010 110100
- bitbasis.build_bitmap(configs)¶
Build of map of bits to linear indices, suitable for use with numba.
- bitbasis.coupled_bits_numba(bi, coupling_map)¶
- bitbasis._build_coo_numba_core(bits, coupling_map, bitmap=None, dtype=np.float64)¶
- bitbasis.build_coo_numba(bits, coupling_map, dtype=None, parallel=False)¶
- Build an operator in COO form, using the basis
bitsand the coupling_map, optionally multithreaded.
- Parameters:
bits (array) – An array of integers, each representing a bit string.
coupling_map (Dict[int, Dict[int, Dict[int, Tuple[int, float]]]]) – A nested numba dictionary of couplings. The outermost key is the term index, the next key is the register, and the innermost key is the bit index. The value is a tuple of (coupled bit index, coupling coefficient).
parallel (bool or int, optional) – Whether to parallelize the computation. If an integer is given, it specifies the number of threads to use.
- Returns:
data (array) – The non-zero elements of the operator.
cis (array) – The row indices of the non-zero elements.
cjs (array) – The column indices of the non-zero elements.
- Build an operator in COO form, using the basis
- bitbasis.config_to_bit(self, config)¶
Encode a ‘configuration’ as a bit.