View source on GitHub |
Simulator that computes final amplitudes of given bitstrings.
qsimcirq.QSimhSimulator(
qsimh_options: dict = {}
)
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.
Methods
compute_amplitudes
compute_amplitudes(
program: 'cirq.AbstractCircuit',
bitstrings: Sequence[int],
param_resolver: 'cirq.ParamResolverOrSimilarType' = None,
qubit_order: 'cirq.QubitOrderOrList' = 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. 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
compute_amplitudes_sweep(
program: cirq.Circuit,
bitstrings: Sequence[int],
params: cirq.Sweepable,
qubit_order: cirq.QubitOrderOrList = cirq.QubitOrder.DEFAULT
) -> Sequence[Sequence[complex]]
Wraps computed amplitudes in a list.
Prefer overriding compute_amplitudes_sweep_iter
.
compute_amplitudes_sweep_iter
compute_amplitudes_sweep_iter(
program: 'cirq.AbstractCircuit',
bitstrings: Sequence[int],
params: 'cirq.Sweepable',
qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT
) -> Iterator[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. 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
sample_from_amplitudes(
circuit: 'cirq.AbstractCircuit',
param_resolver: 'cirq.ParamResolver',
seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE',
repetitions: int = 1,
qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT
) -> Dict[int, int]
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. |