tangelo.toolboxes.measurements package

Subpackages

Submodules

tangelo.toolboxes.measurements.estimate_measurements module

This file provides functions allowing users to estimate the number of measurements that are needed to approximate the expectation values of some qubit operators up to a given accuracy.

The functions range from simple general heuristics to more complex approaches that may leverage our knowledge of the quantum state.

tangelo.toolboxes.measurements.estimate_measurements.get_measurement_estimate(qb_op, digits=3, method='uniform')

Given a qubit operator and a level of accuracy, computes the number of measurements required by each term of the qubit operator to reach the accuracy provided by the user when computing expectation values, returns it as a dictionary mapping measurement basis to number of measurements.

“uniform” method makes no assumption about the underlying probability distribution resulting from the quantum state preparation circuit. The rule of thumb is “Multiply number of samples by 100 for each digit of accuracy”.

Parameters:
  • qb_op – qubit operator.

  • digits (integer) – number of digits of accuracy desired on expectation value.

Returns:

dict – Dictionary mapping terms / measurement bases to their number of measurements.

tangelo.toolboxes.measurements.qubit_terms_grouping module

This file provides access to different approaches aiming at reducing the number of measurements required to compute the expectation value of a qubit (Pauli) operator. They attempt to identify the minimal amount of measurement bases / terms required to deduce the expectation values associated to the other terms present in the Pauli operator.

tangelo.toolboxes.measurements.qubit_terms_grouping.check_bases_commute_qwc(b1, b2)

Check whether two bases commute qubitwise.

Parameters:
  • b1 (tuple of (int, str)) – the first measurement basis

  • b2 (tuple of (int, str)) – the second measurement basis

Returns:

bool – whether or not the bases commute qubitwise

tangelo.toolboxes.measurements.qubit_terms_grouping.exp_value_from_measurement_bases(sub_ops, histograms)

Computes the expectation value of the sum of all suboperators corresponding to the different measurement bases in the input dictionary. This is how one would go about computing the expectation value of an operator while trying to send a limited amount of tasks to a quantum computer, thereby lowering the cost in terms of number of measurements needed.

Parameters:
  • sub_ops (dict) – Maps measurement bases to suboperators whose exp. value can be computed from it.

  • histograms (dict) – Maps measurement bases to histograms corresponding to that quantum circuit.

Returns:

float or complex – Expectation value of the sum of all suboperators.

tangelo.toolboxes.measurements.qubit_terms_grouping.group_qwc(qb_ham, seed=None, n_repeat=1)

Wrapper around Openfermion functionality that takes as input a QubitOperator and yields a collection of measurement bases defining a partition of groups of sub-operators with terms that are diagonal in the same tensor product basis. Each sub-operator can be measured using the same qubit post-rotations in expectation estimation. This uses the idea of qubitwise commutativity (qwc), and the minimum clique cover algorithm.

The resulting dictionary maps the measurement basis (key) to the list of qubit operators whose expectation value can be computed using the corresponding circuit. The size of this dictionary determines how many quantum circuits need to be executed in order to provide the expectation value of the input qubit operator.

The minimum clique cover algorithm can be initialized with a random seed and can be repeated several times with different seeds in order to return the run that produces the lowest number of groups.

Parameters:
  • qb_ham (QubitOperator) – the operator that will be split into sub-operators (tensor product basis sets).

  • seed (int) – default None. Random seed used to initialize the numpy.RandomState pseudo-RNG.

  • n_repeat (int) – Repeat with a different random seed, keep the outcome resulting in the lowest number of groups.

Returns:

dict – a dictionary where each key defines a tensor product basis, and each corresponding value is a QubitOperator with terms that are all diagonal in that basis.

tangelo.toolboxes.measurements.qubit_terms_grouping.map_measurements_qwc(qwc_group_map)

Somewhat reverses a grouping dictionary, linking all measurement bases to the list of group representatives that commute with them qubitwise. Useful to find all the bases whose shots can be used in order to form data for other bases during a hardware experiment.

Parameters:

qwc_group_map (dict) – maps a measurement basis to a qubit operator whose terms commute with said measurement basis qubit-wise.

Returns:

dict – maps each of the bases to all group representatives that commute with them qubitwise.

Module contents