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) Simulate a Quil program and return the wavefunction.
expectation(prep_prog, pauli_terms) Calculate the expectation value of Pauli operators given a state prepared by prep_program.
run_and_measure(quil_program[, qubits, trials]) 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 QVM Overview.

Initializes a wavefunction

Parameters:amplitude_vector – A numpy array of complex amplitudes

Attributes and Methods

probabilities() Returns an array of probabilities in lexicographical order
pretty_print([decimal_digits]) 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.
pretty_print_probabilities([decimal_digits]) Prints outcome probabilities, ignoring all outcomes with approximately zero probabilities (up to a certain number of decimal digits) and rounding the probabilities to decimal_digits.
sample_bitstrings(n_samples) Sample bitstrings from the distribution defined by the wavefunction.
zeros(qubit_num) Constructs the groundstate wavefunction for a given number of qubits.