|
| 1 | +--- |
| 2 | +title: counts (v0.8) |
| 3 | +description: API reference for qiskit_addon_sqd.counts in qiskit-addon-sqd v0.8 |
| 4 | +in_page_toc_min_heading_level: 2 |
| 5 | +python_api_type: module |
| 6 | +python_api_name: qiskit_addon_sqd.counts |
| 7 | +--- |
| 8 | + |
| 9 | +<span id="module-qiskit_addon_sqd.counts" /> |
| 10 | + |
| 11 | +<span id="counts-qiskit-addon-sqd-counts" /> |
| 12 | + |
| 13 | +# Counts |
| 14 | + |
| 15 | +`qiskit_addon_sqd.counts` |
| 16 | + |
| 17 | +Functions for transforming counts dictionaries. |
| 18 | + |
| 19 | +### counts\_to\_arrays |
| 20 | + |
| 21 | +<Function id="qiskit_addon_sqd.counts.counts_to_arrays" github="https://github.com/Qiskit/qiskit-addon-sqd/tree/stable/0.8/qiskit_addon_sqd/counts.py#L21-L40" signature="counts_to_arrays(counts)"> |
| 22 | + Convert a counts dictionary into a bitstring matrix and a probability array. |
| 23 | + |
| 24 | + **Parameters** |
| 25 | + |
| 26 | + **counts** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")*,* [*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") *|*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")*]*) – The counts dictionary to convert |
| 27 | + |
| 28 | + **Returns** |
| 29 | + |
| 30 | + * A 2D array representing the sampled bitstrings. Each row represents a bitstring, and each element is a `bool` representation of the bit’s value |
| 31 | + * A 1D array containing the probability with which each bitstring was sampled |
| 32 | + |
| 33 | + **Return type** |
| 34 | + |
| 35 | + [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)")\[[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)"), [*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)")] |
| 36 | +</Function> |
| 37 | + |
| 38 | +### generate\_counts\_uniform |
| 39 | + |
| 40 | +<Function id="qiskit_addon_sqd.counts.generate_counts_uniform" github="https://github.com/Qiskit/qiskit-addon-sqd/tree/stable/0.8/qiskit_addon_sqd/counts.py#L43-L77" signature="generate_counts_uniform(num_samples, num_bits, rand_seed=None)"> |
| 41 | + Generate a bitstring counts dictionary of samples drawn from the uniform distribution. |
| 42 | + |
| 43 | + **Parameters** |
| 44 | + |
| 45 | + * **num\_samples** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The number of samples to draw |
| 46 | + * **num\_bits** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The number of bits in the bitstrings |
| 47 | + * **rand\_seed** ([*Generator*](https://numpy.org/doc/stable/reference/random/generator.html#numpy.random.Generator "(in NumPy v2.1)") *|*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *| None*) – A seed for controlling randomness |
| 48 | + |
| 49 | + **Returns** |
| 50 | + |
| 51 | + A dictionary mapping bitstrings of length `num_bits` to the number of times they were sampled. |
| 52 | + |
| 53 | + **Raises** |
| 54 | + |
| 55 | + [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.13)") – `num_samples` and `num_bits` must be positive integers. |
| 56 | + |
| 57 | + **Return type** |
| 58 | + |
| 59 | + [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)"), [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")] |
| 60 | +</Function> |
| 61 | + |
| 62 | +### generate\_counts\_bipartite\_hamming |
| 63 | + |
| 64 | +<Function id="qiskit_addon_sqd.counts.generate_counts_bipartite_hamming" github="https://github.com/Qiskit/qiskit-addon-sqd/tree/stable/0.8/qiskit_addon_sqd/counts.py#L80-L135" signature="generate_counts_bipartite_hamming(num_samples, num_bits, *, hamming_right, hamming_left, rand_seed=None)"> |
| 65 | + Generate a bitstring counts dictionary with specified bipartite hamming weight. |
| 66 | + |
| 67 | + **Parameters** |
| 68 | + |
| 69 | + * **num\_samples** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The number of samples to draw |
| 70 | + * **num\_bits** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The number of bits in the bitstrings |
| 71 | + * **hamming\_right** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The hamming weight on the right half of each bitstring |
| 72 | + * **hamming\_left** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The hamming weight on the left half of each bitstring |
| 73 | + * **rand\_seed** ([*Generator*](https://numpy.org/doc/stable/reference/random/generator.html#numpy.random.Generator "(in NumPy v2.1)") *|*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *| None*) – A seed for controlling randomness |
| 74 | + |
| 75 | + **Returns** |
| 76 | + |
| 77 | + A dictionary mapping bitstrings to the number of times they were sampled. Each half of each bitstring in the output dictionary will have a hamming weight as specified by the inputs. |
| 78 | + |
| 79 | + **Raises** |
| 80 | + |
| 81 | + * [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.13)") – `num_bits` and `num_samples` must be positive integers. |
| 82 | + * [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.13)") – Hamming weights must be specified as non-negative integers. |
| 83 | + * [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.13)") – `num_bits` must be even. |
| 84 | + |
| 85 | + **Return type** |
| 86 | + |
| 87 | + [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)"), [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")] |
| 88 | +</Function> |
| 89 | + |
| 90 | +### normalize\_counts\_dict |
| 91 | + |
| 92 | +<Function id="qiskit_addon_sqd.counts.normalize_counts_dict" github="https://github.com/Qiskit/qiskit-addon-sqd/tree/stable/0.8/qiskit_addon_sqd/counts.py#L138-L145" signature="normalize_counts_dict(counts)"> |
| 93 | + Convert a counts dictionary into a probability dictionary. |
| 94 | + |
| 95 | + **Parameters** |
| 96 | + |
| 97 | + **counts** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")*,* [*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") *|*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")*]*) |
| 98 | + |
| 99 | + **Return type** |
| 100 | + |
| 101 | + [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)"), [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")] |
| 102 | +</Function> |
| 103 | + |
0 commit comments