View source on GitHub |
Estimates the energy of a linear combination of Pauli observables.
Inherits From: Collector
cirq.PauliSumCollector(
circuit: 'cirq.AbstractCircuit',
observable: 'cirq.PauliSumLike',
*,
samples_per_term: int,
max_samples_per_job: int = 1000000
)
Used in the notebooks
Used in the tutorials |
---|
Methods
collect
collect(
sampler: 'cirq.Sampler',
*,
concurrency: int = 2,
max_total_samples: Optional[int] = None
) -> None
Collects needed samples from a sampler.
Examples | |
---|---|
|
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
collect_async(
sampler, *, concurrency=2, max_total_samples=None
)
Asynchronously collects needed samples from a sampler.
Examples | |
---|---|
|
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
estimated_energy() -> Union[float, complex]
Sums up the sampled expectations, weighted by their coefficients.
next_job
next_job() -> Optional['cirq.CircuitSampleJob']
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
on_job_result(
job: 'cirq.CircuitSampleJob', result: 'cirq.Result'
)
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.