1.2 Randomized Measurement¶
Entanglement Entropy¶
This method is based on Probing Rényi entanglement entropy via randomized measurements with deplorizing error mitigation by Simple mitigation of global depolarizing errors in quantum simulations.
randomized_entangled_entropy
¶
Here, we assume you already have the calculated data. You can call the function randomized_entangled_entropy
from qurry.process.randomized_measure
to calculate the entropy.
This function requires only three arguments: shots
, counts
, and selected_classical_registers
. All other arguments are optional.
Note that selected_classical_registers
expects a list of bitstring indices, NOT qubit indices, as these are distinct.
The following is the arguments of the function:
def randomized_entangled_entropy(
shots: int,
counts: list[dict[str, int]],
selected_classical_registers: Optional[list[int]] = None,
backend: PostProcessingBackendLabel = DEFAULT_PROCESS_BACKEND,
pbar: Optional[tqdm.tqdm] = None,
) -> EntangledEntropyResult:
"""Calculate entangled entropy.
Args:
shots (int):
Shots of the experiment on quantum machine.
counts (list[dict[str, int]]):
Counts of the experiment on quantum machine.
selected_classical_registers (Optional[list[int]], optional):
The list of **the index of the selected_classical_registers**.
backend (ExistingProcessBackendLabel, optional):
Backend for the process. Defaults to DEFAULT_PROCESS_BACKEND.
pbar (Optional[tqdm.tqdm], optional):
The progress bar API, you can use put a :cls:`tqdm` object here.
This function will update the progress bar description.
Defaults to None.
Returns:
EntangledEntropyReturn:
A dictionary contains purity, entropy, a dictionary of each purity cell,
entropySD, puritySD, num_classical_registers, classical_registers,
classical_registers_actually, counts_num, taking_time.
"""
This function returns a dictionary that contains the entropy, purity, and other relevant information.
The returned dict
contains the following information:
class EntangledEntropyResult(TypedDict, total=False):
"""The return type of the post-processing for entangled entropy."""
purity: GenericFloatType
"""The purity of the system."""
entropy: GenericFloatType
"""The entropy of the system."""
puritySD: GenericFloatType
"""The standard deviation of the purity."""
entropySD: GenericFloatType
"""The standard deviation of the entropy."""
purityCells: Union[dict[int, np.float64], dict[int, float]]
"""The purity of each single count."""
# new added
num_classical_registers: int
"""The number of classical registers."""
classical_registers: Optional[list[int]]
"""The list of the index of the selected classical registers."""
classical_registers_actually: list[int]
"""The list of the index of the selected classical registers which is actually used."""
# refactored
counts_num: int
"""The number of counts."""
taking_time: GenericFloatType
"""The calculation time."""
Dummy Data¶
from qurry.capsule import quickRead
easy_dummy: dict[str, dict[str, int]] = quickRead("../easy-dummy.json")
large_dummy_list = [easy_dummy["0"] for _ in range(100)]
Simple Example¶
from qurry.process.randomized_measure import randomized_entangled_entropy
test_result_1_1_1 = randomized_entangled_entropy(4096, large_dummy_list, list(range(6)))
from pprint import pprint
print("| result of randomized_entangled_entropy except for purityCells")
pprint({k: v for k, v in test_result_1_1_1.items() if k != "purityCells"})
# "purityCells" is too long we skip it here
print("| result of randomized_entangled_entropy[purityCells]")
print(test_result_1_1_1["purityCells"][0])
print(test_result_1_1_1["purityCells"][1])
| result of randomized_entangled_entropy except for purityCells
{'classical_registers': [0, 1, 2, 3, 4, 5],
'classical_registers_actually': [0, 1, 2, 3, 4, 5],
'counts_num': 100,
'entropy': np.float64(-0.08786065308638322),
'entropySD': np.float64(0.0),
'num_classical_registers': 8,
'purity': np.float64(1.0627930164337158),
'puritySD': np.float64(0.0),
'taking_time': 0.002455481}
| result of randomized_entangled_entropy[purityCells]
1.0627930164337158
1.0627930164337158
Integration with your own progress bar¶
from tqdm import tqdm
import time
all_counts_progress_01 = tqdm(
[
(4096, large_dummy_list, list(range(6))),
(4096, large_dummy_list, list(range(2, 8))),
(4096, large_dummy_list, list(range(7))),
(4096, large_dummy_list, list(range(0, 7))),
(4096, large_dummy_list, [0, 1, 2, 6, 7]),
(4096, large_dummy_list, [3, 4, 5, 6, 7, 0, 1]),
],
bar_format="| {desc} - {elapsed} < {remaining}",
)
test_result_1_1_2 = []
for tmp_shot, tmp_counts, tmp_partition in all_counts_progress_01:
print(tmp_partition)
test_result_1_1_2.append(
randomized_entangled_entropy(
tmp_shot, tmp_counts, tmp_partition, pbar=all_counts_progress_01
)
)
time.sleep(0.5)
| - 00:00 < ?
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5]. - 00:00 < ?
[0, 1, 2, 3, 4, 5]
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5]. - 00:00 < 00:02
| Calculate selected classical registers: [2, 3, 4, 5, 6, 7]. - 00:00 < 00:02
[2, 3, 4, 5, 6, 7]
| Calculate selected classical registers: [2, 3, 4, 5, 6, 7]. - 00:01 < 00:02
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:01 < 00:02
[0, 1, 2, 3, 4, 5, 6]
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:01 < 00:01
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:01 < 00:01
[0, 1, 2, 3, 4, 5, 6]
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:02 < 00:01
| Calculate selected classical registers: [0, 1, 2, 6, 7]. - 00:02 < 00:01
[0, 1, 2, 6, 7]
| Calculate selected classical registers: [0, 1, 2, 6, 7]. - 00:02 < 00:00
| Calculate selected classical registers: [3, 4, 5, 6, 7, 0, 1]. - 00:02 < 00:00
[3, 4, 5, 6, 7, 0, 1]
| Calculate selected classical registers: [3, 4, 5, 6, 7, 0, 1]. - 00:03 < 00:00
| Calculate selected classical registers: [3, 4, 5, 6, 7, 0, 1]. - 00:03 < 00:00
Using Python backend¶
It will be slow. You’d better think twice before using it.
all_counts_progress_02 = tqdm(
[
(4096, large_dummy_list, list(range(6))),
(4096, large_dummy_list, list(range(2, 8))),
(4096, large_dummy_list, list(range(7))),
(4096, large_dummy_list, list(range(0, 7))),
(4096, large_dummy_list, [0, 1, 2, 6, 7]),
(4096, large_dummy_list, [3, 4, 5, 6, 7, 0, 1]),
],
bar_format="| {desc} - {elapsed} < {remaining}",
)
test_result_1_1_2 = []
for tmp_shot, tmp_counts, tmp_partition in all_counts_progress_02:
print(tmp_partition)
test_result_1_1_2.append(
randomized_entangled_entropy(
tmp_shot,
tmp_counts,
tmp_partition,
pbar=all_counts_progress_02,
backend="Python",
)
)
time.sleep(0.5)
| - 00:00 < ?
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5]. - 00:00 < ?
[0, 1, 2, 3, 4, 5]
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5]. - 00:05 < 00:28
| Calculate selected classical registers: [2, 3, 4, 5, 6, 7]. - 00:05 < 00:28
[2, 3, 4, 5, 6, 7]
| Calculate selected classical registers: [2, 3, 4, 5, 6, 7]. - 00:11 < 00:23
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:11 < 00:23
[0, 1, 2, 3, 4, 5, 6]
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:18 < 00:18
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:18 < 00:18
[0, 1, 2, 3, 4, 5, 6]
| Calculate selected classical registers: [0, 1, 2, 3, 4, 5, 6]. - 00:25 < 00:12
| Calculate selected classical registers: [0, 1, 2, 6, 7]. - 00:25 < 00:12
[0, 1, 2, 6, 7]
| Calculate selected classical registers: [0, 1, 2, 6, 7]. - 00:31 < 00:06
| Calculate selected classical registers: [3, 4, 5, 6, 7, 0, 1]. - 00:31 < 00:06
[3, 4, 5, 6, 7, 0, 1]
| Calculate selected classical registers: [3, 4, 5, 6, 7, 0, 1]. - 00:37 < 00:00
| Calculate selected classical registers: [3, 4, 5, 6, 7, 0, 1]. - 00:37 < 00:00
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>