Quantum Computer

pyquil.get_qc(name, *, as_qvm=None, noisy=None, connection=None, compiler_timeout=10)[source]

Get a quantum computer.

A quantum computer is an object of type QuantumComputer and can be backed either by a QVM simulator (“Quantum/Quil Virtual Machine”) or a physical Rigetti QPU (“Quantum Processing Unit”) made of superconducting qubits.

You can choose the quantum computer to target through a combination of its name and optional flags. There are multiple ways to get the same quantum computer. The following are equivalent:

>>> qc = get_qc("Aspen-1-16Q-A-noisy-qvm")
>>> qc = get_qc("Aspen-1-16Q-A", as_qvm=True, noisy=True)

and will construct a simulator of an Aspen-1 lattice with a noise model based on device characteristics. We also provide a means for constructing generic quantum simulators that are not related to a given piece of Rigetti hardware:

>>> qc = get_qc("9q-square-qvm")
>>> qc = get_qc("9q-square", as_qvm=True)

Finally, you can get request a QVM with “no” topology of a given number of qubits (technically, it’s a fully connected graph among the given number of qubits) with:

>>> qc = get_qc("5q-qvm") # or "6q-qvm", or "34q-qvm", ...

These less-realistic, fully-connected QVMs will also be more lenient on what types of programs they will run. Specifically, you do not need to do any compilation. For the other, realistic QVMs you must use qc.compile() or qc.compiler.native_quil_to_executable() prior to qc.run().

The Rigetti QVM must be downloaded from https://www.rigetti.com/forest and run as a server alongside your python program. To use pyQuil’s built-in QVM, replace all "-qvm" suffixes with "-pyqvm":

>>> qc = get_qc("5q-pyqvm")

Redundant flags are acceptable, but conflicting flags will raise an exception:

>>> qc = get_qc("9q-square-qvm") # qc is fully specified by its name
>>> qc = get_qc("9q-square-qvm", as_qvm=True) # redundant, but ok
>>> qc = get_qc("9q-square-qvm", as_qvm=False) # Error!

Use list_quantum_computers() to retrieve a list of known qc names.

This method is provided as a convenience to quickly construct and use QVM’s and QPU’s. Power users may wish to have more control over the specification of a quantum computer (e.g. custom noise models, bespoke topologies, etc.). This is possible by constructing a QuantumComputer object by hand. Please refer to the documentation on QuantumComputer for more information.

  • name (str) – The name of the desired quantum computer. This should correspond to a name returned by list_quantum_computers(). Names ending in “-qvm” will return a QVM. Names ending in “-pyqvm” will return a PyQVM. Names ending in “-noisy-qvm” will return a QVM with a noise model. Otherwise, we will return a QPU with the given name.

  • as_qvm (Optional[bool]) – An optional flag to force construction of a QVM (instead of a QPU). If specified and set to True, a QVM-backed quantum computer will be returned regardless of the name’s suffix

  • noisy (Optional[bool]) – An optional flag to force inclusion of a noise model. If specified and set to True, a quantum computer with a noise model will be returned regardless of the name’s suffix. The noise model for QVMs based on a real QPU is an empirically parameterized model based on real device noise characteristics. The generic QVM noise model is simple T1 and T2 noise plus readout error. See decoherence_noise_with_asymmetric_ro().

  • connection (Optional[ForestConnection]) – An optional ForestConnection object. If not specified, the default values for URL endpoints will be used. If you deign to change any of these parameters, pass your own ForestConnection object.

  • compiler_timeout (float) – The number of seconds after which a compilation request will raise a TimeoutError.

Return type



A pre-configured QuantumComputer

pyquil.api.local_forest_runtime(*, host='', qvm_port=5000, quilc_port=5555, use_protoquil=False)[source]

A context manager for local QVM and QUIL compiler.

You must first have installed the qvm and quilc executables from the forest SDK. [https://www.rigetti.com/forest]

This context manager will ensure that the designated ports are not used, start up qvm and quilc proccesses if possible and terminate them when the context is exited. If one of the ports is in use, a RuntimeWarning will be issued and the qvm/quilc process won’t be started.


Only processes started by this context manager will be terminated on exit, no external process will be touched.

>>> from pyquil import get_qc, Program
>>> from pyquil.gates import CNOT, Z
>>> from pyquil.api import local_forest_runtime
>>> qvm = get_qc('9q-square-qvm')
>>> prog = Program(Z(0), CNOT(0, 1))
>>> with local_forest_runtime():
>>>     results = qvm.run_and_measure(prog, trials=10)
  • host (str) – Host on which qvm and quilc should listen on.

  • qvm_port (int) – Port which should be used by qvm.

  • quilc_port (int) – Port which should be used by quilc.

  • use_protoquil (bool) – Restrict input/output to protoquil.


If use_protoquil is set to True language features you need may be disabled. Please use it with caution.


FileNotFoundError: If either executable is not installed.

Return type

Iterator[Tuple[Optional[Popen], Optional[Popen]]]


The returned tuple contains two subprocess.Popen objects for the qvm and the quilc processes. If one of the designated ports is in use, the process won’t be started and the respective value in the tuple will be None.

pyquil.list_quantum_computers(connection=None, qpus=True, qvms=True)[source]

List the names of available quantum computers

  • connection (Optional[ForestConnection]) – An optional :py:class:ForestConnection` object. If not specified, the default values for URL endpoints will be used, and your API key will be read from ~/.pyquil_config. If you deign to change any of these parameters, pass your own ForestConnection object.

  • qpus (bool) – Whether to include QPU’s in the list.

  • qvms (bool) – Whether to include QVM’s in the list.

Return type


class pyquil.api.QuantumComputer(*, name, qam, device, compiler, symmetrize_readout=False)[source]

A quantum computer for running quantum programs.

A quantum computer has various characteristics like supported gates, qubits, qubit topologies, gate fidelities, and more. A quantum computer also has the ability to run quantum programs.

A quantum computer can be a real Rigetti QPU that uses superconducting transmon qubits to run quantum programs, or it can be an emulator like the Rigetti QVM with noise models and mimicked topologies.

  • name (str) – A string identifying this particular quantum computer.

  • qam (QAM) – A quantum abstract machine which handles executing quantum programs. This dispatches to a QVM or QPU.

  • device (AbstractDevice) – A collection of connected qubits and associated specs and topology.

  • symmetrize_readout (bool) – Whether to apply readout error symmetrization. See run_symmetrized_readout() for a complete description.


run(executable[, memory_map])

Run a quil executable.


Perform readout calibration on the various multi-qubit observables involved in the provided Experiment.

experiment(experiment[, memory_map])

Run an Experiment on a QVM or QPU backend.

run_and_measure(program, trials)

Run the provided state preparation program and measure all qubits.

run_symmetrized_readout(program, trials[, …])

Run a quil program in such a way that the readout error is made symmetric.


Return a sorted list of this QuantumComputer’s device’s qubits


Return a NetworkX graph representation of this QuantumComputer’s device’s qubit connectivity.

get_isa([oneq_type, twoq_type])

Return a target ISA for this QuantumComputer’s device.

compile(program[, to_native_gates, …])

A high-level interface to program compilation.