classical_shadow
¶
Post Processing - Classical Shadow - Classical Shadow
(qurry.process.classical_shadow.classical_shadow
)
- qurry.process.classical_shadow.classical_shadow.classical_shadow_complex(shots: int, counts: list[dict[str, int]], random_unitary_um: dict[int, dict[int, Literal[0, 1, 2] | int]], selected_classical_registers: Iterable[int], given_operators: list[ndarray[tuple[int, int], dtype[complex128]]] | None = None, accuracy_prob_comp_delta: float = 0.01, max_shadow_norm: float | None = None, rho_method: Literal['numpy', 'numpy_precomputed'] | str | Literal['numpy_flatten', 'jax_flatten'] = 'numpy_precomputed', trace_method: Literal['trace_of_matmul', 'quick_trace_of_matmul', 'einsum_ij_ji'] | str | Literal['einsum_aij_bji_to_ab_numpy', 'einsum_aij_bji_to_ab_jax'] = 'einsum_aij_bji_to_ab_jax', estimate_trace_method: Literal['einsum_aij_bji_to_ab_numpy', 'einsum_aij_bji_to_ab_jax'] | str = 'einsum_aij_bji_to_ab_jax', pbar: tqdm | None = None) ClassicalShadowComplex [source]¶
Calculate the expectation value of Rho and the purity by classical shadow.
- Reference:
Note
Predicting many properties of a quantum system from very few measurements -
Huang, Hsin-Yuan and Kueng, Richard and Preskill, John [doi:10.1038/s41567-020-0932-7](
The randomized measurement toolbox -
Elben, Andreas and Flammia, Steven T. and Huang, Hsin-Yuan and Kueng, Richard and Preskill, John and Vermersch, Benoît and Zoller, Peter [doi:10.1038/s42254-022-00535-2](
- Parameters:
shots (int) – The number of shots.
random_unitary_um (dict[int, dict[int, Union[Literal[0, 1, 2], int]]]) – The shadow direction of the unitary operators.
selected_classical_registers (Iterable[int]) – The list of the index of the selected_classical_registers.
given_operators (list[np.ndarray[tuple[int, int], np.dtype[np.complex128]]]) – The list of the operators to estimate. Defaults to None.
accuracy_prob_comp_delta (float, optional) – The accuracy probability component delta. Defaults to 0.01.
max_shadow_norm (Optional[float], optional) – The maximum shadow norm. Defaults to None. If it is None, it will be calculated by the largest shadow norm upper bound. If it is not None, it must be a positive float number. It is \(|| O_i - \frac{\text{tr}(O_i)}{2^n} ||_{\text{shadow}}^2\) in equation.
rho_method (RhoMCoreMethod, optional) – The method to use for the calculation. Defaults to “numpy_precomputed”. It can be either “numpy”, “numpy_precomputed”, “jax_flatten”, or “numpy_flatten”. - “numpy”: Use Numpy to calculate the rho_m. - “numpy_precomputed”: Use Numpy to calculate the rho_m with precomputed values. - “numpy_flatten”: Use Numpy to calculate the rho_m with a flattening workflow. Currently, “numpy_precomputed” is the best option for performance.
trace_method (TraceRhoMethod, optional) –
The method to calculate the trace of Rho square. - “trace_of_matmul”:
Use np.trace(np.matmul(rho_m1, rho_m2)) to calculate the each summation item in rho_m_list.
- ”quick_trace_of_matmul” or “einsum_ij_ji”:
Use np.einsum(“ij,ji”, rho_m1, rho_m2) to calculate the each summation item in rho_m_list.
- ”einsum_aij_bji_to_ab_numpy”:
Use np.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
- ”einsum_aij_bji_to_ab_jax”:
Use jnp.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
estimate_trace_method (AllTraceRhoMethod, optional) –
The method to calculate the trace for searching esitmator. - “einsum_aij_bji_to_ab_numpy”:
Use np.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
- ”einsum_aij_bji_to_ab_jax”:
Use jnp.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
pbar (Optional[tqdm.tqdm], optional) – The progress bar. Defaults to None.
- Returns:
The expectation value of Rho and the purity calculated by classical shadow.
- Return type:
- qurry.process.classical_shadow.classical_shadow.esitimation_of_given_operators(shots: int, counts: list[dict[str, int]], random_unitary_um: dict[int, dict[int, Literal[0, 1, 2] | int]], selected_classical_registers: Iterable[int], given_operators: list[ndarray[tuple[int, int], dtype[complex128]]], accuracy_prob_comp_delta: float = 0.01, max_shadow_norm: float | None = None, rho_method: Literal['numpy', 'numpy_precomputed'] | str | Literal['numpy_flatten', 'jax_flatten'] = 'numpy_precomputed', estimate_trace_method: Literal['einsum_aij_bji_to_ab_numpy', 'einsum_aij_bji_to_ab_jax'] | str = 'einsum_aij_bji_to_ab_jax', pbar: tqdm | None = None) ClassicalShadowEstimation [source]¶
Calculate the expectation value of given operators.
- Reference:
Note
Predicting many properties of a quantum system from very few measurements -
Huang, Hsin-Yuan and Kueng, Richard and Preskill, John [doi:10.1038/s41567-020-0932-7](
The randomized measurement toolbox -
Elben, Andreas and Flammia, Steven T. and Huang, Hsin-Yuan and Kueng, Richard and Preskill, John and Vermersch, Benoît and Zoller, Peter [doi:10.1038/s42254-022-00535-2](
- Parameters:
shots (int) – The number of shots.
random_unitary_um (dict[int, dict[int, Union[Literal[0, 1, 2], int]]]) – The shadow direction of the unitary operators.
selected_classical_registers (Iterable[int]) – The list of the index of the selected_classical_registers.
given_operators (list[np.ndarray[tuple[int, int], np.dtype[np.complex128]]]) – The list of the operators to estimate.
accuracy_prob_comp_delta (float, optional) – The accuracy probability component delta. Defaults to 0.01.
max_shadow_norm (Optional[float], optional) – The maximum shadow norm. Defaults to None. If it is None, it will be calculated by the largest shadow norm upper bound. If it is not None, it must be a positive float number. It is \(|| O_i - \frac{\text{tr}(O_i)}{2^n} ||_{\text{shadow}}^2\) in equation.
rho_method (RhoMCoreMethod, optional) – The method to use for the calculation. Defaults to “numpy_precomputed”. It can be either “numpy”, “numpy_precomputed”, “jax_flatten”, or “numpy_flatten”. - “numpy”: Use Numpy to calculate the rho_m. - “numpy_precomputed”: Use Numpy to calculate the rho_m with precomputed values. - “numpy_flatten”: Use Numpy to calculate the rho_m with a flattening workflow. Currently, “numpy_precomputed” is the best option for performance.
estimate_trace_method (AllTraceRhoMethod, optional) –
The method to calculate the trace for searching esitmator. - “einsum_aij_bji_to_ab_numpy”:
Use np.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
- ”einsum_aij_bji_to_ab_jax”:
Use jnp.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
pbar (Optional[tqdm.tqdm], optional) – The progress bar. Defaults to None.
- Returns:
The estimation of the given operators.
- Return type:
- qurry.process.classical_shadow.classical_shadow.mean_of_rho(shots: int, counts: list[dict[str, int]], random_unitary_um: dict[int, dict[int, Literal[0, 1, 2] | int]], selected_classical_registers: Iterable[int], rho_method: Literal['numpy', 'numpy_precomputed'] | str | Literal['numpy_flatten', 'jax_flatten'] = 'numpy_precomputed', pbar: tqdm | None = None) ClassicalShadowMeanRho [source]¶
Calculate the mean of Rho.
- Reference:
Note
Predicting many properties of a quantum system from very few measurements -
Huang, Hsin-Yuan and Kueng, Richard and Preskill, John [doi:10.1038/s41567-020-0932-7](
The randomized measurement toolbox -
Elben, Andreas and Flammia, Steven T. and Huang, Hsin-Yuan and Kueng, Richard and Preskill, John and Vermersch, Benoît and Zoller, Peter [doi:10.1038/s42254-022-00535-2](
- Parameters:
shots (int) – The number of shots.
random_unitary_um (dict[int, dict[int, Union[Literal[0, 1, 2], int]]]) – The shadow direction of the unitary operators.
selected_classical_registers (list[int]) – The list of the index of the selected_classical_registers.
rho_method (RhoMCoreMethod, optional) – The method to use for the calculation. Defaults to “numpy_precomputed”. It can be either “numpy”, “numpy_precomputed”, “jax_flatten”, or “numpy_flatten”. - “numpy”: Use Numpy to calculate the rho_m. - “numpy_precomputed”: Use Numpy to calculate the rho_m with precomputed values. - “numpy_flatten”: Use Numpy to calculate the rho_m with a flattening workflow. Currently, “numpy_precomputed” is the best option for performance.
backend (PostProcessingBackendLabel, optional) – The backend for the postprocessing. Defaults to DEFAULT_PROCESS_BACKEND.
pbar (Optional[tqdm.tqdm], optional) – The progress bar. Defaults to None.
- Returns:
The expectation value of Rho.
- Return type:
- qurry.process.classical_shadow.classical_shadow.trace_rho_square(shots: int, counts: list[dict[str, int]], random_unitary_um: dict[int, dict[int, Literal[0, 1, 2] | int]], selected_classical_registers: Iterable[int], rho_method: Literal['numpy', 'numpy_precomputed'] | str | Literal['numpy_flatten', 'jax_flatten'] = 'numpy_precomputed', trace_method: Literal['trace_of_matmul', 'quick_trace_of_matmul', 'einsum_ij_ji'] | str | Literal['einsum_aij_bji_to_ab_numpy', 'einsum_aij_bji_to_ab_jax'] = 'einsum_aij_bji_to_ab_jax', pbar: tqdm | None = None) ClassicalShadowPurity [source]¶
Trace of Rho square.
- Parameters:
shots (int) – The number of shots.
random_unitary_um (dict[int, dict[int, Union[Literal[0, 1, 2], int]]]) – The shadow direction of the unitary operators.
selected_classical_registers (Iterable[int]) – The list of the index of the selected_classical_registers.
rho_method (RhoMCoreMethod, optional) – The method to use for the calculation. Defaults to “numpy_precomputed”. It can be either “numpy”, “numpy_precomputed”, “jax_flatten”, or “numpy_flatten”. - “numpy”: Use Numpy to calculate the rho_m. - “numpy_precomputed”: Use Numpy to calculate the rho_m with precomputed values. - “numpy_flatten”: Use Numpy to calculate the rho_m with a flattening workflow. Currently, “numpy_precomputed” is the best option for performance.
trace_method (TraceRhoMethod, optional) –
The method to calculate the trace of Rho square. - “trace_of_matmul”:
Use np.trace(np.matmul(rho_m1, rho_m2)) to calculate the each summation item in rho_m_list.
- ”quick_trace_of_matmul” or “einsum_ij_ji”:
Use np.einsum(“ij,ji”, rho_m1, rho_m2) to calculate the each summation item in rho_m_list.
- ”einsum_aij_bji_to_ab_numpy”:
Use np.einsum(“aij,bji->ab”, rho_m_list, rho_m_list) to calculate the trace.
pbar (Optional[tqdm.tqdm], optional) – The progress bar. Defaults to None.
- Returns:
The trace of Rho.
- Return type: