A list of pyQuil instructions that comprise a quantum program.
>>> from pyquil import Program >>> from pyquil.gates import * >>> p = Program() >>> p += H(0) >>> p += CNOT(0, 1)
Fill in any placeholders and return a list of quil AbstractInstructions.
A list of defined gates on the program.
Serializes the Quil program to a string suitable for submitting to the QVM or QPU.
Returns all of the qubit indices used in this program, including gate applications and allocated qubits.
Protoquil programs may only contain gates, Pragmas, and RESET.
Concatenate two programs together using +=, returning a new one.
Concatenate two programs together, returning a new one.
Mutates the Program object by appending new instructions.
gate(name, params, qubits)
Add a gate to the program.
defgate(name, matrix[, parameters])
Define a new static gate.
define_noisy_gate(name, qubit_indices, kraus_ops)
Overload a static ideal gate with a noisy one defined in terms of a Kraus map.
define_noisy_readout(qubit, p00, p11)
For this program define a classical bit flip readout error channel parametrized by
Prevent a noisy gate definition from being applied to the immediately following Gate instruction.
Measures a qubit at qubit_index and puts the result in classical_reg
Reset all qubits or just a specific qubit at qubit_index.
Measures many qubits into their specified classical bits, in the order they were entered.
Get a new qubit.
declare(name[, memory_type, memory_size, …])
DECLARE a quil variable
Wraps a Quil program in a loop that re-runs the same program many times.
While a classical register at index classical_reg is 1, loop q_program
if_then(classical_reg, if_program[, …])
If the classical register at index classical reg is 1, run if_program, else run else_program.
Perform a shallow copy of this program.
Pops off the last instruction.
Creates the conjugate transpose of the Quil program.
Allows indexing into the program to get an action.
Takes a program which contains qubit placeholders and provides a mapping to the integers 0 through N-1.
The output of this function is suitable for input to
Parameters: program – A program containing qubit placeholders Returns: A dictionary mapping qubit placeholder to an addressed qubit from 0 through N-1.
Takes a program which contains placeholders and assigns them all defined values.
Either all qubits must be defined or all undefined. If qubits are undefined, you may provide a qubit mapping to specify how placeholders get mapped to actual qubits. If a mapping is not provided, integers 0 through N are used.
This function will also instantiate any label placeholders.
- program – The program.
- qubit_mapping – A dictionary-like object that maps from
int(but not both).
A new Program with all qubit and label placeholders assigned to real qubits and labels.
Takes an iterable of instructions which may contain label placeholders and assigns them all defined values.
Returns: list of instructions with all label placeholders assigned to real labels.
Implicitly declare a register named
rofor backwards compatibility with Quil 1.
There used to be one un-named hunk of classical memory. Now there are variables with declarations. Instead of:
MEASURE 0 
You must now measure into a named register, idiomatically:
MEASURE 0 ro
MEASUREinstruction will emit this (with a deprecation warning) if you’re still using bare integers for classical addresses. However, you must also declare memory in the new scheme:
DECLARE ro BIT MEASURE 0 ro
This method will determine if you are in “backwards compatibility mode” and will declare a read-out
roregister for you. If you program contains any DECLARE commands or if it does not have any MEASURE x ro[x], this will not do anything.
This behavior is included for backwards compatibility and will be removed in future releases of PyQuil. Please DECLARE all memory including
merge_with_pauli_noise(prog_list, probabilities, qubits)¶
Insert pauli noise channels between each item in the list of programs. This noise channel is implemented as a single noisy identity gate acting on the provided qubits. This method does not rely on merge_programs and so avoids the inclusion of redundant Kraus Pragmas that would occur if merge_programs was called directly on programs with distinct noisy gate definitions.
- prog_list (
Iterable) – an iterable such as a program or a list of programs. If a program is provided, a single noise gate will be applied after each gate in the program. If a list of programs is provided, the noise gate will be applied after each program.
- probabilities (
List) – The 4^num_qubits list of probabilities specifying the desired pauli channel. There should be either 4 or 16 probabilities specified in the order I, X, Y, Z or II, IX, IY, IZ, XI, XX, XY, etc respectively.
- qubits (
List) – a list of the qubits that the noisy gate should act on.
A single program with noisy gates inserted between each element of the program list.
- prog_list (
Merges a list of pyQuil programs into a single one by appending them in sequence. If multiple programs in the list contain the same gate and/or noisy gate definition with identical name, this definition will only be applied once. If different definitions with the same name appear multiple times in the program list, each will be applied once in the order of last occurrence.
Parameters: prog_list (list) – A list of pyquil programs Returns: a single pyQuil program Return type: Program
Returns a sorted list of classical addresses found in the MEASURE instructions in the program.
Parameters: program (Program) – The program from which to get the classical addresses. Return type:
Returns: A mapping from memory region names to lists of offsets appearing in the program.
Move all the DECLARE statements to the top of the program. Return a fresh obejct.
Parameters: program (
Program) – Perhaps jumbled program.
Returns: Program with DECLAREs all at the top and otherwise the same sorted contents.
Ensure that a program is valid ProtoQuil, otherwise raise a ValueError. Protoquil is a subset of Quil which excludes control flow and classical instructions.
Parameters: program (
Program) – The Quil program to validate.
Parse a raw Quil program and return a corresponding list of PyQuil objects.
Parameters: quil (str) – a single or multiline Quil program Returns: list of instructions