Computing the quantum error bars (tomographer.querrorbars)

Utilities for fitting the histogram data and computing the quantum error bars.

class tomographer.querrorbars.HistogramAnalysis(final_histogram, ftox=(0, 1), fit_fn=None, **kwopts)

Bases: object

Take care of analyzing histogram data obtained from performing a random walk over state space according to the distribution \(\mu_{B^n}(\cdot)\) defined by the tomography data, while collecting a histogram of a figure of merit.

Arguments to the constructor:
  • final_histogram: the final histogram returned by the random walks procedure. It is expected to be a tomographer.UniformBinsHistogramWithErrorBars.
  • ftox: Specify how to transform the figure of merit value f into the x coordinate for fit. Specify the transformation as a pair of values (h, s) in the relation x = s*(f-h) or f=s*x+h, where h can be any constant, and where s must be plus or minus one. By default there is no transformation (x=f, corresponding to ftox=(0,1). For the fidelity, you should use x = 1-f (ftox=(1,-1)). For an entanglement witness, you might use x = 2-f (ftox=(2,-1)) for example.
  • fit_fn: a function which serves as fit model (for the log of the data)
  • additional named arguments in kwopts are passed on to fit_histogram().
fitParameters()

Return the parameters of the fit. The return value type is a named tuple whose fields are the argument names of the fit model fit_fn specified to the constructor. For example, for the default fit model fit_fn_default(), the fields are (a2, a1, m, c).

ftox(f)

Convert an f-value (value of the figure of merit) to an x-value (natural variable of the fit model).

plot(log_scale=False, xlabel='Distribution of values', plot_deskewed_gaussian=True, **kwopts)

Plot the histogram data using matplotlib.

Parameters:
  • log_scale – if True, then use a logarithmic scale for the y-axis.
  • xlabel – the label for the x axis (i.e., the figure of merit). Note this is the f-value, not the x-value.
  • show_plot – if True (the default), then the plot is displayed immediately. If False, then the returned object has an additional method show() which can be used to display the plot.

The return value is an object with the attributes fig (the matplotlib figure object) and ax (the matplotlib axes object) which you can use to set specific custom properties. If you specified show_plot=False, then you should call the show() method on the returned object in order to show the plots (which is simply an alias for matplotlib.pyplot.show().

printFitParameters(print_func=<built-in function print>)

Display the fit parameters.

By default the values are displayed using print(...). You may specify a custom print function if you want them displayed somewhere else.

The fit parameters are returned in the same format as fitParameters().

printQuantumErrorBars(print_func=<built-in function print>)

Calculates and displays the values of the quantum error bars.

The quantum error bars are returned, provided in the same format as quantumErrorBars().

quantumErrorBars()

Calculate the quantum error bars.

This function is only available if you use the default fit model (i.e., if you didn’t specify the fit_fn argument to the constructor).

Returns a QuantumErrorBars named tuple.

xtof(x)

Convert an x-value (natural variable of the fit model) to the value of the figure of merit (f).

class tomographer.querrorbars.QuantumErrorBars(f0, Delta, gamma)

Bases: tuple

Delta

Alias for field number 1

f0

Alias for field number 0

gamma

Alias for field number 2

tomographer.querrorbars.deskew_logmu_curve(a2, a1, m, c)

De-skew the fit model to obtain a second order approximation at the peak maximum (see details of how to calculate the quantum error bars in our paper).

Usage:

(a, x0, y0) = deskew_logmu_curve(a2, a1, m, c)
tomographer.querrorbars.fit_fn_default(x, a2, a1, m, c)

The default fit model for the logarithm of the histogram data. The x-values are not directly the figure of merit, but may be possibly transformed via a f-to-x transformation (see HistogramAnalysis).

Returns the value \(-a_2\,x^2 - a_1\,x + m\log(x) + c\), which is the default fit model. If a NumPy vector is specified as x, the function is evaluated for all the given values and the values are returned as a vector.

tomographer.querrorbars.fit_histogram(normalized_histogram, fit_fn, ftox, **kwopts)

Fit the histogram data to a model function.

Parameters:
  • normalized_histogram – the final histogram data, provided as a tomographer.UniformBinsHistogramWithErrorBars class (or a subclass thereof), and normalized to a proper probability density (see tomographer.UniformBinsHistogramWithErrorBars.normalized()).
  • ftox – a function which transforms the figure of merit values (f-values) into the natural parameter for the fit function (x-values). For example, for the fidelity, one should use \(x = 1 - f\).
  • threshold_fraction – a fraction (i.e. value between 0 and 1) of the maximum peak value over which the data points are kept; values below the threshold are ignored for the fit. (By default, threshold_fraction=0 and all points are considered; since the error bars are taken into account this should be fine in most cases.)
  • kwopts – additional keyword options are passed on to scipy.optimize.curve_fit(...).