get_qc(name, *, as_qvm=None, noisy=None, connection=None)¶
Get a quantum computer.
A quantum computer is an object of type
QuantumComputerand 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
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
>>> 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!
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
QuantumComputerobject by hand. Please refer to the documentation on
QuantumComputerfor 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 (
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 (
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
- connection (
ForestConnection]) – An optional
ForestConnectionobject. If not specified, the default values for URL endpoints will be used. If you deign to change any of these parameters, pass your own
A pre-configured QuantumComputer
- name (
local_forest_runtime(*, host='127.0.0.1', qvm_port=5000, quilc_port=5555, use_protoquil=False)¶
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
RuntimeWarningwill 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)
use_protoquilis set to
Truelanguage features you need may be disabled. Please use it with caution.
Raises: FileNotFoundError: If either executable is not installed. Return type:
Returns: The returned tuple contains two
subprocess.Popenobjects 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
list_quantum_computers(connection=None, qpus=True, qvms=True)¶
List the names of available quantum computers
- connection (
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
- qpus (
bool) – Whether to include QPU’s in the list.
- qvms (
bool) – Whether to include QVM’s in the list.
- connection (
QuantumComputer(*, name, qam, device, compiler, symmetrize_readout=False)¶
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 a quil executable.
Perform readout calibration on the various multi-qubit observables involved in the provided
Experimenton a QVM or QPU backend.
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.
Return a target ISA for this QuantumComputer’s device.
compile(program[, to_native_gates, …])
A high-level interface to program compilation.
- name (