pyquil.wavefunction module¶
Module containing the Wavefunction object and methods for working with wavefunctions.
- class pyquil.wavefunction.Wavefunction(amplitude_vector: ndarray)[source]¶
Bases:
object
Encapsulate a wavefunction representing a quantum state as returned by
WavefunctionSimulator
.Note
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 bitstring01
indicates that qubit 0 is in the state 1. See also the related documentation section in the WavefunctionSimulator Overview.Initialize a Wavefunction.
- Parameters:
amplitude_vector – A numpy array of complex amplitudes
- static from_bit_packed_string(coef_string: bytes) Wavefunction [source]¶
Unpack the bit string to get a Wavefunction.
- Parameters:
coef_string
- get_outcome_probs() dict[str, float] [source]¶
Parse a wavefunction (array of complex amplitudes) and return a dictionary of outcomes and associated probabilities.
- Returns:
A dict with outcomes as keys and probabilities as values.
- Return type:
dict
- plot(qubit_subset: Sequence[int] | None = None) None [source]¶
Plot a bar chart with bitstring on the x-axis and probability on the y-axis.
- Parameters:
qubit_subset – Optional parameter used for plotting a subset of the Hilbert space.
- pretty_print(decimal_digits: int = 2) str [source]¶
Return a human-friendly string representation of the wavefunction.
Ignores all outcomes with approximately zero amplitude (up to a certain number of decimal digits) and rounding the amplitudes to decimal_digits.
- Parameters:
decimal_digits (int) – The number of digits to truncate to.
- Returns:
A string representation of the wavefunction.
- pretty_print_probabilities(decimal_digits: int = 2) dict[str, float] [source]¶
TODO: This doesn’t seem like it is named correctly…
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.
- Parameters:
decimal_digits (int) – The number of digits to truncate to.
- Returns:
A dict with outcomes as keys and probabilities as values.
- sample_bitstrings(n_samples: int) ndarray [source]¶
Sample bitstrings from the distribution defined by the wavefunction.
- Parameters:
n_samples – The number of bitstrings to sample
- Returns:
An array of shape (n_samples, n_qubits)
- static zeros(qubit_num: int) Wavefunction [source]¶
Construct the groundstate wavefunction for a given number of qubits.
- Parameters:
qubit_num
- Returns:
A Wavefunction in the ground state