tangelo.toolboxes.measurements.classical_shadows package

Submodules

tangelo.toolboxes.measurements.classical_shadows.adaptive module

This file provides an API enabling the use of adaptive classical shadows. This algorithm is described in C. Hadfield, ArXiv:2105.12207 [Quant-Ph] (2021).

class tangelo.toolboxes.measurements.classical_shadows.adaptive.AdaptiveClassicalShadow(circuit=None, bitstrings=None, unitaries=None)

Bases: ClassicalShadow

Classical shadows using adaptive single Pauli measurements, as defined in C. Hadfield, ArXiv:2105.12207 [Quant-Ph] (2021).

build(n_shots, qu_op)

Adaptive classical shadow building method to define relevant unitaries depending on the qubit operator.

Parameters:
  • n_shots (int) – The number of desired measurements.

  • qu_op (QubitOperator) – The observable that one wishes to measure.

Returns:

list of str – The list of Pauli words that describes the measurement basis to use.

get_basis_circuits(only_unique=False)

Outputs a list of circuits corresponding to the adaptive single-Pauli unitaries.

Parameters:

only_unique (bool) – Consider only unique unitaries.

Returns:

list of Circuit or tuple – All basis circuits or a tuple of unique circuits, string representation and numbers of occurence.

get_term_observable(term, coeff=1.0)

Returns the estimated observable for a term and its coefficient.

Parameters:
  • term (tuple) – Openfermion style of a qubit operator term.

  • coeff (float) – Multiplication factor for the term.

Returns:

float – Observable estimated with the shadow.

tangelo.toolboxes.measurements.classical_shadows.classical_shadows module

This file provides an API enabling the use of classical shadows. The original idea is described in H.Y. Huang, R. Kueng, and J. Preskill, Nature Physics 16, 1050 (2020).

class tangelo.toolboxes.measurements.classical_shadows.classical_shadows.ClassicalShadow(circuit=None, bitstrings=None, unitaries=None)

Bases: ABC

Abstract class for the classical shadows implementation. Classical shadows is a mean to characterize a quantum state (within an error treshold) with the fewest measurement possible.

append(bitstring, unitary)

Append method to merge new snapshots to an existing shadow.

Parameters:
  • bistring (str or list of str) – Representation of outcomes.

  • unitary (str or list of str) – Relevant unitary for those outcomes.

abstract build()
abstract get_basis_circuits(only_unique=False)
get_observable(qubit_op, *args, **kwargs)

Getting an estimated observable value for a qubit operator from the classical shadow. This function loops through all terms and calls, for each of them, the get_term_observable method defined in the child class. Other arguments (args, kwargs) can be passed to the method.

Parameters:

qubit_op (QubitOperator) – Operator to estimate.

abstract get_term_observable()
property n_qubits

Returns the number of qubits the shadow represents.

simulate(backend, initial_statevector=None)

Simulate, using a predefined backend, a shadow from a circuit or a statevector.

Parameters:
  • backend (Backend) – Backend for the simulation of a shadow.

  • initial_statevector (list/array) – A valid statevector in the format supported by the target backend.

property size

Number of shots used to make the shadow.

property unique_unitaries

Returns the list of unique unitaries.

tangelo.toolboxes.measurements.classical_shadows.derandomized module

This file provides an API enabling the use of derandomized classical shadows. This algorithm is described in H.-Y. Huang, R. Kueng, and J. Preskill, ArXiv:2103.07510 [Quant-Ph] (2021).

class tangelo.toolboxes.measurements.classical_shadows.derandomized.DerandomizedClassicalShadow(circuit=None, bitstrings=None, unitaries=None)

Bases: ClassicalShadow

Classical shadows using derandomized single Pauli measurements, as defined in H.-Y. Huang, R. Kueng, and J. Preskill, ArXiv:2103.07510 [Quant-Ph] (2021).

build(n_shots, qu_op, eta=0.9)

Derandomized sampling of single Pauli words.

Parameters:
  • n_shots (int) – Total number of measurements.

  • qu_op (QubitOperator) – Relevant QubitOperator.

  • eta (float) – Empirical parameter for the cost function. Default is 0.9.

Returns:

list of str – Measurements generated for a derandomized procedure.

get_basis_circuits(only_unique=False)

Outputs a list of circuits corresponding to the chosen single-Pauli unitaries.

Parameters:

only_unique (bool) – Considering only unique unitaries.

Returns:

list of Circuit or tuple – All basis circuits or a tuple of unique circuits, string representation and numbers of occurence.

get_term_observable(term, coeff=1.0)

Returns the estimated observable for a term and its coefficient.

Parameters:
  • term (tuple) – Openfermion style of a qubit operator term.

  • coeff (float) – Multiplication factor for the term.

Returns:

float – Observable estimated with the shadow.

tangelo.toolboxes.measurements.classical_shadows.randomized module

This file provides an API enabling the use of randomized classical shadows. This algorithm is described in H.Y. Huang, R. Kueng, and J. Preskill, Nature Physics 16, 1050 (2020).

class tangelo.toolboxes.measurements.classical_shadows.randomized.RandomizedClassicalShadow(circuit=None, bitstrings=None, unitaries=None, shuffle=True)

Bases: ClassicalShadow

Classical shadows using randomized single Pauli measurements, as defined in H.Y. Huang, R. Kueng, and J. Preskill, Nature Physics 16, 1050 (2020). In short, the channel is inversed to geet the state with the formula hat{rho} = bigotimes_{j=1}^n left( 3U_j^{dagger} |b_j\rangle \langle b_j| U_j - mathbb{I} right)

build(n_shots)

Random sampling of single pauli words.

Parameters:

n_shots (int) – Total number of measurements.

Returns:

list of str – Measurements generated for a randomized procedure.

estimate_state(start=0, end=None, indices=None)

Returns the classical shadow average density matrix for a range of snapshots.

Parameters:
  • start (int) – Starting snapshot for the desired range.

  • end (int) – Ending snapshot for the desired range.

  • indices (list int) – Specific snapshot to pick. If this variable is set, start and end are ignored.

Returns:

array of complex – Estimation of the 2^n * 2^n state.

get_basis_circuits(only_unique=False)

Output a list of circuits corresponding to the random Pauli words unitaries.

Parameters:

only_unique (bool) – Considering only unique unitaries.

Returns:

list of Circuit or tuple – All basis circuits or a tuple of unique circuits, string representation and numbers of occurence.

get_term_observable(term, coeff=1.0, k=10)

Returns the estimated observable for a term and its coefficient.

Parameters:
  • term (tuple) – Openfermion style of a qubit operator term.

  • coeff (float) – Multiplication factor for the term.

  • k (int) – Grouping k observations for the means of median protocol.

Returns:

float – Observable estimated with the shadow.

Module contents