executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
simulationChoose and operate PyQuil's in-process and service-backed simulators, inspect quantum states and observables, and diagnose ordering, noise, random-state, and scaling failures.
Independent GitHub snapshot · Automated classification · Original documentation governs
Use this route when the task is to simulate a small Quil Program, inspect a
wavefunction or density matrix, calculate Pauli expectations, sample outcomes,
construct simulation matrices, or decide whether a QVM service is required.
This route assumes a usable PyQuil installation and a concrete qubit count.
For general program construction, use program-authoring.
For compilation, QuantumComputer, QVM/QPU jobs, or QCS orchestration, use
compile-execute. For complete channel,
readout, and Experiment workflows, use noise-experiments.
PyQVM for a QAM-shaped execution
path, or use ReferenceWavefunctionSimulator/NumpyWavefunctionSimulator
directly for a gate-only numerical path. PyQVM(n_qubits=..., seed=...)
supplies a shared random state and is the safest default when measurement,
sampling, control flow, or repeatable noise is involved.pyquil.api.WavefunctionSimulator is a
client for the QVM HTTP wavefunction/expectation/measurement endpoints. It
is not an in-process simulator. With no QVM service, its
.wavefunction(...) call attempts HTTP and raises api.QVMError (typically
beginning Could not communicate with QVM at ...). Do not use it to prove
service-free execution.PyQVM with post_gate_noise_probabilities selects
ReferenceDensitySimulator by default. This is an experimental post-gate
single-qubit Kraus path, not the full noise/Experiment API; route the latter
to noise-experiments.Read simulator-selection.md before choosing an engine, especially when a request mentions QVM, noise, state injection, or many qubits.
Program from program-authoring.
Count the qubits explicitly; PyQVM allocates the full Hilbert space.ReferenceWavefunctionSimulator(n_qubits) or
NumpyWavefunctionSimulator(n_qubits), then .do_program(program).PyQVM(n_qubits, seed=integer).execute(program).
Execution requires a Program, resets the simulator at each execute call,
and returns the stateful PyQVM; inspect qam.wf_simulator.2**n
amplitudes; the NumPy tensor has shape (2,) * n; a density matrix has
shape (2**n, 2**n), is Hermitian, and has trace one.Wavefunction helpers, expectations, density observables,
sampling, and matrix lifting.python scripts/bell_state_inprocess.py. Use
python scripts/bell_state_inprocess.py --help to inspect its interface;
it performs no network call or file write.ReferenceWavefunctionSimulator stores a flat canonical vector and favors
readable reference behavior. NumpyWavefunctionSimulator stores an
n-dimensional tensor and is the default PyQVM backend without noise.
Compare the NumPy tensor after reversing axes and flattening when comparing
it with the reference vector.rs. Instantiate them with a
numpy.random.RandomState, or prefer PyQVM(seed=...) so all stochastic
actions share one deterministic stream.ReferenceDensitySimulator stores a dense matrix and supports the
experimental post-gate noise names relaxation, dephasing,
depolarizing, phase_flip, bit_flip, and bitphase_flip. Its current
expectation method raises NotImplementedError; compute Tr(rho O) with
a lifted Pauli matrix for a local diagnostic, or route full observable and
Experiment work to noise-experiments.do_program is gate-only. PyQVM adds classical
memory/control-flow plumbing, measurement, and ordinary Program
execution, but still rejects several instructions and parameterized
DEFGATEs. Treat a failure as a backend capability issue, not automatically
as a malformed program. See api-reference.md
and troubleshooting.md.00, 01, 10, 11, ..., with qubit
0 as the least-significant/rightmost bit. Thus index 1 is bitstring 01
and means q0=1. Measurement arrays and user-selected qubit lists can use a
different column presentation; never infer labels from array positions alone.16 * 2**n bytes; a dense complex128 density
matrix needs 16 * 4**n bytes, before temporary lifted matrices. Estimate
memory before allocating and stop early for an exponential-size request.Before claiming a simulation result, record the engine and version, qubit
count, seed policy, whether noise was applied, state shape, basis convention,
and whether any service was contacted. Assert normalization and the expected
ordering for at least one basis state. For Bell-like checks, compare vector,
probabilities, XX/YY/ZZ expectations, and sampled bitstring columns across
reference and PyQVM paths rather than comparing only a pretty-printed string.