pyquil.operator_estimation module¶
Tools for estimating the expectation value of operators on a quantum computer.
- pyquil.operator_estimation.group_experiments(experiments: Experiment, method: str = 'greedy') Experiment ¶
Group experiments that are diagonal in a shared tensor product basis (TPB) to minimize number of QPU runs.
Background
Given some PauliTerm operator, the ‘natural’ tensor product basis to diagonalize this term is the one which diagonalizes each Pauli operator in the product term-by-term.
For example, X(1) * Z(0) would be diagonal in the ‘natural’ tensor product basis
{(|0> +/- |1>)/Sqrt[2]} * {|0>, |1>}
, whereas Z(1) * X(0) would be diagonal in the ‘natural’ tpb{|0>, |1>} * {(|0> +/- |1>)/Sqrt[2]}
. The two operators commute but are not diagonal in each others ‘natural’ tpb (in fact, they are anti-diagonal in each others ‘natural’ tpb). This function tests whether two operators given as PauliTerms are both diagonal in each others ‘natural’ tpb.Note that for the given example of X(1) * Z(0) and Z(1) * X(0), we can construct the following basis which simultaneously diagonalizes both operators:
-- |0>' = |0> (|+>) + |1> (|->) -- |1>' = |0> (|+>) - |1> (|->) -- |2>' = |0> (|->) + |1> (|+>) -- |3>' = |0> (-|->) + |1> (|+>)
In this basis, X Z looks like diag(1, -1, 1, -1), and Z X looks like diag(1, 1, -1, -1). Notice however that this basis cannot be constructed with single-qubit operations, as each of the basis vectors are entangled states.
Methods
The “greedy” method will keep a running set of ‘buckets’ into which grouped ExperimentSettings will be placed. Each new ExperimentSetting considered is assigned to the first applicable bucket and a new bucket is created if there are no applicable buckets.
The “clique-removal” method maps the term grouping problem onto Max Clique graph problem. This method constructs a NetworkX graph where an edge exists between two settings that share an nTPB and then uses networkx’s algorithm for clique removal. This method can give you marginally better groupings in certain circumstances, but constructing the graph is pretty slow so “greedy” is the default.
- Parameters:
experiments – a tomography experiment
method – method used for grouping; the allowed methods are one of [‘greedy’, ‘clique-removal’]
- Returns:
a tomography experiment with all the same settings, just grouped according to shared TPBs.
- pyquil.operator_estimation.group_experiments_clique_removal(experiments: Experiment) Experiment ¶
Group experiments that are diagonal in a shared tensor product basis (TPB) to minimize number of QPU runs.
This function uses a graph clique removal algorithm.
- Parameters:
experiments – a tomography experiment
- Returns:
a tomography experiment with all the same settings, just grouped according to shared TPBs.
- pyquil.operator_estimation.group_experiments_greedy(tomo_expt: Experiment) Experiment ¶
Greedy method to group ExperimentSettings in a given Experiment.
- Parameters:
tomo_expt – Experiment to group ExperimentSettings within
- Returns:
Experiment, with grouped ExperimentSettings according to whether it consists of PauliTerms diagonal in the same tensor product basis
- pyquil.operator_estimation.measure_observables(qc: QuantumComputer, tomo_experiment: Experiment, progress_callback: Callable[[int, int], None] | None = None, calibrate_readout: str | None = 'plus-eig') Generator[ExperimentResult, None, None] [source]¶
Measure all the observables in a TomographyExperiment.
- Parameters:
qc – A QuantumComputer which can run quantum programs
tomo_experiment – A suite of tomographic observables to measure
progress_callback – If not None, this function is called each time a group of settings is run with arguments
f(i, len(tomo_experiment)
such that the progress isi / len(tomo_experiment)
.calibrate_readout – Method used to calibrate the readout results. Currently, the only method supported is normalizing against the operator’s expectation value in its +1 eigenstate, which can be specified by setting this variable to ‘plus-eig’ (default value). The preceding symmetrization and this step together yield a more accurate estimation of the observable. Set to None if no calibration is desired.