1.1 Hadamard Test#

Entanglement Entropy#

This method is also called ‘Swap test’. The interested users are encouraged to read the papers Identification of Symmetry-Protected Topological States on Noisy Quantum Computers and Entanglement spectroscopy on a quantum computer for the introduction and applications of this method.

hadamard_entangled_entropy#

def hadamard_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.

    - Which entropy:

        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.
    """

Dummy Data#

dummy_cases = [
    {"shots": 100, "counts": [{"0": 51, "1": 49}], "answer": 0},
    {"shots": 100, "counts": [{"0": 100}], "answer": 1},
    {"shots": 100, "counts": [{"1": 100}], "answer": 1},
]

Simple Example#

from qurry.process.hadamard_test import hadamard_entangled_entropy

test_result_2_1s = [
    hadamard_entangled_entropy(case["shots"], case["counts"]) for case in dummy_cases
]
print("| result of hadamard_entangled_entropy")
for i, result in enumerate(test_result_2_1s):
    print(f"| case {i + 1}")
    print(f"| {result}")
| result of hadamard_entangled_entropy
| case 1
| {'purity': 0.02, 'entropy': np.float64(5.643856189774724)}
| case 2
| {'purity': 1.0, 'entropy': np.float64(-0.0)}
| case 3
| {'purity': 1.0, 'entropy': np.float64(-0.0)}

Integration wit your own progress bar#

from tqdm import tqdm

all_counts_progress_01 = tqdm(
    dummy_cases,
    bar_format="| {desc} - {elapsed} < {remaining}",
)

test_result_2_2s = []
for case in all_counts_progress_01:
    test_result_2_2s.append(hadamard_entangled_entropy(case["shots"], case["counts"]))
    print(f"| case {i + 1}")
    print(f"| {test_result_2_2s[-1]}")
|  - 00:00 < ?
|  - 00:00 < 00:00
| case 3
| {'purity': 0.02, 'entropy': np.float64(5.643856189774724)}
| case 3
| {'purity': 1.0, 'entropy': np.float64(-0.0)}
| case 3
| {'purity': 1.0, 'entropy': np.float64(-0.0)}

Post-Process Availablities and Version Info#

from qurry.process.status import AVAIBILITY_STATESHEET

AVAIBILITY_STATESHEET
 | Qurrium version: 0.13.0
---------------------------------------------------------------------------
 ### Qurrium Post-Processing
   - Backend Availability ................... Python Cython Rust   JAX   
 - randomized_measure
   - entangled_entropy.entropy_core_2 ....... Yes    Depr.  Yes    No    
   - entangle_entropy.purity_cell_2 ......... Yes    Depr.  Yes    No    
   - entangled_entropy_v1.entropy_core ...... Yes    Depr.  Yes    No    
   - entangle_entropy_v1.purity_cell ........ Yes    Depr.  Yes    No    
   - wavefunction_overlap.echo_core_2 ....... Yes    Depr.  Yes    No    
   - wavefunction_overlap.echo_cell_2 ....... Yes    Depr.  Yes    No    
   - wavefunction_overlap_v1.echo_core ...... Yes    Depr.  Yes    No    
   - wavefunction_overlap_v1.echo_cell ...... Yes    Depr.  Yes    No    
 - hadamard_test
   - purity_echo_core ....................... Yes    No     Yes    No    
 - magnet_square
   - magnsq_core ............................ Yes    No     Yes    No    
 - string_operator
   - strop_core ............................. Yes    No     Yes    No    
 - classical_shadow
   - rho_m_core ............................. Yes    No     No     Yes   
 - utils
   - randomized ............................. Yes    Depr.  Yes    No    
   - counts_process ......................... Yes    No     Yes    No    
   - bit_slice .............................. Yes    No     Yes    No    
   - dummy .................................. Yes    No     Yes    No    
   - test ................................... Yes    No     Yes    No    
---------------------------------------------------------------------------
   + Yes ...... Working normally.
   + Error .... Exception occurred.
   + No ....... Not supported.
   + Depr. .... Deprecated.
---------------------------------------------------------------------------
by <Hoshi>