A wrapper around AbstractProcessor to implement the cirq.Sampler interface.
cirq_google.engine.ProcessorSampler(
*,
processor: 'cg.engine.AbstractProcessor',
run_name: str = '',
device_config_name: str = ''
)
Args |
processor
|
AbstractProcessor instance to use.
|
run_name
|
A unique identifier representing an automation run for the
specified processor. An Automation Run contains a collection of
device configurations for a processor.
|
device_config_name
|
An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
|
Raises |
ValueError
|
If only one of run_name and device_config_name are specified.
|
Attributes |
device_config_name
|
|
processor
|
|
run_name
|
|
Methods
run
run(
program: 'cirq.AbstractCircuit',
param_resolver: 'cirq.ParamResolverOrSimilarType' = None,
repetitions: int = 1
) -> 'cirq.Result'
Samples from the given Circuit
.
This mode of operation for a sampler will provide results
in the form of measurement outcomes. It will not provide
access to state vectors (even if the underlying
sampling mechanism is a simulator). This method will substitute
parameters in the param_resolver
attributes for sympy.Symbols
used within the Circuit. This circuit will be executed a number
of times specified in the repetitions
attribute, though some
simulated implementations may instead sample from the final
distribution rather than execute the circuit each time.
Args |
program
|
The circuit to sample from.
|
param_resolver
|
Parameters to run with the program.
|
repetitions
|
The number of times to sample.
|
Returns |
cirq.Result that contains all the measurements for a run.
|
run_async
run_async(
program, param_resolver=None, repetitions=1
)
Asynchronously samples from the given Circuit.
Provides measurement outcomes as a cirq.Result
object. This
interface will operate in a similar way to the run
method
except for executing asynchronously.
Args |
program
|
The circuit to sample from.
|
param_resolver
|
Parameters to run with the program.
|
repetitions
|
The number of times to sample.
|
Returns |
Result for a run.
|
run_batch
View source
run_batch(
programs, params_list=None, repetitions=1
)
run_batch_async
View source
run_batch_async(
programs, params_list=None, repetitions=1
)
Runs the supplied circuits asynchronously.
See docs for cirq.Sampler.run_batch
.
run_sweep
View source
run_sweep(
program, params, repetitions=1
)
run_sweep_async
View source
run_sweep_async(
program, params, repetitions=1
)
Asynchronously samples from the given Circuit.
By default, this method invokes run_sweep
synchronously and simply
exposes its result is an awaitable. Child classes that are capable of
true asynchronous sampling should override it to use other strategies.
Args |
program
|
The circuit to sample from.
|
params
|
Parameters to run with the program.
|
repetitions
|
The number of times to sample.
|
Returns |
Result list for this run; one for each possible parameter resolver.
|
sample
sample(
program: 'cirq.AbstractCircuit',
*,
repetitions: int = 1,
params: 'cirq.Sweepable' = None
) -> 'pd.DataFrame'
Samples the given Circuit, producing a pandas data frame.
This interface will operate in a similar way to the run
method
except that it returns a pandas data frame rather than a cirq.Result
object.
Args |
program
|
The circuit to sample from.
|
repetitions
|
The number of times to sample the program, for each
parameter mapping.
|
params
|
Maps symbols to one or more values. This argument can be
a dictionary, a list of dictionaries, a cirq.Sweep , a list of
cirq.Sweep , etc. The program will be sampled repetition
times for each mapping. Defaults to a single empty mapping.
|
Returns |
A pandas.DataFrame with a row for each sample, and a column for
each measurement key as well as a column for each symbolic
parameter. Measurement results are stored as a big endian integer
representation with one bit for each measured qubit in the key.
See cirq.big_endian_int_to_bits and similar functions for how
to convert this integer into bits.
There is an also index column containing the repetition number,
for each parameter assignment.
|
Raises |
ValueError
|
If a supplied sweep is invalid.
|
Examples |
>>> a, b, c = cirq.LineQubit.range(3)
>>> sampler = cirq.Simulator()
>>> circuit = cirq.Circuit(cirq.X(a),
... cirq.measure(a, key='out'))
>>> print(sampler.sample(circuit, repetitions=4))
out
0 1
1 1
2 1
3 1
circuit = cirq.Circuit(cirq.X(a),
cirq.CNOT(a, b),
cirq.measure(a, b, c, key='out'))
print(sampler.sample(circuit, repetitions=4))
out
0 6
1 6
2 6
3 6
circuit = cirq.Circuit(cirq.X(a)**sympy.Symbol('t'),
cirq.measure(a, key='out'))
print(sampler.sample(
circuit,
repetitions=3,
params=[{'t': 0}, {'t': 1}]))
t out
0 0 0
1 0 0
2 0 0
0 1 1
1 1 1
2 1 1
|
sample_expectation_values
sample_expectation_values(
program: 'cirq.AbstractCircuit',
observables: Union['cirq.PauliSumLike', List['cirq.PauliSumLike']],
*,
num_samples: int,
params: 'cirq.Sweepable' = None,
permit_terminal_measurements: bool = False
) -> Sequence[Sequence[float]]
Calculates estimated expectation values from samples of a circuit.
Please see also cirq.work.observable_measurement.measure_observables
for more control over how to measure a suite of observables.
This method can be run on any device or simulator that supports circuit sampling. Compare
with simulate_expectation_values
in simulator.py, which is limited to simulators
but provides exact results.
Args |
program
|
The circuit which prepares a state from which we sample expectation values.
|
observables
|
A list of observables for which to calculate expectation values.
|
num_samples
|
The number of samples to take. Increasing this value increases the
statistical accuracy of the estimate.
|
params
|
Parameters to run with the program.
|
permit_terminal_measurements
|
If the provided circuit ends in a measurement, this
method will generate an error unless this is set to True. This is meant to
prevent measurements from ruining expectation value calculations.
|
Returns |
A list of expectation-value lists. The outer index determines the sweep, and the inner
index determines the observable. For instance, results[1][3] would select the fourth
observable measured in the second sweep.
|
Raises |
ValueError
|
If the number of samples was not positive, if empty observables were
supplied, or if the provided circuit has terminal measurements and
permit_terminal_measurements is true.
|