Postselection¶
Functions¶
-
template<typename BitstringVectorType, typename WeightVectorType, typename CallableType>
std::pair<BitstringVectorType, WeightVectorType> Qiskit::addon::sqd::postselect_bitstrings(const BitstringVectorType &bitstrings, const WeightVectorType &weights, CallableType filter_function)¶ Post-select bitstrings based on a given criteria.
Example¶
std::vector<std::bitset<6>> bitstrings = {0b011010, 0b100011}; std::vector<double> weights = {0.1, 0.7}; auto [new_bitstrings, new_weights] = Qiskit::addon::sqd::postselect_bitstrings( bitstrings, weights, Qiskit::addon::sqd::MatchesRightLeftHamming(1, 2) );
- Parameters:
bitstrings – [in] Bitstrings to consider.
weights – [in] Relative weight of each bitstring (need not be normalized to 1).
filter_function – [in] Callable which returns a boolean indicating whether a is to be kept.
- Template Parameters:
BitstringVectorType – Type of
bitstrings
, compatible withstd::vector<boost::dynamic_bitset<>>
.WeightVectorType – Type of
weights
, compatible withstd::vector<double>
.CallableType – Type of
filter_function
, compatible withbool (*f)(const BitstringType &)
.
- Returns:
Post-selected bitstrings and their corresponding weights, normalized to 1.
Classes¶
-
template<typename UnsignedType = uint32_t>
class MatchesRightLeftHamming¶ Functor which returns
true
if a bitstring has a predetermined Hamming weight.Public Functions
-
inline explicit MatchesRightLeftHamming(UnsignedType right_target, UnsignedType left_target)¶
Constructor.
-
template<typename BitstringType>
inline bool operator()(const BitstringType &bitstring) const¶ Function to be used as filter.
- Parameters:
bitstring – [in] Bitstring to consider.
- Template Parameters:
BitstringType – Type of
bitstring
, compatible withboost::dynamic_bitset<>
(for example).- Returns:
true
if the bitstring matches the Hamming weight that the functor was initialized with.
-
inline explicit MatchesRightLeftHamming(UnsignedType right_target, UnsignedType left_target)¶