cirq.SimulatesAmplitudes

Simulator that computes final amplitudes of given bitstrings.

Given a circuit and a list of bitstrings, computes the amplitudes of the given bitstrings in the state obtained by applying the circuit to the all zeros state. Implementors of this interface should implement the compute_amplitudes_sweep_iter method.

Methods

compute_amplitudes

View source

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. If inputting a binary literal add the prefix 0b or 0B. For example: 0010 can be input as 0b0010, 0B0010, 2, 0x2, etc.
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

Wraps computed amplitudes in a list.

Prefer overriding compute_amplitudes_sweep_iter.

compute_amplitudes_sweep_iter

View source

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. If inputting a binary literal add the prefix 0b or 0B. For example: 0010 can be input as 0b0010, 0B0010, 2, 0x2, etc.
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
An Iterator over lists of amplitudes. The outer dimension indexes the circuit parameters and the inner dimension indexes bitstrings.

sample_from_amplitudes

View source

Uses amplitude simulation to sample from the given circuit.

This implements the algorithm outlined by Bravyi, Gosset, and Liu in https://arxiv.org/abs/2112.08499 to more efficiently calculate samples given an amplitude-based simulator.

Simulators which also implement SimulatesSamples or SimulatesFullState should prefer run() or simulate(), respectively, as this method only accelerates sampling for amplitude-based simulators.

Args
circuit The circuit to simulate.
param_resolver Parameters to run with the program.
seed Random state to use as a seed. This must be provided manually - if the simulator has its own seed, it will not be used unless it is passed as this argument.
repetitions The number of repetitions to simulate.
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
A dict of bitstrings sampled from the final state of circuit to the number of occurrences of that bitstring.

Raises
ValueError if 'circuit' has non-unitary elements, as differences in behavior between sampling steps break this algorithm.