trace_expect_process¶

Post Processing - Classical Shadow - Trace-Expectation Process (qurry.process.classical_shadow.trace_expect_process)

This module is used to process the rho dictionary for classical shadow.

qurry.process.classical_shadow.trace_expect_process.TraceRhoMethod¶

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.

alias of 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’]

qurry.process.classical_shadow.trace_expect_process.mean_rho_core(rho_m_list: list[ndarray[tuple[int, int], dtype[complex128]]], selected_classical_registers_sorted: list[int]) ndarray[tuple[int, int], dtype[complex128]][source]¶

Calculate the expectation value of Rho.

Parameters:
  • rho_m_list (list[np.ndarray[tuple[int, int], np.dtype[np.complex128]]]) – The dictionary of Rho M. The dictionary of Rho M I.

  • selected_classical_registers_sorted (list[int]) – The list of the selected_classical_registers.

Returns:

The expectation value of Rho.

Return type:

np.ndarray[tuple[int, int], np.dtype[np.complex128]]

qurry.process.classical_shadow.trace_expect_process.trace_rho_square_core(rho_m_list: list[ndarray[tuple[int, int], dtype[complex128]]], 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') complex128[source]¶

Calculate the trace of Rho square.

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:
  • rho_m_list (list[np.ndarray[tuple[int, int], np.dtype[np.complex128]]]) – The dictionary of Rho M.

  • trace_method (TraceMethod , 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.

Returns:

The trace of Rho square.

Return type:

np.complex128