![]() |
Estimates the energy of a linear combination of Pauli observables.
Inherits From: Collector
cirq.PauliSumCollector(
circuit: 'cirq.Circuit',
observable: 'cirq.PauliSumLike',
*,
samples_per_term: int,
max_samples_per_job: int = 1000000
)
Args | |
---|---|
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
collect(
sampler: 'cirq.Sampler',
*,
concurrency: int = 2,
max_total_samples: Optional[int] = None
) -> None
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
collect_async(
sampler, *, concurrency=2, max_total_samples=None
)
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
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.