cirq.PauliSumCollector

Estimates the energy of a linear combination of Pauli observables.

Inherits From: Collector

Used in the notebooks

Used in the tutorials

circuit Produces the state to be tested.
observable The pauli product observables to measure. Their sampled expectations will be scaled by their coefficients and their dictionary weights, and then added up to produce the final result.
samples_per_term The number of samples to collect for each PauliString term in order to estimate its expectation.
max_samples_per_job How many samples to request at a time.

Methods

collect

View source

Collects needed samples from a sampler.

Examples

collector = cirq.PauliStringCollector(...)
sampler.collect(collector, concurrency=3)
print(collector.estimated_energy())

Args
sampler The simulator or service to collect samples from.
concurrency Desired number of sampling jobs to have in flight at any given time.
max_total_samples Optional limit on the maximum number of samples to collect.

Returns
The collector's result after all desired samples have been collected.

collect_async

View source

Asynchronously collects needed samples from a sampler.

Examples

collector = cirq.PauliStringCollector(...)
await sampler.collect_async(collector, concurrency=3)
print(collector.estimated_energy())

Args
sampler The simulator or service to collect samples from.
concurrency Desired number of sampling jobs to have in flight at any given time.
max_total_samples Optional limit on the maximum number of samples to collect.

Returns
The collector's result after all desired samples have been collected.

estimated_energy

View source

Sums up the sampled expectations, weighted by their coefficients.

next_job

View source

Determines what to sample next.

This method is called by driving code when more samples can be requested.

Returns
A CircuitSampleJob describing the circuit to sample, how many samples to take, and a key value that can be used in the on_job_result method to recognize which job this is.

Can also return a nested iterable of such jobs.

Returning None, an empty list, or any other result which flattens into an empty list of work, indicates that the driving code should await more results (and pass them into on_job_results) before bothering to ask for more jobs again.

on_job_result

View source

Incorporates sampled results.

This method is called by driving code when sample results have become available.

The results should be incorporated into the collector's state.