Wrapper on top of cirq.Simulator that allows to simulate calibration requests.
Inherits From: SimulatesSamples
, Sampler
, SimulatesIntermediateStateVector
, SimulatesAmplitudes
, SimulatesIntermediateState
, SimulatesFinalState
cirq.google.PhasedFSimEngineSimulator(
simulator: cirq.sim.Simulator
,
*,
drift_generator: cirq.google.calibration.engine_simulator.ParametersDriftGenerator
= try_convert_sqrt_iswap_to_fsim,
gates_translator: Callable[[Gate], Optional[PhaseCalibratedFSimGate]] = cirq.google.try_convert_sqrt_iswap_to_fsim
) -> None
Used in the notebooks
This simulator introduces get_calibrations which allows to simulate
cirq.google.run_characterizations requests. The returned calibration results represent the
internal state of a simulator. Circuits which are run on this simulator are modified to account
for the changes in the unitary parameters as described by the calibration results.
Args |
simulator
|
cirq.Simulator that all the simulation requests are delegated to.
|
drift_generator
|
Callable that generates the imperfect parameters for each pair of
qubits and the gate. They are later used for simulation.
|
gates_translator
|
Function that translates a gate to a supported FSimGate which will
undergo characterization.
|
Attributes |
gates_translator
|
Function that translates a gate to a supported FSimGate which will undergo
characterization.
|
Methods
compute_amplitudes
View source
compute_amplitudes(
program: "cirq.Circuit",
bitstrings: Sequence[int],
param_resolver: "study.ParamResolverOrSimilarType" = None,
qubit_order: cirq.ops.QubitOrderOrList
= cirq.ops.QubitOrder.DEFAULT
) -> Sequence[complex]
Computes the desired amplitudes.
The initial state is assumed to be the all zeros state.
Args |
program
|
The circuit to simulate.
|
bitstrings
|
The bitstrings whose amplitudes are desired, input
as an integer array where each integer is formed from measured
qubit values according to qubit_order from most to least
significant qubit, i.e. in big-endian ordering.
|
param_resolver
|
Parameters to run with the program.
|
qubit_order
|
Determines the canonical ordering of the qubits. This
is often used in specifying the initial state, i.e. the
ordering of the computational basis states.
|
Returns |
List of amplitudes.
|
compute_amplitudes_sweep
View source
compute_amplitudes_sweep(
program: "cirq.Circuit",
bitstrings: Sequence[int],
params: cirq.study.Sweepable
,
qubit_order: cirq.ops.QubitOrderOrList
= cirq.ops.QubitOrder.DEFAULT
) -> Sequence[Sequence[complex]]
Computes the desired amplitudes.
The initial state is assumed to be the all zeros state.
Args |
program
|
The circuit to simulate.
|
bitstrings
|
The bitstrings whose amplitudes are desired, input
as an integer array where each integer is formed from measured
qubit values according to qubit_order from most to least
significant qubit, i.e. in big-endian ordering.
|
params
|
Parameters to run with the program.
|
qubit_order
|
Determines the canonical ordering of the qubits. This
is often used in specifying the initial state, i.e. the
ordering of the computational basis states.
|
Returns |
List of lists of amplitudes. The outer dimension indexes the
circuit parameters and the inner dimension indexes the bitstrings.
|
create_from_characterizations_sqrt_iswap
View source
@classmethod
create_from_characterizations_sqrt_iswap(
characterizations: Iterable[cirq.google.PhasedFSimCalibrationResult
],
*,
simulator: Optional[cirq.sim.Simulator
] = None,
ideal_when_missing_gate: bool = False,
ideal_when_missing_parameter: bool = False
) -> "PhasedFSimEngineSimulator"
Creates PhasedFSimEngineSimulator with fixed drifts from the characterizations results.
Args |
characterizations
|
Characterization results which are source of the parameters for
each gate.
|
simulator
|
Simulator object to use. When None, a new instance of cirq.Simulator() will
be created.
|
ideal_when_missing_gate
|
When set and parameters for some gate for a given pair of
qubits are not specified in the parameters dictionary then the
FSimGate(theta=π/4, phi=0) gate parameters will be used. When not set and this
situation occurs, ValueError is thrown during simulation.
|
ideal_when_missing_parameter
|
When set and some parameter for some gate for a given pair
of qubits is specified then the matching parameter of FSimGate(theta=π/4, phi=0)
gate will be used. When not set and this situation occurs, ValueError is thrown
during simulation.
|
Returns |
New PhasedFSimEngineSimulator instance.
|
create_from_dictionary_sqrt_iswap
View source
@classmethod
create_from_dictionary_sqrt_iswap(
parameters: cirq.google.calibration.engine_simulator.PhasedFsimDictParameters
,
*,
simulator: Optional[cirq.sim.Simulator
] = None,
ideal_when_missing_gate: bool = False,
ideal_when_missing_parameter: bool = False
) -> "PhasedFSimEngineSimulator"
Creates PhasedFSimEngineSimulator with fixed drifts.
Args |
parameters
|
Parameters to use for each gate. All keys must be stored in canonical order,
when the first qubit is not greater than the second one.
|
simulator
|
Simulator object to use. When None, a new instance of cirq.Simulator() will
be created.
|
ideal_when_missing_gate
|
When set and parameters for some gate for a given pair of
qubits are not specified in the parameters dictionary then the
FSimGate(theta=π/4, phi=0) gate parameters will be used. When not set and this
situation occurs, ValueError is thrown during simulation.
|
ideal_when_missing_parameter
|
When set and some parameter for some gate for a given pair
of qubits is specified then the matching parameter of FSimGate(theta=π/4, phi=0)
gate will be used. When not set and this situation occurs, ValueError is thrown
during simulation.
|
Returns |
New PhasedFSimEngineSimulator instance.
|
create_gate_with_drift
View source
create_gate_with_drift(
a: cirq.ops.Qid
,
b: cirq.ops.Qid
,
gate_calibration: cirq.google.calibration.phased_fsim.PhaseCalibratedFSimGate
) -> cirq.ops.PhasedFSimGate
Generates a gate with drift for a given gate.
Args |
a
|
The first qubit.
|
b
|
The second qubit.
|
gate_calibration
|
Reference gate together with a phase information.
|
Returns |
A modified gate that includes the drifts induced by internal state of the simulator.
|
create_with_ideal_sqrt_iswap
View source
@classmethod
create_with_ideal_sqrt_iswap(
*,
simulator: Optional[cirq.sim.Simulator
] = None
) -> "PhasedFSimEngineSimulator"
Creates a PhasedFSimEngineSimulator that simulates ideal FSimGate(theta=π/4, phi=0).
Attributes |
simulator
|
Simulator object to use. When None, a new instance of cirq.Simulator() will
be created.
|
Returns |
New PhasedFSimEngineSimulator instance.
|
create_with_random_gaussian_sqrt_iswap
View source
@classmethod
create_with_random_gaussian_sqrt_iswap(
mean: cirq.google.PhasedFSimCharacterization
= cirq.google.SQRT_ISWAP_PARAMETERS,
*,
simulator: Optional[cirq.sim.Simulator
] = None,
sigma: cirq.google.PhasedFSimCharacterization
= PhasedFSimCharacterization(theta=0.02, zeta=0.05, chi=0.05, gamma=0.05, phi\n =0.02),
random_or_seed: RANDOM_STATE_OR_SEED_LIKE = None
) -> "PhasedFSimEngineSimulator"
Creates a PhasedFSimEngineSimulator that introduces a random deviation from the mean.
The random deviations are described by a Gaussian distribution of a given mean and sigma,
for each angle respectively.
Each gate for each pair of qubits retains the sampled values for the entire simulation, even
when used multiple times within a circuit.
Attributes |
mean
|
The mean value for each unitary angle. All parameters must be provided.
|
simulator
|
Simulator object to use. When None, a new instance of cirq.Simulator() will
be created.
|
sigma
|
The standard deviation for each unitary angle. For sigma parameters that are
None, the mean value will be used without any sampling.
|
Returns |
New PhasedFSimEngineSimulator instance.
|
final_state_vector
View source
final_state_vector(
program: cirq.circuits.Circuit
) -> np.array
get_calibrations
View source
get_calibrations(
requests: Sequence[cirq.google.PhasedFSimCalibrationRequest
]
) -> List[cirq.google.PhasedFSimCalibrationResult
]
Retrieves the calibration that matches the requests
Args |
requests
|
Calibration requests to obtain.
|
Returns |
Calibration results that reflect the internal state of simulator.
|
run
View source
run(
program: "cirq.Circuit",
param_resolver: "cirq.ParamResolverOrSimilarType" = None,
repetitions: int = 1
) -> "cirq.Result"
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
View source
run_async(
program, *, repetitions
)
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
run_batch(
programs: List['cirq.Circuit'],
params_list: Optional[List['cirq.Sweepable']] = None,
repetitions: Union[int, List[int]] = 1
) -> List[List['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.
|
run_sweep
View source
run_sweep(
program: "cirq.Circuit",
params: cirq.study.Sweepable
,
repetitions: int = 1
) -> List[cirq.study.Result
]
Runs the supplied Circuit, mimicking quantum hardware.
In contrast to run, this allows for sweeping over different parameter
values.
Args |
program
|
The circuit to simulate.
|
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
View source
run_sweep_async(
program, params, repetitions=1
)
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
View source
sample(
program: "cirq.Circuit",
*,
repetitions: int = 1,
params: "cirq.Sweepable" = None
) -> "pd.DataFrame"
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
simulate
View source
simulate(
program: "cirq.Circuit",
param_resolver: "study.ParamResolverOrSimilarType" = None,
qubit_order: cirq.ops.QubitOrderOrList
= cirq.ops.QubitOrder.DEFAULT,
initial_state: Any = None
) -> cirq.sim.simulator.TSimulationTrialResult
Simulates the supplied Circuit.
This method returns a result which allows access to the entire
simulator's final state.
Args |
program
|
The circuit to simulate.
|
param_resolver
|
Parameters to run with the program.
|
qubit_order
|
Determines the canonical ordering of the qubits. This
is often used in specifying the initial state, i.e. the
ordering of the computational basis states.
|
initial_state
|
The initial state for the simulation. The form of
this state depends on the simulation implementation. See
documentation of the implementing class for details.
|
Returns |
SimulationTrialResults for the simulation. Includes the final state.
|
simulate_moment_steps
View source
simulate_moment_steps(
circuit: cirq.circuits.Circuit
,
param_resolver: "study.ParamResolverOrSimilarType" = None,
qubit_order: cirq.ops.QubitOrderOrList
= cirq.ops.QubitOrder.DEFAULT,
initial_state: Any = None
) -> Iterator[cirq.sim.simulator.TStepResult
]
Returns an iterator of StepResults for each moment simulated.
If the circuit being simulated is empty, a single step result should
be returned with the state being set to the initial state.
Args |
circuit
|
The Circuit to simulate.
|
param_resolver
|
A ParamResolver for determining values of Symbols.
|
qubit_order
|
Determines the canonical ordering of the qubits. This
is often used in specifying the initial state, i.e. the
ordering of the computational basis states.
|
initial_state
|
The initial state for the simulation. The form of
this state depends on the simulation implementation. See
documentation of the implementing class for details.
|
Returns |
Iterator that steps through the simulation, simulating each
moment and returning a StepResult for each moment.
|
simulate_sweep
View source
simulate_sweep(
program: "cirq.Circuit",
params: cirq.study.Sweepable
,
qubit_order: cirq.ops.QubitOrderOrList
= cirq.ops.QubitOrder.DEFAULT,
initial_state: Any = None
) -> List[cirq.sim.simulator.TSimulationTrialResult
]
Simulates the supplied Circuit.
This method returns a result which allows access to the entire
state vector. In contrast to simulate, this allows for sweeping
over different parameter values.
Args |
program
|
The circuit to simulate.
|
params
|
Parameters to run with the program.
|
qubit_order
|
Determines the canonical ordering of the qubits. This
is often used in specifying the initial state, i.e. the
ordering of the computational basis states.
|
initial_state
|
The initial state for the simulation. The form of
this state depends on the simulation implementation. See
documentation of the implementing class for details.
|
Returns |
List of SimulationTrialResults for this run, one for each
possible parameter resolver.
|