We're celebrating World Quantum Day 2022! Join us

qsimcirq.QSimhSimulator

Simulator that computes final amplitudes of given bitstrings.

Used in the notebooks

Used in the tutorials

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.

qsim_options A map of circuit options for the simulator. These will be applied to all circuits run using this simulator. Accepted keys and their behavior are as follows:

- 'k': Comma-separated list of ints. Indices of "part 1" qubits.
- 'p': int (>= 0). Number of "prefix" gates.
- 'r': int (>= 0). Number of "root" gates.
- 't': int (> 0). Number of threads to run on. Default: 1.
- 'v': int (>= 0). Log verbosity. Default: 0.
- 'w': int (>= 0). Prefix value.

See qsim/docs/usage.md for more details on these options.

Methods

compute_amplitudes

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

Wraps computed amplitudes in a list.

Prefer overriding compute_amplitudes_sweep_iter.

compute_amplitudes_sweep_iter

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
An Iterator over lists of amplitudes. The outer dimension indexes the circuit parameters and the inner dimension indexes bitstrings.

sample_from_amplitudes

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.