A QuantumFlow Program is an implementation of the Quantum Abstract Machine from A Practical Quantum Instruction Set Architecture. [1] A Program can be built programatically by appending Instuctions, or can be parsed from code written in Rigetti’s Quantum Instruction Language (Quil). This Quantum Virtual Machine represents a hybrid device with quantum computation and classical control flow.

[1]A Practical Quantum Instruction Set Architecture Robert S. Smith, Michael J. Curtis, William J. Zeng arXiv:1608.03355
import quantumflow as qf

# Create an empty Program
prog = qf.Program()

# Measure qubit 0 and store result in classical bit (cbit) o
prog += qf.Measure(0, 0)

# Apply an X gate to qubit 0
prog += qf.Call('X', params=[], qubits=[0])

# Measure qubit 0 and store result in cbit 1.
prog += qf.Measure(0, 1)

# Compile and run program

# Contents of classical memory
assert prog.memory == {0: 0, 1: 1}


class quantumflow.Instruction

An program instruction a hybrid quantum-classical program. Represents such operations as control flow and declarations.


Return the name of this operation


Return the total number of qubits


Return the qubits that this operation acts upon

run(ket: qf.State) → qf.State

Apply the action of this operation upon a pure state

class quantumflow.Program(instructions: List[quantumflow.programs.Instruction] = None, name: str = None, params: dict = None)

A Program for a hybrid quantum computer, following the Quil quantum instruction set architecture.


Return the qubits that this operation acts upon

run(ket: qf.State = None) → qf.State

Compiles and runs a program. The optional program argument supplies the initial state and memory. Else qubits and classical bits start from zero states.

class quantumflow.DefCircuit(name: str, params: Dict[str, float], qubits: Qubits = None, instructions: List[quantumflow.programs.Instruction] = None)

Define a parameterized sub-circuit of instructions.

class quantumflow.Wait

Returns control to higher level by calling Program.wait()

class quantumflow.Nop

No operation

class quantumflow.Halt

Halt program and exit

class quantumflow.Reset(*qubits)

An operation that resets qubits to zero irrespective of the initial state.

class quantumflow.And(target: quantumflow.cbits.Addr, source: Union[quantumflow.cbits.Addr, numbers.Number])

Classical logical And of two addresses. Result placed in target

class quantumflow.Or(target: quantumflow.cbits.Addr, source: Union[quantumflow.cbits.Addr, numbers.Number])

Take logical inclusive-or of two classical bits, and place result in first bit. (Deprecated in quil. Use Ior instead.

class quantumflow.Move(target: quantumflow.cbits.Addr, source: Union[quantumflow.cbits.Addr, numbers.Number])

Copy left classical bit to right classical bit

class quantumflow.Exchange(target: quantumflow.cbits.Addr, source: Union[quantumflow.cbits.Addr, numbers.Number])

Exchange two classical bits

class quantumflow.Not(target: quantumflow.cbits.Addr)

Take logical Not of a classical bit.

class quantumflow.Label(target: str)

Set a jump target.

class quantumflow.Jump(target: str)

Unconditional jump to target label

class quantumflow.JumpWhen(target: str, condition: quantumflow.cbits.Addr)

Jump to target label if a classical bit is one.

class quantumflow.JumpUnless(target: str, condition: quantumflow.cbits.Addr)

Jump to target label if a classical bit is zero.

class quantumflow.Pragma(command: str, args: List[float] = None, freeform: str = None)

A PRAGMA instruction.

This is printed in QUIL as::
PRAGMA <command> <arg>* “<freeform>”?
class quantumflow.Measure(qubit: Qubit, cbit: quantumflow.cbits.Addr = None)

Measure a quantum bit and copy result to a classical bit

class quantumflow.Include(filename: str, program: quantumflow.programs.Program = None)

Include additional file of quil instructions.

(Currently recorded, but not acted upon)

class quantumflow.Call(name: str, params: List[Parameter], qubits: Qubits)

Pass control to a named gate or circuit