pyquil.quilbase

Contains the core pyQuil objects that correspond to Quil instructions.

class pyquil.quilbase.AbstractInstruction

Bases: pyquil.quilbase.QuilAction

Abstract class for representing single instructionos.

out()
synthesize(resource_manager=None)
class pyquil.quilbase.Addr(value)

Bases: pyquil.quil_atom.QuilAtom

Representation of a classical bit address.

Parameters:value (int) – The classical address.
class pyquil.quilbase.BinaryClassicalInstruction(left, right)

Bases: pyquil.quilbase.AbstractInstruction

The abstract class for binary classical instructions.

out()
class pyquil.quilbase.ClassicalAnd(left, right)

Bases: pyquil.quilbase.BinaryClassicalInstruction

op = 'AND'
class pyquil.quilbase.ClassicalExchange(left, right)

Bases: pyquil.quilbase.BinaryClassicalInstruction

op = 'EXCHANGE'
class pyquil.quilbase.ClassicalFalse(target)

Bases: pyquil.quilbase.UnaryClassicalInstruction

op = 'FALSE'
class pyquil.quilbase.ClassicalMove(left, right)

Bases: pyquil.quilbase.BinaryClassicalInstruction

op = 'MOVE'
class pyquil.quilbase.ClassicalNot(target)

Bases: pyquil.quilbase.UnaryClassicalInstruction

op = 'NOT'
class pyquil.quilbase.ClassicalOr(left, right)

Bases: pyquil.quilbase.BinaryClassicalInstruction

op = 'OR'
class pyquil.quilbase.ClassicalTrue(target)

Bases: pyquil.quilbase.UnaryClassicalInstruction

op = 'TRUE'
class pyquil.quilbase.DefGate(name, matrix)

Bases: pyquil.quilbase.AbstractInstruction

A DEFGATE directive.

Parameters:
  • name (string) – The name of the newly defined gate.
  • matrix (array-like) – {list, nparray, np.matrix} The matrix defining this gate.
get_constructor()
Returns:A function that constructs this gate on variable qubit indices. E.g. mygate.get_constructor()(1) applies the gate to qubit 1.
num_args()
Returns:The number of qubit arguments the gate takes.
Return type:int
out()

Prints a readable Quil string representation of this gate.

Returns:String representation of a gate
Return type:string
class pyquil.quilbase.Gate(name, params, qubits)

Bases: pyquil.quilbase.Instr

This is the pyQuil object for a quantum gate instruction.

class pyquil.quilbase.Halt

Bases: pyquil.quilbase.SimpleInstruction

The HALT instruction.

op = 'HALT'
class pyquil.quilbase.If(condition)

Bases: pyquil.quilbase.QuilAction

Representation of an if construct. To use, initialize with an address to be branched on, and add instructions to self.Then and self.Else for the corresponding branches.

synthesize(resource_manager=None)
class pyquil.quilbase.Instr(op, params, args)

Bases: pyquil.quilbase.AbstractInstruction

Representation of an instruction represented by an operator, parameters, and arguments.

make_qubits_known(rm)

Make the qubits involved with this instruction known to a ResourceManager.

Parameters:rm (ResourceManager) – A ResourceManager object.
out()
qubits()

The qubits this instruction affects.

Returns:Set of qubit indexes.
Return type:set
synthesize(resource_manager=None)
class pyquil.quilbase.InstructionGroup(resource_manager=None)

Bases: pyquil.quilbase.QuilAction

Representation of a sequence of instructions that can be synthesized into a Quil program.

alloc()

Get a new qubit.

Returns:A qubit.
Return type:Qubit
extract_qubits()

Return all qubit addresses involved in the instruction group. :return: Set of qubits. :rtype: set

free(qubit)

Free a qubit.

Parameters:q (AbstractQubit) – An AbstractQubit instance.
inst(*instructions)

Mutates the Program object by appending new instructions.

Parameters:instructions – A list of Instruction objects, e.g. Gates
Returns:self
out()
pop()

Pops off the last instruction.

Returns:The (action, instruction) pair for the instruction that was popped.
Return type:tuple
synthesize(resource_manager=None)
class pyquil.quilbase.Jump(target)

Bases: pyquil.quilbase.AbstractInstruction

Representation of an unconditional jump instruction (JUMP).

out()
class pyquil.quilbase.JumpConditional(target, condition)

Bases: pyquil.quilbase.AbstractInstruction

Abstract representation of an conditional jump instruction.

out()
class pyquil.quilbase.JumpTarget(label)

Bases: pyquil.quilbase.AbstractInstruction

Representation of a target that can be jumped to.

out()
class pyquil.quilbase.JumpUnless(target, condition)

Bases: pyquil.quilbase.JumpConditional

The JUMP-UNLESS instruction.

op = 'JUMP-UNLESS'
class pyquil.quilbase.JumpWhen(target, condition)

Bases: pyquil.quilbase.JumpConditional

The JUMP-WHEN instruction.

op = 'JUMP-WHEN'
class pyquil.quilbase.Label(label_name)

Bases: pyquil.quil_atom.QuilAtom

Representation of a label.

Parameters:label_name (string) – The label name.
class pyquil.quilbase.Measurement(qubit, classical_reg=None)

Bases: pyquil.quilbase.Instr

This is the pyQuil object for a Quil measurement instruction.

class pyquil.quilbase.Nop

Bases: pyquil.quilbase.SimpleInstruction

The RESET instruction.

op = 'NOP'
class pyquil.quilbase.QuilAction

Bases: object

Representation of some executable code, i.e., something that can be synthesized into final Quil instructions.

synthesize(resource_manager=None)
class pyquil.quilbase.RawInstr(instr_str)

Bases: pyquil.quilbase.AbstractInstruction

A raw instruction represented as a string.

out()
class pyquil.quilbase.Reset

Bases: pyquil.quilbase.SimpleInstruction

The RESET instruction.

op = 'RESET'
class pyquil.quilbase.SimpleInstruction

Bases: pyquil.quilbase.AbstractInstruction

Abstract class for simple instructions with no arguments.

out()
class pyquil.quilbase.UnaryClassicalInstruction(target)

Bases: pyquil.quilbase.AbstractInstruction

The abstract class for unary classical instructions.

out()
class pyquil.quilbase.Wait

Bases: pyquil.quilbase.SimpleInstruction

The WAIT instruction.

op = 'WAIT'
class pyquil.quilbase.While(condition)

Bases: pyquil.quilbase.QuilAction

Representation of a while construct. To use, initialize with an address to branch on, and use self.Body.inst() to add instructions to the body of the loop.

synthesize(resource_manager=None)
pyquil.quilbase.action(type, obj)
pyquil.quilbase.action_install(obj)
pyquil.quilbase.format_matrix_element(element)

Formats a parameterized matrix element.

Parameters:element – {int, float, complex, str} The parameterized element to format.
pyquil.quilbase.format_parameter(element)

Formats a particular parameter.

Parameters:element – {int, float, long, complex, Slot} Formats a parameter for Quil output.
pyquil.quilbase.gen_label(prefix='L')

Generate a fresh label.

Parameters:prefix (string) – An optional prefix for the label name.
Returns:A new Label instance.
Return type:Label
pyquil.quilbase.issubinstance(x, cls)

Checks if class x is an instance or subclass of cls.

pyquil.quilbase.reset_label_counter()
pyquil.quilbase.unpack_qubit(qubit)

Get a qubit from an object.

Parameters:qubit – An int or AbstractQubit.
Returns:An AbstractQubit instance