core.bitssample#
This module provides classes for representing and manipulating bit samples from quantum computations in Qamomile.
Classes#
Represents a single bit array sample with its occurrence count. |
|
Represents a set of bit array samples from quantum computations. |
Module Contents#
- class BitsSample#
Represents a single bit array sample with its occurrence count.
- num_occurrences#
The number of times this bit array occurred in the sample set.
- Type:
int
- bits#
The bit array represented as a list of integers (0 or 1).
- Type:
List[int]
- num_occurrences: int#
- bits: list[int]#
- property num_bits: int#
Returns the number of bits in the sample.
- Returns:
The length of the bit array.
- Return type:
int
- class BitsSampleSet#
Represents a set of bit array samples from quantum computations.
This class provides methods for converting between different representations of the sample set and analyzing the results.
- bitarrays#
A list of BitsSample objects representing the sample set.
- Type:
List[BitsSample]
- bitarrays: list[BitsSample]#
- get_int_counts() dict[int, int] #
Converts the bit array samples to integer counts.
This method interprets each bit array as a binary number and counts the occurrences of each unique integer value.
- Returns:
A dictionary mapping integer values to their occurrence counts.
- Return type:
dict[int, int]
- classmethod from_int_counts(int_counts: dict[int, int], bit_length: int) BitsSampleSet #
Creates a BitsSampleSet from a dictionary of integer counts.
This class method converts integer-based sample counts to bit array samples.
- Parameters:
int_counts (dict[int, int]) – A dictionary mapping integer values to their occurrence counts.
bit_length (int) – The length of the bit arrays to be created.
- Returns:
A new BitsSampleSet object containing the converted samples.
- Return type:
- get_most_common(n: int = 1) list[BitsSample] #
Returns the n most common bit samples in the set.
- Parameters:
n (int, optional) – The number of most common samples to return. Defaults to 1.
- Returns:
- A list of the n most common BitsSample objects,
sorted by occurrence in descending order.
- Return type:
List[BitsSample]
- total_samples() int #
Calculates the total number of samples in the set.
- Returns:
The sum of occurrence counts across all samples.
- Return type:
int