cirq_google.engine.QuantumEngineSampler

A sampler that samples from processors managed by the Quantum Engine.

Exposes a cirq_google.Engine instance as a cirq.Sampler.

engine

Methods

run

Samples from the given Circuit.

By default, the run_async method invokes this method on another thread. So this method is supposed to be thread safe.

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_async

Asynchronously samples from the given Circuit.

By default, this method invokes run 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.
repetitions The number of times to sample.

Returns
An awaitable Result.

run_batch

View source

Runs the supplied circuits.

In order to gain a speedup from using this method instead of other run methods, the following conditions must be satisfied:

1. All circuits must measure the same set of qubits.
2. The number of circuit repetitions must be the same for all
   circuits. That is, the `repetitions` argument must be an integer,
   or else a list with identical values.

run_sweep

View source

Samples from the given Circuit.

In contrast to run, this allows for sweeping over different parameter values.

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.

run_sweep_async

Asynchronously sweeps and 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 One or more mappings from parameter keys to parameter values to use. For each parameter assignment, repetitions samples will be taken.
repetitions The number of times to sample.

Returns
An awaitable Result.

sample

Samples the given Circuit, producing a pandas data frame.

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.

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