Source code for qurry.process.hadamard_test.entangled_entropy
"""Post Processing - Hadamard Test - Entangled Entropy(:mod:`qurry.process.hadamard_test.entangled_entropy`)"""fromtypingimportOptionalimportnumpyasnpimporttqdmfrom..availabilityimportPostProcessingBackendLabelfrom.purity_echo_coreimportpurity_echo_core,DEFAULT_PROCESS_BACKEND
[docs]defhadamard_entangled_entropy(shots:int,counts:list[dict[str,int]],backend:PostProcessingBackendLabel=DEFAULT_PROCESS_BACKEND,pbar:Optional[tqdm.tqdm]=None,)->dict[str,float]:"""Calculate entangled entropy with more information combined. The entropy we compute is the Second Order Rényi Entropy. Args: shots (int): Shots of the experiment on quantum machine. counts (list[dict[str, int]]): Counts of the experiment on quantum machine. backend (PostProcessingBackendLabel, optional): Backend of the postprocessing. Defaults to DEFAULT_PROCESS_BACKEND. pbar (Optional[tqdm.tqdm], optional): Progress bar. Defaults to None. Raises: ValueError: Get degree neither 'int' nor 'tuple[int, int]'. ValueError: Measure range does not contain subsystem. Returns: dict[str, float]: Quantity of the experiment. """ifisinstance(pbar,tqdm.tqdm):pbar.set_description_str("Calculate entropy by Hadamard Test.")purity=purity_echo_core(shots,counts,backend)quantity={"purity":purity,"entropy":-np.log2(purity),}returnquantity