{"id":24381,"library":"pyquil","title":"PyQuil","description":"PyQuil is a Python library for creating and running Quantum Instruction Language (Quil) programs on Rigetti quantum processors and simulators. The current version is 4.17.0, supporting Python 3.9-3.12. It sees regular releases alongside Rigetti's Forest SDK.","status":"active","version":"4.17.0","language":"python","source_language":"en","source_url":"https://github.com/rigetti/pyquil","tags":["quantum computing","quil","rigetti","quantum instruction language","simulator"],"install":[{"cmd":"pip install pyquil","lang":"bash","label":"Standard install"}],"dependencies":[],"imports":[{"note":"","wrong":"","symbol":"Program","correct":"from pyquil import Program"},{"note":"In v4.x, get_qc is a top-level import; the submodule path changed.","wrong":"from pyquil.api import get_qc","symbol":"get_qc","correct":"from pyquil import get_qc"},{"note":"Common mistake due to old docs; correct module is pyquil.api.","wrong":"from pyquil.compiler import AbstractCompiler","symbol":"AbstractCompiler","correct":"from pyquil.api import AbstractCompiler"}],"quickstart":{"code":"from pyquil import Program, get_qc\nfrom pyquil.gates import H, CNOT, MEASURE\n\n# Create a Bell state program\np = Program()\np += H(0)\np += CNOT(0, 1)\nro = p.declare('ro', 'BIT', 2)\np += MEASURE(0, ro[0])\np += MEASURE(1, ro[1])\n\n# Get a quantum computer (simulator)\nqc = get_qc('2q-qvm')\n\n# Run the program\nexecutable = qc.compile(p)\nresult = qc.run(executable)\nprint(result.readout.get('ro'))","lang":"python","description":"Minimal example creating a Bell state circuit and running on the QVM simulator."},"warnings":[{"fix":"Update import statements and use `qc.compile(program)` before running.","message":"PyQuil 4.x introduced breaking changes from 3.x: import paths changed (e.g., `from pyquil.api` instead of `from pyquil.quilbase`), and the `QuantumComputer.run()` now expects compiled executables, not programs.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Switch to the new import paths; see migration guide.","message":"The `from pyquil.quil` module and `from pyquil.parser` are deprecated in 4.x. Use `from pyquil import Program` and `from pyquil.gates` for gate definitions.","severity":"deprecated","affected_versions":">=4.0.0 <5.0.0"},{"fix":"Ensure the QVM server is running: `qvm -S` in a separate terminal, or use a remote QPU endpoint.","message":"When using `get_qc('2q-qvm')`, the QVM (quantum virtual machine) is a simulator that requires the QVM server to be running locally or via Forest SDK. Without it, calls to `run` will hang or fail with connection errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `from pyquil import get_qc` for the quantum computer object; API classes are under `pyquil.api` but may require separate import.","cause":"Incorrect import path: users try `from pyquil.api import ...` but the module is not installed or deprecated in older versions.","error":"ModuleNotFoundError: No module named 'pyquil.api'"},{"fix":"Replace `program.run(qc)` with `qc.compile(program)` then `qc.run(executable)`.","cause":"In PyQuil 4.x, programs are not directly runnable; they must be compiled first.","error":"AttributeError: 'Program' object has no attribute 'run'"},{"fix":"Set shots via `program.wrap_in_numshots_loop(N)` before compiling.","cause":"In PyQuil 4.x, the `run()` method no longer accepts `shots`; the number of shots is set in the program via `measurements` or in the `compile` step.","error":"TypeError: 'QuantumComputer.run()' got an unexpected keyword argument 'shots'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}