Source code for qlauncher.utils

 1"""Utility functions for QLauncher"""
 2
 3from collections import defaultdict
 4from itertools import chain
 5from typing import TypeVar
 6
 7import numpy as np
 8
 9T = TypeVar('T')
10
11
[docs] 12def sum_counts(*counts: dict[T, int]) -> dict[T, int]: 13 """Sum up counts from multiple count dicts into one count dict""" 14 result = defaultdict(int) 15 for key, value in chain(*(c.items() for c in counts)): 16 result[key] += value 17 return result
18 19
[docs] 20def int_to_bitstring(number: int, total_bits: int): 21 return np.binary_repr(number, total_bits)[::-1]