pytket.circuit

The circuit module provides an API to interact with the tket Circuit data structure. This module is provided in binary form during the PyPI installation.

circuit.fresh_symbol(preferred: str = 'a') sympy.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

create(arg: pytket.circuit.OpType, /) pytket.circuit.Op
create(arg0: pytket.circuit.OpType, arg1: Union[sympy.Expr, float], /) pytket.circuit.Op
create(arg0: pytket.circuit.OpType, arg1: collections.abc.Sequence[Union[sympy.Expr, float]], /) pytket.circuit.Op

Overloaded function.

  1. create(arg: pytket.circuit.OpType, /) -> pytket.circuit.Op

Create an Op with given type

  1. create(arg0: pytket.circuit.OpType, arg1: typing.Union[sympy.Expr, float], /) -> pytket.circuit.Op

Create an Op with given type and parameter

  1. create(arg0: pytket.circuit.OpType, arg1: collections.abc.Sequence[typing.Union[sympy.Expr, float]], /) -> pytket.circuit.Op

Create an Op with given type and parameters

free_symbols(self) set[sympy.Symbol]
get_name(self, latex: bool = False) str

String representation of op

get_unitary(self) numpy.ndarray[dtype=complex128, shape=(*, *), order='F']
is_clifford(self) bool

Test whether the operation is in the Clifford group. A return value of true guarantees that the operation is Clifford. However, the converse is not the case as some Clifford operations may not be detected as such.

is_clifford_type(self) bool

Check if the operation is one of the Clifford OpType s.

is_gate(self) bool
property dagger

Dagger of op

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 transpose

Transpose of op

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) set[sympy.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.

enum pytket.circuit.BasisOrder(value)

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).

Valid values are as follows:

ilo = BasisOrder.ilo

Increasing Lexicographic Order of UnitID, big-endian

dlo = BasisOrder.dlo

Decreasing Lexicographic Order of UnitID, big-endian

enum pytket.circuit.CXConfigType(value)

Enum for available configurations for CXs upon decompose phase gadgets

Valid values are as follows:

Snake = CXConfigType.Snake

linear nearest neighbour CX sequence. Linear depth.

Star = CXConfigType.Star

Every CX has same target, linear depth, good for gate cancellation.

Tree = CXConfigType.Tree

Balanced tree: logarithmic depth, harder to route.

MultiQGate = CXConfigType.MultiQGate

Support for multi-qubit architectures, decomposing to 3-qubit XXPhase3 gates instead of CXs where possible.

enum pytket.circuit.EdgeType(value)

Type of a wire in a circuit or input to an op

Valid values are as follows:

Boolean = EdgeType.Boolean
Classical = EdgeType.Classical
Quantum = EdgeType.Quantum
WASM = EdgeType.WASM
class pytket.circuit.CircBox

A user-defined operation specified by a Circuit.

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

Construct from a Circuit.

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

symbol_substitution(self, symbol_map: collections.abc.Mapping[sympy.Symbol, Union[sympy.Expr, float]]) None

In-place substitution of symbolic expressions within underlying circuit; iterates through each parameterised gate/box within the circuit and performs the substitution.

WARNING: This method potentially mutates the CircBox and any changes are propagated to any Circuit that the CircBox has been added to (via Circuit.add_circbox).

Parameters:

symbol_map – A map from SymPy symbols to SymPy expressions

property circuit_name

the name of the contained circuit.

WARNING: Setting this property mutates the CircBox and any changes are propagated to any Circuit that the CircBox has been added to (via Circuit.add_circbox).

Type:

return

class pytket.circuit.Unitary1qBox

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

__init__(self, m: numpy.ndarray[dtype=complex128, shape=(2, 2), order='F']) None

Construct from a unitary matrix.

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_matrix(self) numpy.ndarray[dtype=complex128, shape=(2, 2), order='F']
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, m: numpy.ndarray[dtype=complex128, shape=(4, 4), order='F'], 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.Circuit
Returns:

the Circuit described by the box

get_matrix(self) numpy.ndarray[dtype=complex128, shape=(4, 4), order='F']
Returns:

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

class pytket.circuit.Unitary3qBox

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

__init__(self, m: numpy.ndarray[dtype=complex128, shape=(*, *), order='F'], 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.Circuit
Returns:

the Circuit described by the box

get_matrix(self) numpy.ndarray[dtype=complex128, shape=(8, 8), order='F']
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, A: numpy.ndarray[dtype=complex128, shape=(4, 4), order='F'], 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.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, paulis: collections.abc.Sequence[pytket.pauli.Pauli], t: Union[sympy.Expr, float], cx_config_type: pytket.circuit.CXConfigType = CXConfigType.Tree) 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.Circuit
Returns:

the Circuit described by the box

get_cx_config(self) pytket.circuit.CXConfigType
Returns:

decomposition method

get_paulis(self) list[pytket.pauli.Pauli]
Returns:

the corresponding list of Pauli s

get_phase(self) Union[sympy.Expr, float]
Returns:

the corresponding phase parameter

class pytket.circuit.PauliExpPairBox

A pair of (not necessarily commuting) Pauli exponentials performed in sequence. Pairing up exponentials for synthesis can reduce gate costs of synthesis compared to synthesising individually, with the best reductions found when the Pauli tensors act on a large number of the same qubits. Phase parameters may be symbolic.

__init__(self, paulis0: collections.abc.Sequence[pytket.pauli.Pauli], t0: Union[sympy.Expr, float], paulis1: collections.abc.Sequence[pytket.pauli.Pauli], t1: Union[sympy.Expr, float], cx_config_type: pytket.circuit.CXConfigType = CXConfigType.Tree) None

Construct a pair of Pauli exponentials of the form \(e^{-\frac12 i \pi t_j \sigma_0 \otimes \sigma_1 \otimes \cdots}\) from Pauli operator strings \(\sigma_i \in \{I,X,Y,Z\}\) and parameters \(t_j, j \in \{0,1\}\).

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self) pytket.circuit.CXConfigType
Returns:

decomposition method

get_paulis_pair(self) tuple[list[pytket.pauli.Pauli], list[pytket.pauli.Pauli]]
Returns:

A tuple containing the two corresponding lists of Pauli s

get_phase_pair(self) tuple[Union[sympy.Expr, float], Union[sympy.Expr, float]]
Returns:

A tuple containing the two phase parameters

class pytket.circuit.PauliExpCommutingSetBox

An operation defined as a set of commuting of exponentials of atensor of Pauli operations and their (possibly symbolic) phase parameters.

__init__(self, pauli_gadgets: collections.abc.Sequence[tuple[collections.abc.Sequence[pytket.pauli.Pauli], Union[sympy.Expr, float]]], cx_config_type: pytket.circuit.CXConfigType = CXConfigType.Tree) None

Construct a set of necessarily commuting Pauli exponentials of the form \(e^{-\frac12 i \pi t_j \sigma_0 \otimes \sigma_1 \otimes \cdots}\) from Pauli operator strings \(\sigma_i \in \{I,X,Y,Z\}\) and parameters \(t_j, j \in \{0, 1, \cdots \}\).

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self) pytket.circuit.CXConfigType
Returns:

decomposition method

get_paulis(self) list[tuple[list[pytket.pauli.Pauli], Union[sympy.Expr, float]]]
Returns:

the corresponding list of Pauli gadgets

class pytket.circuit.TermSequenceBox

An unordered collection of Pauli exponentials that can be synthesised in any order, causing a change in the unitary operation. Synthesis order depends on the synthesis strategy chosen only.

WARNING: Global phase is not preserved when using PauliSynthStrat.Greedy.

__init__(self, pauli_gadgets: collections.abc.Sequence[tuple[collections.abc.Sequence[pytket.pauli.Pauli], Union[sympy.Expr, float]]], synthesis_strategy: pytket.transform.PauliSynthStrat = PauliSynthStrat.Sets, partitioning_strategy: pytket.partition.PauliPartitionStrat = PauliPartitionStrat.CommutingSets, graph_colouring: pytket.partition.GraphColourMethod = GraphColourMethod.Lazy, cx_config_type: pytket.circuit.CXConfigType = CXConfigType.Tree, depth_weight: float = 0.3) None

Construct a set of Pauli exponentials of the form \(e^{-\frac12 i \pi t_j \sigma_0 \otimes \sigma_1 \otimes \cdots}\) from Pauli operator strings \(\sigma_i \in \{I,X,Y,Z\}\) and parameters \(t_j, j \in \{0, 1, \cdots \}\). depth_weight controls the degree of depth optimisation and only applies to synthesis_strategy PauliSynthStrat:Greedy. partitioning_strategy, graph_colouring, and cx_config_type have no effect if PauliSynthStrat.Greedy is used.

WARNING: Global phase is not preserved when using PauliSynthStrat.Greedy.

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self) pytket.circuit.CXConfigType
Returns:

cx decomposition method

get_depth_weight(self) float
Returns:

depth tuning parameter

get_graph_colouring_method(self) pytket.partition.GraphColourMethod
Returns:

graph colouring method

get_partition_strategy(self) pytket.partition.PauliPartitionStrat
Returns:

partitioning strategy

get_paulis(self) list[tuple[list[pytket.pauli.Pauli], Union[sympy.Expr, float]]]
Returns:

the corresponding list of Pauli gadgets

get_synthesis_strategy(self) pytket.transform.PauliSynthStrat
Returns:

synthesis strategy

enum pytket.circuit.ToffoliBoxSynthStrat(value)

Enum strategies for synthesising ToffoliBoxes

Valid values are as follows:

Matching = ToffoliBoxSynthStrat.Matching

Use multiplexors to perform parallel swaps on hypercubes

Cycle = ToffoliBoxSynthStrat.Cycle

Use CnX gates to perform transpositions

class pytket.circuit.ToffoliBox

An operation that constructs a circuit to implement the specified permutation of classical basis states.

__init__(self, permutation: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[bool]]], strat: pytket.circuit.ToffoliBoxSynthStrat, rotation_axis: pytket.circuit.OpType = OpType.Ry) None
__init__(self, permutation: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[bool]]], rotation_axis: pytket.circuit.OpType = OpType.Ry) None
__init__(self, n_qubits: int, permutation: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[bool]]], rotation_axis: pytket.circuit.OpType = OpType.Ry) None
__init__(self, permutation: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[bool]], strat: pytket.circuit.ToffoliBoxSynthStrat, rotation_axis: pytket.circuit.OpType = OpType.Ry) None
__init__(self, permutation: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[bool]], rotation_axis: pytket.circuit.OpType = OpType.Ry) None
__init__(self, n_qubits: int, permutation: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[bool]], rotation_axis: pytket.circuit.OpType = OpType.Ry) None

Overloaded function.

  1. __init__(self, permutation: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[bool]]], strat: pytket.circuit.ToffoliBoxSynthStrat, rotation_axis: pytket.circuit.OpType = OpType.Ry) -> None

Construct from a permutation of basis states

Parameters:
  • permutation – a list of bitstring pairs

  • strat – synthesis strategy

  • rotation_axis – the rotation axis of the multiplexors used in the decomposition. Can be either Rx or Ry. Only applicable to the Matching strategy. Default to Ry.

  1. __init__(self, permutation: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[bool]]], rotation_axis: pytket.circuit.OpType = OpType.Ry) -> None

Construct from a permutation of basis states and perform synthesis using the Matching strategy

Parameters:
  • permutation – a list of bitstring pairs

  • rotation_axis – the rotation axis of the multiplexors used in the decomposition. Can be either Rx or Ry, default to Ry.

  1. __init__(self, n_qubits: int, permutation: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[bool]]], rotation_axis: pytket.circuit.OpType = OpType.Ry) -> None

Constructor for backward compatibility. Subject to deprecation.

  1. __init__(self, permutation: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[bool]], strat: pytket.circuit.ToffoliBoxSynthStrat, rotation_axis: pytket.circuit.OpType = OpType.Ry) -> None

Construct from a permutation of basis states

Parameters:
  • permutation – a map between bitstrings

  • strat – synthesis strategy

  • rotation_axis – the rotation axis of the multiplexors used in the decomposition. Can be either Rx or Ry. Only applicable to the Matching strategy. Default to Ry.

  1. __init__(self, permutation: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[bool]], rotation_axis: pytket.circuit.OpType = OpType.Ry) -> None

Construct from a permutation of basis states and perform synthesis using the Matching strategy

Parameters:
  • permutation – a map between bitstrings

  • rotation_axis – the rotation axis of the multiplexors used in the decomposition. Can be either Rx or Ry, default to Ry.

  1. __init__(self, n_qubits: int, permutation: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[bool]], rotation_axis: pytket.circuit.OpType = OpType.Ry) -> None

Constructor for backward compatibility. Subject to deprecation.

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_permutation(self) dict[tuple, tuple]
Returns:

the permutation

get_rotation_axis(self) pytket.circuit.OpType
Returns:

the rotation axis

get_strat(self) pytket.circuit.ToffoliBoxSynthStrat
Returns:

the synthesis strategy

class pytket.circuit.QControlBox

A user-defined controlled operation specified by an Op, the number of quantum controls, and the control state expressed as an integer or a bit vector.

__init__(self, op: pytket.circuit.Op, n_controls: int = 1, control_state: collections.abc.Sequence[bool] = []) None
__init__(self, op: pytket.circuit.Op, n_controls: int, control_state: int) None
__init__(self, op: pytket.circuit.Op, n: int = 1) None

Overloaded function.

  1. __init__(self, op: pytket.circuit.Op, n_controls: int = 1, control_state: collections.abc.Sequence[bool] = []) -> None

Construct from an Op, a number of quantum controls, and the control state expressed as a bit vector. The controls occupy the low-index ports of the resulting operation.

Parameters:
  • op – the underlying operator

  • n_controls – the number of control qubits. Default to 1

  • control_state – the control state expressed as a bit vector. Default to all 1s

  1. __init__(self, op: pytket.circuit.Op, n_controls: int, control_state: int) -> None

Construct from an Op, a number of quantum controls, and the control state expressed as an integer. The controls occupy the low-index ports of the resulting operation.

Parameters:
  • op – the underlying operator

  • n_controls – the number of control qubits

  • control_state – the control state expressed as an integer. Big-endian

  1. __init__(self, 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.Circuit
Returns:

the Circuit described by the box

get_control_state(self) int
Returns:

the control state as an integer (big-endian binary representation)

get_control_state_bits(self) list[bool]
Returns:

the control state as a bit vector

get_n_controls(self) int
Returns:

the number of control qubits

get_op(self) pytket.circuit.Op
Returns:

the underlying operator

class pytket.circuit.CustomGateDef

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

define(name: str, circ: pytket.circuit.Circuit, args: collections.abc.Sequence[sympy.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

from_dict(arg: dict, /) pytket.circuit.CustomGateDef

Construct Circuit instance from JSON serializable dictionary representation of the Circuit.

to_dict(self) dict
Returns:

a JSON serializable dictionary representation of the CustomGateDef

property args

Return symbolic arguments of gate.

property arity

The number of real parameters for the gate

property definition

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.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.ClExprOp

An operation defined by a classical expression

__init__(self, arg: pytket.circuit.WiredClExpr, /) None

Construct from a wired classical expression

property expr

wired expression

property type

operation type

class pytket.circuit.WiredClExpr

An operation defined by a classical expression over a sequence of bits

__init__(self, expr: pytket.circuit.ClExpr, bit_posn: collections.abc.Mapping[int, int] = {}, reg_posn: collections.abc.Mapping[int, collections.abc.Sequence[int]] = {}, output_posn: collections.abc.Sequence[int] = []) None

Construct from an expression with bit and register positions.

Parameters:
  • expr – an abstract classical expression

  • bit_posn – a map whose keys are the indices of the ClBitVar occurring in the expression, and whose values are the positions of the corresponding bits in the arguments of the operation

  • reg_posn – a map whose keys are the indices of the ClRegVar occurring in the expression, and whose values are the sequences of positions of the corresponding bits in the arguments of the operation

  • output_posn – a list giving the positions of the output bits in the arguments of the operation

from_dict(arg: dict, /) pytket.circuit.WiredClExpr

Construct from JSON-serializable dict representation

to_dict(self) dict
Returns:

JSON-serializable dict representation

property bit_posn

bit positions

property expr

expression

property output_posn

output positions

property reg_posn

register positions

class pytket.circuit.ClExpr

A classical expression

__init__(self, op: pytket.circuit.ClOp, args: collections.abc.Sequence[int | pytket.circuit.ClBitVar | pytket.circuit.ClRegVar | pytket.circuit.ClExpr]) None

Construct from an operation type and a list of arguments.

Parameters:
  • op – the operation type

  • args – list of arguments to the expression (which may be integers, ClBitVar variables, ClRegVar variables, or other ClExpr)

as_qasm(self, input_bits: collections.abc.Mapping[int, pytket.unit_id.Bit], input_regs: collections.abc.Mapping[int, pytket.unit_id.BitRegister]) str

QASM-style string representation given corresponding bits and registers

property args

arguments

property op

main operation

enum pytket.circuit.ClOp(value)

A classical operation

Member Type:

int

Valid values are as follows:

INVALID = ClOp.INVALID

Invalid

BitAnd = ClOp.BitAnd

Bitwise AND

BitOr = ClOp.BitOr

Bitwise OR

BitXor = ClOp.BitXor

Bitwise XOR

BitEq = ClOp.BitEq

Bitwise equality

BitNeq = ClOp.BitNeq

Bitwise inequality

BitNot = ClOp.BitNot

Bitwise NOT

BitZero = ClOp.BitZero

Constant zero bit

BitOne = ClOp.BitOne

Constant one bit

RegAnd = ClOp.RegAnd

Registerwise AND

RegOr = ClOp.RegOr

Registerwise OR

RegXor = ClOp.RegXor

Registerwise XOR

RegEq = ClOp.RegEq

Registerwise equality

RegNeq = ClOp.RegNeq

Registerwise inequality

RegNot = ClOp.RegNot

Registerwise NOT

RegZero = ClOp.RegZero

Constant all-zeros register

RegOne = ClOp.RegOne

Constant all-ones register

RegLt = ClOp.RegLt

Integer less-than comparison

RegGt = ClOp.RegGt

Integer greater-than comparison

RegLeq = ClOp.RegLeq

Integer less-than-or-equal comparison

RegGeq = ClOp.RegGeq

Integer greater-than-or-equal comparison

RegAdd = ClOp.RegAdd

Integer addition

RegSub = ClOp.RegSub

Integer subtraction

RegMul = ClOp.RegMul

Integer multiplication

RegDiv = ClOp.RegDiv

Integer division

RegPow = ClOp.RegPow

Integer exponentiation

RegLsh = ClOp.RegLsh

Left shift

RegRsh = ClOp.RegRsh

Right shift

RegNeg = ClOp.RegNeg

Integer negation

class pytket.circuit.ClBitVar

A bit variable within an expression

__init__(self, i: int) None

Construct from an integer identifier.

Parameters:

i – integer identifier for the variable

property index

integer identifier for the variable

class pytket.circuit.ClRegVar

A register variable within an expression

__init__(self, i: int) None

Construct from an integer identifier.

Parameters:

i – integer identifier for the variable

property index

integer identifier for the variable

class pytket.circuit.PhasePolyBox

Box encapsulating any Circuit made up of CNOT and RZ as a phase polynomial + linear transformation

__init__(self, n_qubits: int, qubit_indices: collections.abc.Mapping[pytket.unit_id.Qubit, int], phase_polynomial: collections.abc.Mapping[collections.abc.Sequence[bool], typing.Union[sympy.Expr, float]], linear_transformation: numpy.ndarray[dtype=bool, shape=(*, *), order='F']) None
__init__(self, n_qubits: int, qubit_indices: collections.abc.Mapping[pytket.unit_id.Qubit, int], phase_polynomial: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], typing.Union[sympy.Expr, float]]], linear_transformation: numpy.ndarray[dtype=bool, shape=(*, *), order='F']) None
__init__(self, circuit: pytket.circuit.Circuit) None

Overloaded function.

  1. __init__(self, n_qubits: int, qubit_indices: collections.abc.Mapping[pytket.unit_id.Qubit, int], phase_polynomial: collections.abc.Mapping[collections.abc.Sequence[bool], typing.Union[sympy.Expr, float]], linear_transformation: numpy.ndarray[dtype=bool, shape=(*, *), order='F']) -> None

Construct from the number of qubits, the mapping from Qubit to index, the phase polynomial (map from bitstring to phase) and the linear transformation (boolean matrix)

  1. __init__(self, n_qubits: int, qubit_indices: collections.abc.Mapping[pytket.unit_id.Qubit, int], phase_polynomial: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], typing.Union[sympy.Expr, float]]], linear_transformation: numpy.ndarray[dtype=bool, shape=(*, *), order='F']) -> None

Construct from the number of qubits, the mapping from Qubit to index, the phase polynomial (list of bitstring phase pairs) and the linear transformation (boolean matrix)

If any bitstring is repeated in the phase polynomial list, the last given value for that bistring will be used

  1. __init__(self, circuit: pytket.circuit.Circuit) -> None

Construct a PhasePolyBox from a given circuit containing only Rz and CX gates.

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box.

property linear_transformation

Boolean matrix corresponding to linear transformation.

property n_qubits

Number of gates the polynomial acts on.

property phase_polynomial

Map from bitstring (basis state) to phase.

property phase_polynomial_as_list

List of bitstring(basis state)-phase pairs.

property qubit_indices

Map from Qubit to index in polynomial.

class pytket.circuit.ProjectorAssertionBox

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

__init__(self, m: numpy.ndarray[dtype=complex128, shape=(*, *), order='F'], 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)

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_matrix(self) numpy.ndarray[dtype=complex128, shape=(*, *), order='F']
Returns:

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

class pytket.circuit.StabiliserAssertionBox

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

__init__(self, stabilisers: collections.abc.Sequence[pytket.pauli.PauliStabiliser]) None
__init__(self, stabilisers: collections.abc.Sequence[str]) None

Overloaded function.

  1. __init__(self, stabilisers: collections.abc.Sequence[pytket.pauli.PauliStabiliser]) -> None

Construct from a list of Pauli stabilisers.

Parameters:

stabilisers – The list of Pauli stabilisers

  1. __init__(self, stabilisers: collections.abc.Sequence[str]) -> None

Construct from a list of Pauli stabilisers.

Parameters:

m – The list of Pauli stabilisers expressed as Python strings

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_stabilisers(self) list[pytket.pauli.PauliStabiliser]
Returns:

the list of Pauli stabilisers

class pytket.circuit.WASMOp

An op holding an external classical call, defined by the external module id, the name of the function and the arguments. External calls can only act on entire registers (which will be interpreted as fixed-width integers).

__init__(self, num_bits: int, num_w: int, n_inputs: collections.abc.Sequence[int], n_outputs: collections.abc.Sequence[int], func_name: str, wasm_uid: str) None

Construct from number of bits, bitwidths of inputs and outputs, function name and module id.

property func_name

Name of function.

property input_widths

Widths of input integers.

property n_i32

Number of integers acted on.

property num_bits

Number of bits interacted with.

property num_w

Number of wasm wire in the op

property output_widths

Widths of output integers.

property wasm_uid

Wasm module id.

class pytket.circuit.MultiBitOp

An operation to apply a classical op multiple times in parallel.

__init__(self, op: pytket.circuit.ClassicalEvalOp, multiplier: int) None

Construct from a basic operation and a multiplier.

property basic_op

Underlying bitwise op.

property multiplier

Multiplier.

class pytket.circuit.SetBitsOp

An operation to set the values of Bits to some constants.

__init__(self, values: collections.abc.Sequence[bool]) None

Construct from a table of values.

property values

The values to set bits to.

class pytket.circuit.ClassicalEvalOp

Evaluatable classical operation.

__init__(*args, **kwargs)
class pytket.circuit.ClassicalOp

Classical operation.

__init__(*args, **kwargs)
property n_input_outputs

Number of pure input/output arguments.

property n_inputs

Number of pure inputs.

property n_outputs

Number of pure outputs.

class pytket.circuit.CopyBitsOp

An operation to copy the values of Bits to other Bits.

__init__(*args, **kwargs)
class pytket.circuit.RangePredicateOp

A predicate defined by a range of values in binary encoding.

__init__(self, width: int, lower: int, upper: int) None

Construct from a bit width, a lower bound and an upper bound.

property lower

Inclusive lower bound.

property upper

Inclusive upper bound.

class pytket.circuit.MultiplexorBox

A user-defined multiplexor (i.e. uniformly controlled operations) specified by a map from bitstrings to Op sor a list of bitstring-Op s pairs

__init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], pytket.circuit.Op]]) None
__init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], pytket.circuit.Op]) None

Overloaded function.

  1. __init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], pytket.circuit.Op]]) -> None

Construct from a list of bitstring-Op spairs

Parameters:

bitstring_to_op_list – List of bitstring-Op spairs

  1. __init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], pytket.circuit.Op]) -> None

Construct from a map from bitstrings to Op s

Parameters:

op_map – Map from bitstrings to Op s

get_bitstring_op_pair_list(self) list[tuple[list[bool], pytket.circuit.Op]]
Returns:

the underlying bistring-op pairs

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_op_map(self) dict[tuple, pytket.circuit.Op]
Returns:

the underlying op map

class pytket.circuit.MultiplexedRotationBox

A user-defined multiplexed rotation gate (i.e. uniformly controlled single-axis rotations) specified by a map from bitstrings to Op sor a list of bitstring-Op s pairs. Implementation based on arxiv.org/abs/quant-ph/0410066. The decomposed circuit has at most 2^k single-qubit rotations, 2^k CX gates, and two additional H gates if the rotation axis is X. k is the number of control qubits.

__init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], pytket.circuit.Op]]) None
__init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], pytket.circuit.Op]) None
__init__(self, angles: collections.abc.Sequence[float], axis: pytket.circuit.OpType) None

Overloaded function.

  1. __init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], pytket.circuit.Op]]) -> None

Construct from a list of bitstring-Op spairs

All Op s must share the same single-qubit rotation type: Rx, Ry, or Rz.

Parameters:

bitstring_to_op_list – List of bitstring-Op spairs

  1. __init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], pytket.circuit.Op]) -> None

Construct from a map from bitstrings to Op s.All Op s must share the same single-qubit rotation type: Rx, Ry, or Rz.

Parameters:

op_map – Map from bitstrings to Op s

  1. __init__(self, angles: collections.abc.Sequence[float], axis: pytket.circuit.OpType) -> None

Construct from a list of angles and the rotation axis.

Parameters:
  • angles – List of rotation angles in half-turns. angles[i] is the angle activated by the binary representation of i

  • axisOpType.Rx, OpType.Ry or OpType.Rz

get_bitstring_op_pair_list(self) list[tuple[list[bool], pytket.circuit.Op]]
Returns:

the underlying bistring-op pairs

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_op_map(self) dict[tuple, pytket.circuit.Op]
Returns:

the underlying op map

class pytket.circuit.MultiplexedU2Box

A user-defined multiplexed U2 gate (i.e. uniformly controlled U2 gate) specified by a map from bitstrings to Op sor a list of bitstring-Op s pairsImplementation based on arxiv.org/abs/quant-ph/0410066. The decomposed circuit has at most 2^k single-qubit gates, 2^k -1 CX gates, and a k+1 qubit DiagonalBox at the end. k is the number of control qubits.

__init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], pytket.circuit.Op]], impl_diag: bool = True) None
__init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], pytket.circuit.Op], impl_diag: bool = True) None

Overloaded function.

  1. __init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], pytket.circuit.Op]], impl_diag: bool = True) -> None

Construct from a list of bitstring-Op spairs

Only supports single qubit unitary gate types and Unitary1qBox.

Parameters:
  • op_map – List of bitstring-Op spairs

  • impl_diag – Whether to implement the final diagonal gate, default to True.

  1. __init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], pytket.circuit.Op], impl_diag: bool = True) -> None

Construct from a map from bitstrings to Op s.Only supports single qubit unitary gate types and Unitary1qBox.

Parameters:
  • op_map – Map from bitstrings to Op s

  • impl_diag – Whether to implement the final diagonal gate, default to True.

get_bitstring_op_pair_list(self) list[tuple[list[bool], pytket.circuit.Op]]
Returns:

the underlying bistring-op pairs

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_impl_diag(self) bool
Returns:

flag indicating whether to implement the final diagonal gate.

get_op_map(self) dict[tuple, pytket.circuit.Op]
Returns:

the underlying op map

class pytket.circuit.MultiplexedTensoredU2Box

A user-defined multiplexed tensor product of U2 gates specified by a map from bitstrings to lists of Op sor a list of bitstring-list(Op s) pairs. A box with k control qubits and t target qubits is implemented as t k-controlled multiplexed-U2 gates with their diagonal components merged and commuted to the end. The resulting circuit contains t non-diagonal components of the multiplexed-U2 decomposition, t k-controlled multiplexed-Rz boxes, and a k-qubit DiagonalBox at the end. The total CX count is at most 2^k(2t+1)-t-2.

__init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[pytket.circuit.Op]]]) None
__init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[pytket.circuit.Op]]) None

Overloaded function.

  1. __init__(self, bistring_to_op_list: collections.abc.Sequence[tuple[collections.abc.Sequence[bool], collections.abc.Sequence[pytket.circuit.Op]]]) -> None

Construct from a list of bitstring-Op spairs

Only supports single qubit unitary gate types and Unitary1qBox.

Parameters:

bitstring_to_op_list – List of bitstring-List of Op s pairs

  1. __init__(self, op_map: collections.abc.Mapping[collections.abc.Sequence[bool], collections.abc.Sequence[pytket.circuit.Op]]) -> None

Construct from a map from bitstrings to equal-sized lists of Op s. Only supports single qubit unitary gate types and Unitary1qBox.

Parameters:

op_map – Map from bitstrings to lists of Op s

get_bitstring_op_pair_list(self) list[tuple[list[bool], list[pytket.circuit.Op]]]
Returns:

the underlying bistring-op pairs

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_op_map(self) dict[tuple, list[pytket.circuit.Op]]
Returns:

the underlying op map

class pytket.circuit.StatePreparationBox

A box for preparing quantum states using multiplexed-Ry and multiplexed-Rz gates. Implementation based on Theorem 9 of arxiv.org/abs/quant-ph/0406176. The decomposed circuit has at most 2*(2^n-2) CX gates, and 2^n-2 CX gates if the coefficients are all real.

__init__(self, statevector: numpy.ndarray[dtype=complex128, shape=(*), order='C'], is_inverse: bool = False, with_initial_reset: bool = False) None

Construct from a statevector

Parameters:
  • statevector – normalised statevector

  • is_inverse – whether to implement the dagger of the state preparation circuit, default to false

  • with_initial_reset – whether to explicitly set the state to zero initially (by default the initial zero state is assumed and no explicit reset is applied)

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_statevector(self) numpy.ndarray[dtype=complex128, shape=(*), order='C']
Returns:

the statevector

is_inverse(self) bool
Returns:

flag indicating whether to implement the dagger of the state preparation circuit

with_initial_reset(self) bool
Returns:

flag indicating whether the qubits are explicitly set to the zero state initially

class pytket.circuit.DiagonalBox

A box for synthesising a diagonal unitary matrix into a sequence of multiplexed-Rz gates. Implementation based on Theorem 7 of arxiv.org/abs/quant-ph/0406176. The decomposed circuit has at most 2^n-2 CX gates.

__init__(self, diagonal: numpy.ndarray[dtype=complex128, shape=(*), order='C'], upper_triangle: bool = True) None

Construct from the diagonal entries of the unitary operator. The size of the vector must be 2^n where n is a positive integer.

Parameters:
  • diagonal – diagonal entries

  • upper_triangle – indicates whether the multiplexed-Rz gates take the shape of an upper triangle or a lower triangle. Default to true.

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_diagonal(self) numpy.ndarray[dtype=complex128, shape=(*), order='C']
Returns:

the statevector

is_upper_triangle(self) bool
Returns:

the upper_triangle flag

class pytket.circuit.ConjugationBox

A box to express computations that follow the compute-action-uncompute pattern.

__init__(self, compute: pytket.circuit.Op, action: pytket.circuit.Op, uncompute: pytket.circuit.Op | None = None) None

Construct from operations that perform compute, action, and uncompute. All three operations need to be quantum and have the same size.

Parameters:
  • compute – the compute operation

  • action – the action operation

  • uncompute – optional uncompute operation, default to compute.dagger(). If provided, the user needs to make sure that uncompute.dagger() and compute have the same unitary.

get_action(self) pytket.circuit.Op
Returns:

the action operation

get_circuit(self) pytket.circuit.Circuit
Returns:

the Circuit described by the box

get_compute(self) pytket.circuit.Op
Returns:

the compute operation

get_uncompute(self) pytket.circuit.Op | None
Returns:

the uncompute operation. Returns None if the default compute.dagger() is used

class pytket.circuit.ResourceBounds

Structure holding a minimum and maximum value of some resource, where both values are unsigned integers.

__init__(self, min: int, max: int) None

Constructs a ResourceBounds object.

Parameters:
  • min – minimum value

  • max – maximum value

get_max(self) int
Returns:

the maximum value

get_min(self) int
Returns:

the minimum value

class pytket.circuit.ResourceData

An object holding resource data for use in a DummyBox.

The object holds several fields representing minimum and maximum values for certain resources. The absence of an OpType in one of these fields is interpreted as the absence of gates of that type in the (imagined) circuit.

See Circuit.get_resources() for how to use this data.

__init__(self, op_type_count: collections.abc.Mapping[pytket.circuit.OpType, pytket.circuit.ResourceBounds], gate_depth: pytket.circuit.ResourceBounds, op_type_depth: collections.abc.Mapping[pytket.circuit.OpType, pytket.circuit.ResourceBounds], two_qubit_gate_depth: pytket.circuit.ResourceBounds) None

Constructs a ResourceData object.

Parameters:
  • op_type_count – dictionary of counts of selected OpType

  • gate_depth – overall gate depth

  • op_type_depth – dictionary of depths of selected OpType

  • two_qubit_gate_depth – overall two-qubit-gate depth

__repr__(self) str
get_gate_depth(self) pytket.circuit.ResourceBounds
Returns:

bounds on the gate depth

get_op_type_count(self) dict[pytket.circuit.OpType, pytket.circuit.ResourceBounds]
Returns:

bounds on the op type count

get_op_type_depth(self) dict[pytket.circuit.OpType, pytket.circuit.ResourceBounds]
Returns:

bounds on the op type depth

get_two_qubit_gate_depth(self) pytket.circuit.ResourceBounds
Returns:

bounds on the two-qubit-gate depth

class pytket.circuit.DummyBox

A placeholder operation that holds resource data. This box type cannot be decomposed into a circuit. It only serves to record resource data for a region of a circuit: for example, upper and lower bounds on gate counts and depth. A circuit containing such a box cannot be executed.

__init__(self, n_qubits: int, n_bits: int, resource_data: pytket.circuit.ResourceData) None

Construct a new instance from some resource data.

get_n_bits(self) int
Returns:

the number of bits covered by the box

get_n_qubits(self) int
Returns:

the number of qubits covered by the box

get_resource_data(self) pytket.circuit.ResourceData
Returns:

the associated resource data

class pytket.circuit.BarrierOp

Barrier operations.

__init__(self, signature: collections.abc.Sequence[pytket.circuit.EdgeType], data: str) None

Construct BarrierOp with signature and additional data string :param signature: signature for the op :param data: additional string stored in the op

property data

Get data from BarrierOp

class pytket.circuit.MetaOp

Meta operation, such as input or output vertices.

__init__(self, type: pytket.circuit.OpType, signature: collections.abc.Sequence[pytket.circuit.EdgeType], data: str) None

Construct MetaOp with optype, signature and additional data string

Parameters:
  • type – type for the meta op

  • signature – signature for the op

  • data – additional string stored in the op

property data

Get data from MetaOp

Named types for convenience

pytket.circuit.named_types.ParamType

Type used for circuit parameters that can either be a floating point number or symbolic

alias of float | Expr

pytket.circuit.named_types.PhasePolynomialDict

Dict type used to define a phase polynomial. A dict that maps Bitstrings(tuples) to ParamType

alias of dict[tuple[bool, …], float | Expr]

pytket.circuit.named_types.PhasePolynomialSequence

Sequence type used to define a phase polynomial. A sequence of Bitstring(sequence) - ParamType pairs

alias of Sequence[tuple[Sequence[bool], float | Expr]]