simulation
Choose and operate PyQuil's in-process and service-backed simulators, inspect quantum states and observables, and diagnose ordering, noise, random-state, and scaling failures.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- simulation
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Choose and operate PyQuil's in-process and service-backed simulators, inspect quantum states and observables, and diagnose ordering, noise, random-state, and scaling failures.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/api-reference.md6.3 KB
- 参考文档references/simulator-selection.md5.6 KB
- 参考文档references/state-and-observables.md5.8 KB
- 参考文档references/troubleshooting.md6.8 KB
- 脚本scripts/bell_state_inprocess.py2.3 KB
03 SKILL.md 正文
PyQuil simulation
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.
First decision: local or service-backed
- Service-free local simulation: choose
PyQVMfor a QAM-shaped execution path, or useReferenceWavefunctionSimulator/NumpyWavefunctionSimulatordirectly 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. - Service-backed wavefunction:
pyquil.api.WavefunctionSimulatoris 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 raisesapi.QVMError(typically beginningCould not communicate with QVM at ...). Do not use it to prove service-free execution. - Density/noise:
PyQVMwithpost_gate_noise_probabilitiesselectsReferenceDensitySimulatorby 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.
Minimal local workflow
- Build or receive a
Programfrom program-authoring. Count the qubits explicitly;PyQVMallocates the full Hilbert space. - For a gate-only state, use
ReferenceWavefunctionSimulator(n_qubits)orNumpyWavefunctionSimulator(n_qubits), then.do_program(program). - For Quil/QAM semantics, use
PyQVM(n_qubits, seed=integer).execute(program). Execution requires aProgram, resets the simulator at eachexecutecall, and returns the statefulPyQVM; inspectqam.wf_simulator. - Validate the state before interpreting it: a wavefunction has
2**namplitudes; the NumPy tensor has shape(2,) * n; a density matrix has shape(2**n, 2**n), is Hermitian, and has trace one. - Convert results into the requested representation. Read
state-and-observables.md for exact
bit ordering,
Wavefunctionhelpers, expectations, density observables, sampling, and matrix lifting. - Run the bundled deterministic Bell check
when a service-free smoke test is needed:
python scripts/bell_state_inprocess.py. Usepython scripts/bell_state_inprocess.py --helpto inspect its interface; it performs no network call or file write.
Engine-specific operating rules
ReferenceWavefunctionSimulatorstores a flat canonical vector and favors readable reference behavior.NumpyWavefunctionSimulatorstores an n-dimensional tensor and is the defaultPyQVMbackend without noise. Compare the NumPy tensor after reversing axes and flattening when comparing it with the reference vector.- Direct simulators can apply gates and compute expectations, but stochastic
measurement/sampling needs
rs. Instantiate them with anumpy.random.RandomState, or preferPyQVM(seed=...)so all stochastic actions share one deterministic stream. ReferenceDensitySimulatorstores a dense matrix and supports the experimental post-gate noise namesrelaxation,dephasing,depolarizing,phase_flip,bit_flip, andbitphase_flip. Its currentexpectationmethod raisesNotImplementedError; computeTr(rho O)with a lifted Pauli matrix for a local diagnostic, or route full observable and Experiment work to noise-experiments.- A direct simulator's
do_programis gate-only.PyQVMadds classical memory/control-flow plumbing, measurement, and ordinaryProgramexecution, but still rejects several instructions and parameterizedDEFGATEs. Treat a failure as a backend capability issue, not automatically as a malformed program. See api-reference.md and troubleshooting.md.
Numerical and resource guardrails
- PyQuil's canonical basis vector order is
00, 01, 10, 11, ..., with qubit0as the least-significant/rightmost bit. Thus index1is bitstring01and means q0=1. Measurement arrays and user-selected qubit lists can use a different column presentation; never infer labels from array positions alone. - A complex128 statevector needs
16 * 2**nbytes; a dense complex128 density matrix needs16 * 4**nbytes, before temporary lifted matrices. Estimate memory before allocating and stop early for an exponential-size request. - Use api-reference.md for verified signatures and state-and-observables.md for concrete shapes and matrix-ordering recipes. Use troubleshooting.md for recovery when a state is invalid, random state is absent, noise is incompatible, or a QVM boundary was mistaken for local execution.
Handoff checks
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.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).