pytket.circuit

pytket.circuit.fresh_symbol(preferred: str = 'a') Symbol

Given some preferred symbol, this finds an appropriate suffix that will guarantee it has not yet been used in the current python session.

Parameters

preferred – The preferred readable symbol name as a string (default is ‘a’)

Returns

A new sympy symbol object

class pytket.circuit.Op

Encapsulates operation information

static create(*args, **kwargs)

Overloaded function.

  1. create(arg0: pytket.circuit.OpType) -> pytket.circuit.Op

Create an Op with given type

  1. create(arg0: pytket.circuit.OpType, arg1: Expression) -> pytket.circuit.Op

Create an Op with given type and parameter

  1. create(arg0: pytket.circuit.OpType, arg1: List[Expression]) -> pytket.circuit.Op

Create an Op with given type and parameters

get_name(self: pytket.circuit.Op, latex: bool = False) str

String representation of op

get_unitary(self: pytket.circuit.Op) numpy.ndarray[numpy.complex128[m, n]]
is_gate(self: pytket.circuit.Op) bool
property n_qubits

Number of qubits of op

property params

Angular parameters of the op, in half-turns (e.g. 1.0 half-turns is \(\pi\) radians). The parameters returned are constrained to the appropriate canonical range, which is usually the half-open interval [0,2) but for some operations (e.g. Rx, Ry and Rz) is [0,4).

property type

Type of op being performed

class pytket.circuit.Command

A single quantum command in the circuit, defined by the Op, the qubits it acts on, and the op group name if any.

free_symbols(self: pytket.circuit.Command) Set[Symbol]
Returns

set of symbolic parameters for the command

property args

The qubits/bits the command acts on.

property bits

The bits the command could write to (does not include read-only bits).

property op

Operation for this command.

property opgroup

The op group name assigned to the command (or None if no name is defined).

property qubits

The qubits the command acts on.

class pytket.circuit.UnitType

Enum for data types of units in circuits (e.g. Qubits vs Bits).

Members:

qubit : A single Qubit

bit : A single classical Bit

property name
class pytket.circuit.UnitID

A handle to a computational unit (e.g. qubit, bit)

property index

Index vector describing position in the register. The length of this vector is the dimension of the register

property reg_name

Readable name of register

property type

Type of unit, either UnitType.qubit or UnitType.bit

class pytket.circuit.Qubit

A handle to a qubit

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket.circuit.Qubit, index: int) -> None

Constructs an id for some index in the default qubit register

Parameters

index – The index in the register

  1. __init__(self: pytket.circuit.Qubit, name: str) -> None

Constructs a named id (i.e. corresponding to a singleton register)

Parameters

name – The readable name for the id

  1. __init__(self: pytket.circuit.Qubit, name: str, index: int) -> None

Constructs an indexed id (i.e. corresponding to an element in a linear register)

Parameters
  • name – The readable name for the register

  • index – The numerical index

  1. __init__(self: pytket.circuit.Qubit, name: str, row: int, col: int) -> None

Constructs a doubly-indexed id (i.e. corresponding to an element in a grid register)

Parameters
  • name – The readable name for the register

  • row – The row index

  • col – The column index

  1. __init__(self: pytket.circuit.Qubit, name: str, index: List[int]) -> None

Constructs an id with an arbitrary-dimensional index

Parameters
  • name – The readable name for the register

  • index – The index vector

static from_list(arg0: json) pytket.circuit.Qubit

Construct Qubit instance from JSON serializable list representation of the Qubit.

to_list(self: pytket.circuit.Qubit) json
Returns

a JSON serializable list representation of the Qubit

class pytket.circuit.Bit

A handle to a bit

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket.circuit.Bit, index: int) -> None

Constructs an id for some index in the default classical register

Parameters

index – The index in the register

  1. __init__(self: pytket.circuit.Bit, name: str) -> None

Constructs a named id (i.e. corresponding to a singleton register)

Parameters

name – The readable name for the id

  1. __init__(self: pytket.circuit.Bit, name: str, index: int) -> None

Constructs an indexed id (i.e. corresponding to an element in a linear register)

Parameters
  • name – The readable name for the register

  • index – The numerical index

  1. __init__(self: pytket.circuit.Bit, name: str, row: int, col: int) -> None

Constructs a doubly-indexed id (i.e. corresponding to an element in a grid register)

Parameters
  • name – The readable name for the register

  • row – The row index

  • col – The column index

  1. __init__(self: pytket.circuit.Bit, name: str, index: List[int]) -> None

Constructs an id with an arbitrary-dimensional index

Parameters
  • name – The readable name for the register

  • index – The index vector

static from_list(arg0: json) pytket.circuit.Bit

Construct Bit instance from JSON serializable list representation of the Bit.

oldeq()

__eq__(*args, **kwargs) Overloaded function.

  1. __eq__(self: pytket.circuit.UnitID, arg0: pytket.circuit.UnitID) -> bool

  2. __eq__(self: pytket.circuit.UnitID, arg0: pytket.circuit.UnitID) -> bool

to_list(self: pytket.circuit.Bit) json

Return a JSON serializable list representation of the Bit. :return: list containing register name and index

class pytket.circuit.Node

A handle to a device node

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket.circuit.Node, index: int) -> None

Constructs an id for some index in the default physical register

Parameters

index – The index in the register

  1. __init__(self: pytket.circuit.Node, name: str, index: int) -> None

Constructs an indexed id (i.e. corresponding to an element in a linear register)

Parameters
  • name – The readable name for the register

  • index – The numerical index

  1. __init__(self: pytket.circuit.Node, name: str, row: int, col: int) -> None

Constructs a doubly-indexed id (i.e. corresponding to an element in a grid register)

Parameters
  • name – The readable name for the register

  • row – The row index

  • col – The column index

  1. __init__(self: pytket.circuit.Node, name: str, row: int, col: int, layer: int) -> None

Constructs a triply-indexed id (i.e. corresponding to an element in a 3D grid register)

Parameters
  • name – The readable name for the register

  • row – The row index

  • col – The column index

  • layer – The layer index

  1. __init__(self: pytket.circuit.Node, name: str, index: List[int]) -> None

Constructs an id with an arbitrary-dimensional index

Parameters
  • name – The readable name for the register

  • index – The index vector

static from_list(arg0: json) pytket.circuit.Node

Construct Node instance from JSON serializable list representation of the Node.

to_list(self: pytket.circuit.Node) json
Returns

a JSON serializable list representation of the Node

class pytket.circuit.QubitRegister

Linear register of UnitID types.

__getitem__(self: pytket.circuit.QubitRegister, arg0: int) pytket.circuit.Qubit
__init__(self: pytket.circuit.QubitRegister, name: str, size: int) None

Construct a new QubitRegister.

Parameters
  • name – Name of the register.

  • size – Size of register.

property name

Name of register.

property size

Size of register.

class pytket.circuit.BitRegister

Linear register of UnitID types.

__getitem__(self: pytket.circuit.BitRegister, arg0: int) pytket.circuit.Bit
__init__(self: pytket.circuit.BitRegister, name: str, size: int) None

Construct a new BitRegister.

Parameters
  • name – Name of the register.

  • size – Size of register.

property name

Name of register.

property size

Size of register.

class pytket.circuit.BasisOrder

Enum for readout basis and ordering. Readouts are viewed in increasing lexicographic order (ILO) of the bit’s UnitID. This is our default convention for column indexing for ALL readout forms (shots, counts, statevector, and unitaries). e.g. \(\lvert abc \rangle\) corresponds to the readout: (‘c’, 0) –> \(a\), (‘c’, 1) –> \(b\), (‘d’, 0) –> \(c\) For statevector and unitaries, the string abc is interpreted as an index in a big-endian (BE) fashion. e.g. the statevector \((a_{00}, a_{01}, a_{10}, a_{11})\) Some backends (Qiskit, ProjectQ, etc.) use a DLO-BE (decreasing lexicographic order, big-endian) convention. This is the same as ILO-LE (little-endian) for statevectors and unitaries, but gives shot tables/readouts in a counter-intuitive manner. Every backend and matrix-based box has a BasisOrder option which can toggle between ILO-BE (ilo) and DLO-BE (dlo).

Members:

ilo : Increasing Lexicographic Order of UnitID, big-endian

dlo : Decreasing Lexicographic Order of UnitID, big-endian

property name
class pytket.circuit.CircBox

A user-defined operation specified by a Circuit.

__init__(self: pytket.circuit.CircBox, circ: pytket.circuit.Circuit) None

Construct from a Circuit.

get_circuit(self: pytket.circuit.CircBox) pytket.circuit.Circuit
Returns

the Circuit described by the box

class pytket.circuit.Unitary1qBox

A user-defined one-qubit operation specified by a unitary matrix.

__init__(self: pytket.circuit.Unitary1qBox, m: numpy.ndarray[numpy.complex128[2, 2]]) None

Construct from a unitary matrix.

get_circuit(self: pytket.circuit.Unitary1qBox) pytket.circuit.Circuit
Returns

the Circuit described by the box

get_matrix(self: pytket.circuit.Unitary1qBox) numpy.ndarray[numpy.complex128[2, 2]]
Returns

the unitary matrix as a numpy array

class pytket.circuit.Unitary2qBox

A user-defined two-qubit operation specified by a unitary matrix.

__init__(self: pytket.circuit.Unitary2qBox, m: numpy.ndarray[numpy.complex128[4, 4]], basis: pytket.circuit.BasisOrder = BasisOrder.ilo) None

Construct from a unitary matrix.

Parameters
  • m – The unitary matrix

  • basis – Whether the provided unitary is in the ILO-BE (increasing lexicographic order of qubit ids, big-endian indexing) format, or DLO-BE (decreasing lexicographic order of ids)

get_circuit(self: pytket.circuit.Unitary2qBox) pytket.circuit.Circuit
Returns

the Circuit described by the box

get_matrix(self: pytket.circuit.Unitary2qBox) numpy.ndarray[numpy.complex128[4, 4]]
Returns

the unitary matrix (in ILO-BE format) as a numpy array

class pytket.circuit.ExpBox

A user-defined two-qubit operation whose corresponding unitary matrix is the exponential of a user-defined hermitian matrix.

__init__(self: pytket.circuit.ExpBox, A: numpy.ndarray[numpy.complex128[4, 4]], t: float, basis: pytket.circuit.BasisOrder = BasisOrder.ilo) None

Construct \(e^{itA}\) from a hermitian matrix \(A\) and a parameter \(t\).

Parameters
  • A – A hermitian matrix

  • t – Exponentiation parameter

  • basis – Whether the provided matrix is in the ILO-BE (increasing lexicographic order of qubit ids, big-endian indexing) format, or DLO-BE (decreasing lexicographic order of ids)

get_circuit(self: pytket.circuit.ExpBox) pytket.circuit.Circuit
Returns

the Circuit described by the box

class pytket.circuit.PauliExpBox

An operation defined as the exponential of a tensor of Pauli operations and a (possibly symbolic) phase parameter.

__init__(self: pytket.circuit.PauliExpBox, paulis: List[pytket.circuit.Pauli], t: Expression) None

Construct \(e^{-\frac12 i \pi t \sigma_0 \otimes \sigma_1 \otimes \cdots}\) from Pauli operators \(\sigma_i \in \{I,X,Y,Z\}\) and a parameter \(t\).

get_circuit(self: pytket.circuit.PauliExpBox) pytket.circuit.Circuit
Returns

the Circuit described by the box

get_paulis(self: pytket.circuit.PauliExpBox) List[pytket.circuit.Pauli]
Returns

the corresponding list of Pauli s

get_phase(self: pytket.circuit.PauliExpBox) Expression
Returns

the corresponding phase parameter

class pytket.circuit.QControlBox

A user-defined controlled operation specified by an Op and the number of quantum controls.

__init__(self: pytket.circuit.QControlBox, op: pytket.circuit.Op, n: int = 1) None

Construct from an Op and a number of quantum controls. The controls occupy the low-index ports of the resulting operation.

get_circuit(self: pytket.circuit.QControlBox) pytket.circuit.Circuit
Returns

the Circuit described by the box

get_n_controls(self: pytket.circuit.QControlBox) int
Returns

the number of control qubits

get_op(self: pytket.circuit.QControlBox) pytket.circuit.Op
Returns

the underlying operator

class pytket.circuit.CustomGateDef

A custom unitary gate definition, given as a composition of other gates

static define(name: str, circ: pytket.circuit.Circuit, args: List[Symbol]) pytket.circuit.CustomGateDef

Define a new custom gate as a composite of other gates

Parameters
  • name – Readable name for the new gate

  • circ – The definition of the gate as a Circuit

  • args – Symbols to be encapsulated as arguments of the custom gate

property arity

The number of real parameters for the gate

property def

Return definition as a circuit.

property name

The readable name of the gate

class pytket.circuit.CustomGate

A user-defined gate defined by a parametrised Circuit.

get_circuit(self: pytket.circuit.CustomGate) pytket.circuit.Circuit
Returns

the Circuit described by the gate.

property gate

Underlying gate object.

property name

The readable name of the gate.

property params

The parameters of the gate.

class pytket.circuit.Conditional

A wrapper for an operation to be applied conditionally on the value of some classical bits (following the nature of conditional operations in the OpenQASM specification).

property op

The operation to be applied conditionally

property value

The little-endian value the classical register must read in order to apply the operation (e.g. value 2 (10b) means bits[0] must be 0 and bits[1] must be 1)

property width

The number of bits in the condition register

class pytket.circuit.ClassicalExpBox

A box for holding classical expressions on Bits.

content_equality(self: pytket.circuit.ClassicalExpBox, arg0: pytket.circuit.ClassicalExpBox) bool

Check whether two ClassicalExpBox are equal in content

get_exp(self: pytket.circuit.ClassicalExpBox) object
Returns

the classical expression

get_n_i(self: pytket.circuit.ClassicalExpBox) int
Returns

the number of pure inputs to the box.

get_n_io(self: pytket.circuit.ClassicalExpBox) int
Returns

the number of inputs/outputs to the box.

get_n_o(self: pytket.circuit.ClassicalExpBox) int
Returns

the number of pure outputs from the box.

class pytket.circuit.ProjectorAssertionBox

A user-defined assertion specified by a 2x2, 4x4, or 8x8 projector matrix.

__init__(self: pytket.circuit.ProjectorAssertionBox, m: numpy.ndarray[numpy.complex128[m, n]], basis: pytket.circuit.BasisOrder = BasisOrder.ilo) None

Construct from a projector matrix.

Parameters
  • m – The projector matrix

  • basis – Whether the provided unitary is in the ILO-BE (increasing lexicographic order of qubit ids, big-endian indexing) format, or DLO-BE (decreasing lexicographic order of ids)

class pytket.circuit.StabiliserAssertionBox

A user-defined assertion specified by a list of pauli stabilisers.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket.circuit.StabiliserAssertionBox, stabilisers: List[pytket.circuit.PauliStabiliser]) -> None

Construct from a list of pauli stabilisers.

Parameters

m – The list of pauli stabilisers

  1. __init__(self: pytket.circuit.StabiliserAssertionBox, stabilisers: List[str]) -> None

Construct from a list of pauli stabilisers.

Parameters

m – The list of pauli stabilisers expressed as Python strings