View source on GitHub |
cirq.Sampler using the AQT simulator on the local machine.
Inherits From: AQTSampler
cirq_aqt.aqt_sampler.AQTSamplerLocalSimulator(
workspace: str = '',
resource: str = '',
access_token: str = '',
remote_host: str = '',
simulate_ideal: bool = False
)
Can be used as a replacement for the AQTSampler When the attribute simulate_ideal is set to True, an ideal circuit is sampled If not, the error model defined in aqt_simulator_test.py is used Example for running the ideal sampler:
sampler = AQTSamplerLocalSimulator() sampler.simulate_ideal=True
Methods
fetch_resources
@staticmethod
fetch_resources( access_token: str, remote_host: str = _DEFAULT_HOST ) -> list[Workspace]
Lists the workspaces and resources that are accessible with access_token.
Returns a list containing the workspaces and resources that the passed access_token gives access to. The workspace and resource IDs in this list can be used to submit jobs using the run and run_sweep methods.
The printed table contains four columns:
- WORKSPACE ID: the ID of the workspace. Use this value to submit circuits.
- RESOURCE NAME: the human-readable name of the resource.
- RESOURCE ID: the ID of the resource. Use this value to submit circuits.
- D/S: whether the resource is a (D)evice or (S)imulator.
Args | |
---|---|
access_token
|
Access token for the AQT API. |
remote_host
|
Address of the AQT API. Defaults to "https://arnica.aqt.eu/api/v1/". |
Raises | |
---|---|
RuntimeError
|
If there was an unexpected response from the server. |
print_resources
@staticmethod
print_resources( access_token: str, emit: Callable = print, remote_host: str = _DEFAULT_HOST ) -> None
Displays the workspaces and resources that are accessible with access_token.
Prints a table using the function passed as 'emit' containing the workspaces and resources that the passed access_token gives access to. The IDs in this table can be used to submit jobs using the run and run_sweep methods.
The printed table contains four columns:
- WORKSPACE ID: the ID of the workspace. Use this value to submit circuits.
- RESOURCE NAME: the human-readable name of the resource.
- RESOURCE ID: the ID of the resource. Use this value to submit circuits.
- D/S: whether the resource is a (D)evice or (S)imulator.
Args | |
---|---|
access_token
|
Access token for the AQT API. |
emit
|
optional
A Callable which will be called once with a single string argument, containing the table. Defaults to print from the standard library. |
remote_host
|
optional
Address of the AQT API. Defaults to "https://arnica.aqt.eu/api/v1/". |
Raises | |
---|---|
RuntimeError
|
If there was an unexpected response from the server. |
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
run_batch(
programs: Sequence['cirq.AbstractCircuit'],
params_list: Optional[Sequence['cirq.Sweepable']] = None,
repetitions: Union[int, Sequence[int]] = 1
) -> Sequence[Sequence['cirq.Result']]
Runs the supplied circuits.
Each circuit provided in programs
will pair with the optional
associated parameter sweep provided in the params_list
, and be run
with the associated repetitions provided in repetitions
(if
repetitions
is an integer, then all runs will have that number of
repetitions). If params_list
is specified, then the number of
circuits is required to match the number of sweeps. Similarly, when
repetitions
is a list, the number of circuits is required to match
the length of this list.
By default, this method simply invokes run_sweep
sequentially for
each (circuit, parameter sweep, repetitions) tuple. Child classes that
are capable of sampling batches more efficiently should override it to
use other strategies. Note that child classes may have certain
requirements that must be met in order for a speedup to be possible,
such as a constant number of repetitions being used for all circuits.
Refer to the documentation of the child class for any such requirements.
Args | |
---|---|
programs
|
The circuits to execute as a batch. |
params_list
|
Parameter sweeps to use with the circuits. The number of sweeps should match the number of circuits and will be paired in order with the circuits. |
repetitions
|
Number of circuit repetitions to run. Can be specified as a single value to use for all runs, or as a list of values, one for each circuit. |
Returns | |
---|---|
A list of lists of TrialResults. The outer list corresponds to the circuits, while each inner list contains the TrialResults for the corresponding circuit, in the order imposed by the associated parameter sweep. |
Raises | |
---|---|
ValueError
|
If length of programs is not equal to the length
of params_list or the length of repetitions .
|
run_batch_async
run_batch_async(
programs, params_list=None, repetitions=1
)
Runs the supplied circuits asynchronously.
See docs for cirq.Sampler.run_batch
.
run_sweep
run_sweep(
program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
) -> Sequence[cirq.Result]
Samples from the given Circuit.
In contrast to run, this allows for sweeping over different parameter values.
Args | |
---|---|
program
|
The circuit to simulate. Should be generated using AQTSampler.generate_circuit_from_list |
params
|
Parameters to run with the program. |
repetitions
|
The number of repetitions to simulate. |
Returns | |
---|---|
Result list for this run; one for each possible parameter resolver. |
run_sweep_async
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 | |
---|---|
|
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.
|