tangelo.toolboxes.post_processing package
Subpackages
Submodules
tangelo.toolboxes.post_processing.bootstrapping module
- tangelo.toolboxes.post_processing.bootstrapping.get_resampled_frequencies(freq_dict, ncount)
From a frequencies dictionary, makes a set of samples consistent with those frequencies and resample from that set to obtain a new frequencies dictionary consistent with ncount measurements.
- Parameters:
freq_dict (array) – dictionary of measurement/sample frequencies.
ncount (int) – number of shots/samples to generate resampled frequencies.
- Returns
dict: new frequencies dictionary with resampled distribution.
tangelo.toolboxes.post_processing.extrapolation module
- tangelo.toolboxes.post_processing.extrapolation.diis(coeffs, energies, stderr=None)
DIIS extrapolation, originally developed by Pulay in Chemical Physics Letters 73, 393-398 (1980)
- Parameters:
coeffs (array-like) – Noise rate amplification factors
energies (array-like) – Energy expectation values for amplified noise rates
stderr (array-like, optional) – Energy standard error estimates
- Returns:
float – Extrapolated energy
float – Error estimation for extrapolated energy
- tangelo.toolboxes.post_processing.extrapolation.extrapolation(coeffs, energies, stderr=None, taylor_order=None)
General, DIIS-like extrapolation procedure as found in Nature 567, 491-495 (2019) [arXiv:1805.04492]
- Parameters:
coeffs (array-like) – Noise rate amplification factors
energies (array-like) – Energy expectation values for amplified noise rates
stderr (array-like, optional) – Energy standard error estimates
taylor_order (int, optional) – Taylor expansion order; None for Richardson extrapolation (order determined from number of datapoints), 1 for DIIS extrapolation
- Returns:
float – Extrapolated energy
float – Error estimation for extrapolated energy
- tangelo.toolboxes.post_processing.extrapolation.richardson(coeffs, energies, stderr=None, estimate_exp=False)
General, DIIS-like extrapolation procedure as found in Nature 567, 491-495 (2019) [arXiv:1805.04492]
- Parameters:
coeffs (array-like) – Noise rate amplification factors
energies (array-like) – Energy expectation values for amplified noise rates
stderr (array-like, optional) – Energy standard error estimates
estimate_exp (bool, optional) – Choose to estimate exponent in the Richardson method. Default is False.
- Returns:
float – Extrapolated energy
float – Error estimation for extrapolated energy
- tangelo.toolboxes.post_processing.extrapolation.richardson_analytical(coeffs, energies, stderr=None)
Richardson extrapolation explicit result as found in Phys. Rev. Lett. 119, 180509 [arXiv:1612.02058] (up to sign difference)
- Parameters:
coeffs (array-like) – Noise rate amplification factors
energies (array-like) – Energy expectation values for amplified noise rates
stderr (array-like, optional) – Energy standard error estimates
- Returns:
float – Extrapolated energy
float – Error estimation for extrapolated energy
- tangelo.toolboxes.post_processing.extrapolation.richardson_with_exp_estimation(coeffs, energies, stderr=None)
Richardson extrapolation by recurrence, with exponent estimation
- Parameters:
energies (array-like) – Energy expectation values for amplified noise rates
coeffs (array-like) – Noise rate amplification factors
stderr (array-like, optional) – Energy standard error estimates
- Returns:
float – Extrapolated energy
float – Error estimation for extrapolated energy
tangelo.toolboxes.post_processing.histogram module
This module provides a Histogram class and functions to manipulate them, in order to facilitate post-processing of quantum experiments.
- class tangelo.toolboxes.post_processing.histogram.Histogram(outcomes, n_shots=0, msq_first=False, epsilon=0.01)
Bases:
object
Class to provide useful tools helping redundant tasks when analyzing data from an experiment. The expected data input is an histogram of bitstrings (“010…”), where 0 (resp. 1) correspond to the |0> (resp. |1>) measured state in the computational basis. The outcomes can refer to either the shot counts for each computational basis, or the corresponding probability.
The internal representation is kept as an histogram of shots. Normalized quantities are accessible via the Histogram “frequencies” properties. Bitstrings are stored with the lowest-significant qubit first (lsq_first) ordering.
- Parameters:
string (outcomes (dict of) – int or float): Results in the format of bitstring:
outcome
probability. (where outcome can be a number of shots a)
n_shots (int) – Self-explanatory. If it is equal 0, the class considers that probabilities are provided.
msq_first (bool) – Bit ordering. For example, 011 (msq_first) = 110 (lsq_first). This depends on the hardware provider convention.
epsilon (float) – When probabilities are provided, this parameter is used to check if the sum is within [1-epsilon, 1+epsilon]. Default is 1e-2.
- property frequencies
The frequencies are normalized counts vs the number of shots.
- Returns:
dict – Frequencies in a {bitstring: probability, …} format.
- get_expectation_value(term, coeff=1.0)
Output the expectation value for qubit operator term. The histogram data is expected to have been acquired in a compatible measurement basis.
- Parameters:
term (openfermion-style QubitOperator object) – a qubit operator, with only a single term.
coeff (imaginary) – Coefficient to multiply the eigenvalue by.
- Returns:
imaginary – Expectation value for this operator.
- property n_qubits
The length of the bitstrings represents the number of qubits.”
- Returns:
int – Self-explanatory.
- property n_shots
Return the number of shots encoded in the Histogram.
- Returns:
int – Self-explanatory.
- post_select(expected_outcomes)
Method to apply post selection on Histogram data, based on a post selection function in this module. This method changes the Histogram object inplace. This is explicitly done on desired outcomes for specific qubit indices.
- remove_qubit_indices(*indices)
Method to remove qubit indices in the result. The remaining bitstrings (of new length = length - N_indices) are summed up together.
- Parameters:
indices (variable number of int) – Qubit indices to remove.
- resample(n_shots)
Generating new Histogram with n_shots, done with the get_resampled_frequencies function (see the relevant documentation for more details).
- Parameters:
n_shots (int) – Self-explanatory.
- Returns:
Histogram – resampled data with n_shots from the distribution.
- tangelo.toolboxes.post_processing.histogram.aggregate_histograms(*hists)
Return a Histogram object formed from data aggregated from all input Histogram objects.
- Parameters:
hists (variable number of Histogram objects) – the input Histogram objects.
- Returns:
Histogram – The aggregated histogram.
- tangelo.toolboxes.post_processing.histogram.filter_hist(hist, function, *args, **kwargs)
Filter selection function to consider bitstrings in respect to a boolean predicate on a bitstring.
- Parameters:
hist (Histogram) – Self-explanatory.
function (function) – Given a bitstring and some arbitrary arguments, the predicate should return a boolean value.
- Returns:
Histogram – New Histogram with filtered outcomes based on the predicate provided.
tangelo.toolboxes.post_processing.mc_weeny_rdm_purification module
- tangelo.toolboxes.post_processing.mc_weeny_rdm_purification.mcweeny_purify_2rdm(rdm2_spin, conv=1e-07)
Perform 2-RDM purification based on McWeeny”s algorithm. The value selected for the convergence criteria should be consistent with the accuracy of the 2-RDM provided as input (in particular it should be correlated to the number of shots used to compute the RDM values, if a QPU or a shot-based quantum circuit simulator was used).
This algorithm only works on a RDM associated with a 2-electron system.
- Parameters:
rdm2_spin (numpy array) – The 2-RDM to be purified (in chemistry notation).
conv (float) – The convergence criteria for McWeeny”s purification.
- Returns:
numpy.array – One-particle RDM in spatial orbital basis.
numpy.array – Two-particle RDM in spatial orbital basis (in chemistry notation).
tangelo.toolboxes.post_processing.post_selection module
This module provides functions to create symmetry verification and post-selection circuits.
- tangelo.toolboxes.post_processing.post_selection.ancilla_symmetry_circuit(circuit, sym_op)
Append a symmetry operator circuit to an input circuit using an extra ancilla qubit, for the purpose of symmetry verification and post-selection. For more details see arXiv:1807.10050.
- Parameters:
circuit (Circuit) – A quantum circuit to be equipped with symmetry verification
sym_op (string) – The symmetry operator to be verified. Can be a Pauli string, OpenFermion style list or a QubitOperator
- Returns:
Circuit – The input circuit appended with the proper basis rotation and entanglement with an ancilla qubit, which is added as the last qubit. This appends an additional qubit to the circuit.
- tangelo.toolboxes.post_processing.post_selection.post_select(freqs, expected_outcomes)
Apply post selection to frequency data based on a dictionary of expected outcomes on ancilla qubits.
- Parameters:
- Returns:
dict – A dictionary of post-selected, renormalized frequencies and bitstrings with removed ancilla qubits
- tangelo.toolboxes.post_processing.post_selection.split_frequency_dict(frequencies, indices, desired_measurement=None)
Marginalize the frequencies dictionary over the indices. This splits the frequency dictionary into two frequency dictionaries and aggregates the corresponding frequencies. If desired_measurement is provided, the marginalized frequencies are post-selected for that outcome on the mid-circuit measurements.
- Parameters:
frequencies (dict) – The input frequency dictionary
indices (list) – The list of indices in the frequency dictionary to marginalize over
desired_measurement (str) – The bit string that is to be selected
- Returns:
dict – The marginal frequencies for provided indices
dict – The marginal frequencies for remaining indices
- tangelo.toolboxes.post_processing.post_selection.split_frequency_dict_for_last_n_digits(frequencies, n)
Marginalize the frequencies dictionary over the last_n_digits. This splits the frequency dictionary into two frequency dictionaries and aggregates the corresponding frequencies.
- Parameters:
frequencies (dict) – The input frequency dictionary
n (int) – The last n digits of the bitstring to store
- Returns:
dict – The marginal frequencies for remaining indices (different bitstring lengths in general)
dict – The frequencies for the last n bits
- tangelo.toolboxes.post_processing.post_selection.strip_post_selection(freqs, *qubits)
Convenience function to remove the symmetry ancilla qubit and aggregate data to recreate results without post-selection.
- Parameters:
freqs (dict) – A dictionary of {bitstring: frequency} as returned from a quantum device
qubits (variable number of int) – The ancilla qubit indices to be removed from the bitstrings
- Returns:
dict – A frequency dictionary with the qubits stripped and data aggregated