tensorcircuit.shadows#

Classical shadows functions

tensorcircuit.shadows.entropy_shadow(snapshots: Any, pauli_strings: Optional[Any] = None, sub: Optional[Sequence[int]] = None, alpha: int = 2) Any[源代码]#

To calculate the Renyi entropy of a subsystem from shadow state or shadow snapshot states

参数
  • snapshots -- shape = (ns, repeat, nq, 2, 2) or (ns, repeat, nq)

  • pauli_strings -- shape = None or (ns, nq) or (ns, repeat, nq)

  • sub -- qubit indices of subsystem

  • alpha -- order of the Renyi entropy, alpha=1 corresponds to the von Neumann entropy

Type

Tensor

Type

Optional[Tensor]

Type

Optional[Sequence[int]]

Type

int

Return Renyi entropy

shape = ()

返回类型

Tensor

tensorcircuit.shadows.expectation_ps_shadow(snapshots: Any, pauli_strings: Optional[Any] = None, x: Optional[Sequence[int]] = None, y: Optional[Sequence[int]] = None, z: Optional[Sequence[int]] = None, ps: Optional[Sequence[int]] = None, k: int = 1) List[Any][源代码]#

To calculate the expectation value of an observable on shadow snapshot states

参数
  • snapshots -- shape = (ns, repeat, nq, 2, 2) or (ns, repeat, nq)

  • pauli_strings -- shape = None or (ns, nq) or (ns, repeat, nq)

  • x -- sites to apply X gate, defaults to None

  • y -- sites to apply Y gate, defaults to None

  • z -- sites to apply Z gate, defaults to None

  • ps -- or one can apply a ps structures instead of x, y, z, e.g. [1, 1, 0, 2, 3, 0] for X_0X_1Y_3Z_4 defaults to None, ps can overwrite x, y and z

  • k -- Number of equal parts to split the shadow snapshot states to compute the median of means. k=1 (default) corresponds to simply taking the mean over all shadow snapshot states.

Type

Tensor

Type

Optional[Tensor]

Type

Optional[Sequence[int]]

Type

Optional[Sequence[int]]

Type

Optional[Sequence[int]]

Type

Optional[Sequence[int]]

Type

int

Return expectation values

shape = (k,)

返回类型

List[Tensor]

tensorcircuit.shadows.global_shadow_state(snapshots: Any, pauli_strings: Optional[Any] = None, sub: Optional[Sequence[int]] = None) Any[源代码]#

To generate the global shadow state from local snapshot states or snapshots and pauli strings

参数
  • snapshots -- shape = (ns, repeat, nq, 2, 2) or (ns, repeat, nq)

  • pauli_strings -- shape = None or (ns, nq) or (ns, repeat, nq)

  • sub -- qubit indices of subsystem

Type

Tensor

Type

Optional[Tensor]

Type

Optional[Sequence[int]]

Return gsdw_state

shape = (2 ** nq, 2 ** nq)

返回类型

Tensor

tensorcircuit.shadows.global_shadow_state1(snapshots: Any, pauli_strings: Optional[Any] = None, sub: Optional[Sequence[int]] = None) Any[源代码]#

To generate the global snapshots states from local snapshot states or snapshots and pauli strings

参数
  • snapshots -- shape = (ns, repeat, nq, 2, 2) or (ns, repeat, nq)

  • pauli_strings -- shape = None or (ns, nq) or (ns, repeat, nq)

  • sub -- qubit indices of subsystem

Type

Tensor

Type

Optional[Tensor]

Type

Optional[Sequence[int]]

Return gsdw_state

shape = (2 ** nq, 2 ** nq)

返回类型

Tensor

tensorcircuit.shadows.global_shadow_state2(snapshots: Any, pauli_strings: Optional[Any] = None, sub: Optional[Sequence[int]] = None) Any[源代码]#

To generate the global snapshots states from local snapshot states or snapshots and pauli strings

参数
  • snapshots -- shape = (ns, repeat, nq, 2, 2) or (ns, repeat, nq)

  • pauli_strings -- shape = None or (ns, nq) or (ns, repeat, nq)

  • sub -- qubit indices of subsystem

Type

Tensor

Type

Optional[Tensor]

Type

Optional[Sequence[int]]

Return gsdw_state

shape = (2 ** nq, 2 ** nq)

返回类型

Tensor

tensorcircuit.shadows.local_snapshot_states(snapshots: Any, pauli_strings: Any, sub: Optional[Sequence[int]] = None) Any[源代码]#

To generate the local snapshots states from snapshots and pauli strings

参数
  • snapshots -- shape = (ns, repeat, nq)

  • pauli_strings -- shape = (ns, nq) or (ns, repeat, nq)

  • sub -- qubit indices of subsystem

Type

Tensor

Type

Tensor

Type

Optional[Sequence[int]]

Return lss_states

shape = (ns, repeat, nq, 2, 2)

返回类型

Tensor

tensorcircuit.shadows.renyi_entropy_2(snapshots: Any, sub: Optional[Sequence[int]] = None) Any[源代码]#

To calculate the second order Renyi entropy of a subsystem from snapshot, please refer to Brydges, T. et al. Science 364, 260–263 (2019). This function is not jitable.

参数
  • snapshots -- shape = (ns, repeat, nq)

  • sub -- qubit indices of subsystem

Type

Tensor

Type

Optional[Sequence[int]]

Return second order Renyi entropy

shape = ()

返回类型

Tensor

tensorcircuit.shadows.shadow_bound(observables: Union[Any, Sequence[int]], epsilon: float, delta: float = 0.01) Tuple[int, int][源代码]#

Calculate the shadow bound of the Pauli observables, please refer to the Theorem S1 and Lemma S3 in Huang, H.-Y., R. Kueng, and J. Preskill, 2020, Nat. Phys. 16, 1050.

参数
  • observables -- shape = (nq,) or (M, nq), where nq is the number of qubits, M is the number of observables

  • epsilon -- error on the estimator

  • delta -- rate of failure for the bound to hold

Type

Union[Tensor, Sequence[int]]

Type

float

Type

float

Return Nk

number of snapshots

返回类型

int

Return k

number of equal parts to split the shadow snapshot states to compute the median of means. k=1 (default) corresponds to simply taking the mean over all shadow snapshot states.

返回类型

int

tensorcircuit.shadows.shadow_snapshots(psi: Any, pauli_strings: Any, status: Optional[Any] = None, sub: Optional[Sequence[int]] = None, measurement_only: bool = False) Any[源代码]#

To generate the shadow snapshots from given pauli string observables on psi

参数
  • psi -- shape = (2 ** nq,), where nq is the number of qubits

  • pauli_strings -- shape = (ns, nq), where ns is the number of pauli strings

  • status -- shape = None or (ns, repeat), where repeat is the times to measure on one pauli string

  • sub -- qubit indices of subsystem

  • measurement_only -- return snapshots (True) or snapshot states (False), default=False

Type

Tensor

Type

Tensor

Type

Optional[Tensor]

Type

Optional[Sequence[int]]

Type

bool

Return snapshots

shape = (ns, repeat, nq) if measurement_only=True otherwise (ns, repeat, nq, 2, 2)

返回类型

Tensor

tensorcircuit.shadows.slice_sub(entirety: Any, sub: Sequence[int]) Any[源代码]#

To slice off the subsystem

参数
  • entirety -- shape = (ns, repeat, nq, 2, 2) or (ns, repeat, nq)

  • sub -- qubit indices of subsystem

Type

Tensor

Type

Sequence[int]

Return subsystem

shape = (ns, repeat, nq_sub, 2, 2)

返回类型

Tensor