Wavefunction Methods

class pyquil.api.WavefunctionSimulator(connection=None, random_seed=None)[source]

A simulator that propagates a wavefunction representation of a quantum state.

  • connection (Optional[ForestConnection]) – A connection to the Forest web API.

  • random_seed (Optional[int]) – A seed for the simulator’s random number generators. Either None (for an automatically generated seed) or a non-negative integer.


wavefunction(quil_program[, memory_map])

Simulate a Quil program and return the wavefunction.

expectation(prep_prog, pauli_terms[, memory_map])

Calculate the expectation value of Pauli operators given a state prepared by prep_program.

run_and_measure(quil_program[, qubits, …])

Run a Quil program once to determine the final wavefunction, and measure multiple times.

class pyquil.wavefunction.Wavefunction(amplitude_vector)[source]

Encapsulate a wavefunction representing a quantum state as returned by WavefunctionSimulator.


The elements of the wavefunction are ordered by bitstring. E.g., for two qubits the order is 00, 01, 10, 11, where the the bits are ordered in reverse by the qubit index, i.e., for qubits 0 and 1 the bitstring 01 indicates that qubit 0 is in the state 1. See also the related documentation section in the WavefunctionSimulator Overview.

Initializes a wavefunction


amplitude_vector (ndarray) – A numpy array of complex amplitudes

Attributes and Methods


Returns an array of probabilities in lexicographical order


Returns a string repr of the wavefunction, ignoring all outcomes with approximately zero amplitude (up to a certain number of decimal digits) and rounding the amplitudes to decimal_digits.


TODO: This doesn’t seem like it is named correctly…


Sample bitstrings from the distribution defined by the wavefunction.


Constructs the groundstate wavefunction for a given number of qubits.