pytket.circuit

pytket._tket.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

static create(*args, **kwargs)

Overloaded function.

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

Create an Op with given type

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

Create an Op with given type and parameter

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

Create an Op with given type and parameters

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

String representation of op

get_unitary(self: pytket._tket.circuit.Op) numpy.ndarray[numpy.complex128[m, n]]
is_clifford(self: pytket._tket.circuit.Op) 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: pytket._tket.circuit.Op) bool

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

is_gate(self: pytket._tket.circuit.Op) 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: pytket._tket.circuit.Command) 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.

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

Enum for available configurations for CXs upon decompose phase gadgets

Members:

Snake : linear nearest neighbour CX sequence. Linear depth.

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

Tree : Balanced tree: logarithmic depth, harder to route.

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

property name
class pytket.circuit.CircBox

A user-defined operation specified by a Circuit.

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

Construct from a Circuit.

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

the Circuit described by the box

symbol_substitution(self: pytket._tket.circuit.CircBox, symbol_map: dict[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: pytket._tket.circuit.Unitary1qBox, m: numpy.ndarray[numpy.complex128[2, 2]]) None

Construct from a unitary matrix.

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

the Circuit described by the box

get_matrix(self: pytket._tket.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._tket.circuit.Unitary2qBox, m: numpy.ndarray[numpy.complex128[4, 4]], basis: pytket._tket.circuit.BasisOrder = <BasisOrder.ilo: 0>) 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._tket.circuit.Unitary2qBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_matrix(self: pytket._tket.circuit.Unitary2qBox) numpy.ndarray[numpy.complex128[4, 4]]
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: pytket._tket.circuit.Unitary3qBox, m: numpy.ndarray[numpy.complex128[m, n]], basis: pytket._tket.circuit.BasisOrder = <BasisOrder.ilo: 0>) 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._tket.circuit.Unitary3qBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_matrix(self: pytket._tket.circuit.Unitary3qBox) numpy.ndarray[numpy.complex128[8, 8]]
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._tket.circuit.ExpBox, A: numpy.ndarray[numpy.complex128[4, 4]], t: float, basis: pytket._tket.circuit.BasisOrder = <BasisOrder.ilo: 0>) 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._tket.circuit.ExpBox) pytket._tket.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._tket.circuit.PauliExpBox, paulis: Sequence[pytket._tket.pauli.Pauli], t: typing.Union[sympy.Expr, float], cx_config_type: pytket._tket.circuit.CXConfigType = <CXConfigType.Tree: 1>) 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._tket.circuit.PauliExpBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self: pytket._tket.circuit.PauliExpBox) pytket._tket.circuit.CXConfigType
Returns:

decomposition method

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

the corresponding list of Pauli s

get_phase(self: pytket._tket.circuit.PauliExpBox) 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: pytket._tket.circuit.PauliExpPairBox, paulis0: Sequence[pytket._tket.pauli.Pauli], t0: typing.Union[sympy.Expr, float], paulis1: Sequence[pytket._tket.pauli.Pauli], t1: typing.Union[sympy.Expr, float], cx_config_type: pytket._tket.circuit.CXConfigType = <CXConfigType.Tree: 1>) 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._tket.circuit.PauliExpPairBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self: pytket._tket.circuit.PauliExpPairBox) pytket._tket.circuit.CXConfigType
Returns:

decomposition method

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

A tuple containing the two corresponding lists of Pauli s

get_phase_pair(self: pytket._tket.circuit.PauliExpPairBox) 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: pytket._tket.circuit.PauliExpCommutingSetBox, pauli_gadgets: Sequence[tuple[Sequence[pytket._tket.pauli.Pauli], typing.Union[sympy.Expr, float]]], cx_config_type: pytket._tket.circuit.CXConfigType = <CXConfigType.Tree: 1>) 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._tket.circuit.PauliExpCommutingSetBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self: pytket._tket.circuit.PauliExpCommutingSetBox) pytket._tket.circuit.CXConfigType
Returns:

decomposition method

get_paulis(self: pytket._tket.circuit.PauliExpCommutingSetBox) list[tuple[list[pytket._tket.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.

__init__(self: pytket._tket.circuit.TermSequenceBox, pauli_gadgets: Sequence[tuple[Sequence[pytket._tket.pauli.Pauli], typing.Union[sympy.Expr, float]]], synthesis_strategy: pytket._tket.transform.PauliSynthStrat = <PauliSynthStrat.Sets: 2>, partitioning_strategy: pytket._tket.partition.PauliPartitionStrat = <PauliPartitionStrat.CommutingSets: 1>, graph_colouring: pytket._tket.partition.GraphColourMethod = <GraphColourMethod.Lazy: 0>, cx_config_type: pytket._tket.circuit.CXConfigType = <CXConfigType.Tree: 1>, 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.

get_circuit(self: pytket._tket.circuit.TermSequenceBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_cx_config(self: pytket._tket.circuit.TermSequenceBox) pytket._tket.circuit.CXConfigType
Returns:

cx decomposition method

get_depth_weight(self: pytket._tket.circuit.TermSequenceBox) float
Returns:

depth tuning parameter

get_graph_colouring_method(self: pytket._tket.circuit.TermSequenceBox) pytket._tket.partition.GraphColourMethod
Returns:

graph colouring method

get_partition_strategy(self: pytket._tket.circuit.TermSequenceBox) pytket._tket.partition.PauliPartitionStrat
Returns:

partitioning strategy

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

the corresponding list of Pauli gadgets

get_synthesis_strategy(self: pytket._tket.circuit.TermSequenceBox) pytket._tket.transform.PauliSynthStrat
Returns:

synthesis strategy

class pytket.circuit.ToffoliBoxSynthStrat

Enum strategies for synthesising ToffoliBoxes

Members:

Matching : Use multiplexors to perform parallel swaps on hypercubes

Cycle : Use CnX gates to perform transpositions

property name
class pytket.circuit.ToffoliBox

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

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.circuit.ToffoliBox, permutation: Sequence[tuple[Sequence[bool], Sequence[bool]]], strat: pytket._tket.circuit.ToffoliBoxSynthStrat, rotation_axis: pytket._tket.circuit.OpType = <OpType.Ry: 35>) -> 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: pytket._tket.circuit.ToffoliBox, permutation: Sequence[tuple[Sequence[bool], Sequence[bool]]], rotation_axis: pytket._tket.circuit.OpType = <OpType.Ry: 35>) -> 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: pytket._tket.circuit.ToffoliBox, n_qubits: int, permutation: Sequence[tuple[Sequence[bool], Sequence[bool]]], rotation_axis: pytket._tket.circuit.OpType = <OpType.Ry: 35>) -> None

Constructor for backward compatibility. Subject to deprecation.

  1. __init__(self: pytket._tket.circuit.ToffoliBox, permutation: dict[tuple[bool, …], Sequence[bool]], strat: pytket._tket.circuit.ToffoliBoxSynthStrat, rotation_axis: pytket._tket.circuit.OpType = <OpType.Ry: 35>) -> 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: pytket._tket.circuit.ToffoliBox, permutation: dict[tuple[bool, …], Sequence[bool]], rotation_axis: pytket._tket.circuit.OpType = <OpType.Ry: 35>) -> 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: pytket._tket.circuit.ToffoliBox, n_qubits: int, permutation: dict[tuple[bool, …], Sequence[bool]], rotation_axis: pytket._tket.circuit.OpType = <OpType.Ry: 35>) -> None

Constructor for backward compatibility. Subject to deprecation.

get_circuit(self: pytket._tket.circuit.ToffoliBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_permutation(self: pytket._tket.circuit.ToffoliBox) dict[tuple, tuple]
Returns:

the permutation

get_rotation_axis(self: pytket._tket.circuit.ToffoliBox) pytket._tket.circuit.OpType
Returns:

the rotation axis

get_strat(self: pytket._tket.circuit.ToffoliBox) pytket._tket.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__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.circuit.QControlBox, op: pytket._tket.circuit.Op, n_controls: int = 1, control_state: 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: pytket._tket.circuit.QControlBox, op: pytket._tket.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: pytket._tket.circuit.QControlBox, op: pytket._tket.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._tket.circuit.QControlBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_control_state(self: pytket._tket.circuit.QControlBox) int
Returns:

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

get_control_state_bits(self: pytket._tket.circuit.QControlBox) list[bool]
Returns:

the control state as a bit vector

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

the number of control qubits

get_op(self: pytket._tket.circuit.QControlBox) pytket._tket.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._tket.circuit.Circuit, args: Sequence[sympy.Symbol]) pytket._tket.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

static from_dict(arg0: dict) pytket._tket.circuit.CustomGateDef

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

to_dict(self: pytket._tket.circuit.CustomGateDef) 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._tket.circuit.CustomGate) pytket._tket.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._tket.circuit.ClassicalExpBox, arg0: pytket._tket.circuit.ClassicalExpBox) bool

Check whether two ClassicalExpBox are equal in content

get_exp(self: pytket._tket.circuit.ClassicalExpBox) pytket.circuit.logic_exp.LogicExp
Returns:

the classical expression

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

the number of pure inputs to the box.

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

the number of inputs/outputs to the box.

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

the number of pure outputs from the box.

class pytket.circuit.PhasePolyBox

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

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.circuit.PhasePolyBox, n_qubits: int, qubit_indices: dict[pytket._tket.unit_id.Qubit, int], phase_polynomial: dict[tuple[bool, …], typing.Union[sympy.Expr, float]], linear_transformation: numpy.ndarray[bool[m, n]]) -> 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: pytket._tket.circuit.PhasePolyBox, n_qubits: int, qubit_indices: dict[pytket._tket.unit_id.Qubit, int], phase_polynomial: Sequence[tuple[Sequence[bool], typing.Union[sympy.Expr, float]]], linear_transformation: numpy.ndarray[bool[m, n]]) -> 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: pytket._tket.circuit.PhasePolyBox, circuit: pytket._tket.circuit.Circuit) -> None

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

get_circuit(self: pytket._tket.circuit.PhasePolyBox) pytket._tket.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: pytket._tket.circuit.ProjectorAssertionBox, m: numpy.ndarray[numpy.complex128[m, n]], basis: pytket._tket.circuit.BasisOrder = <BasisOrder.ilo: 0>) 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._tket.circuit.ProjectorAssertionBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_matrix(self: pytket._tket.circuit.ProjectorAssertionBox) numpy.ndarray[numpy.complex128[m, n]]
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__(*args, **kwargs)

Overloaded function.

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

Construct from a list of Pauli stabilisers.

Parameters:

stabilisers – The list of Pauli stabilisers

  1. __init__(self: pytket._tket.circuit.StabiliserAssertionBox, stabilisers: 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._tket.circuit.StabiliserAssertionBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_stabilisers(self: pytket._tket.circuit.StabiliserAssertionBox) list[pytket._tket.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: pytket._tket.circuit.WASMOp, num_bits: int, num_w: int, n_inputs: Sequence[int], n_outputs: 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: pytket._tket.circuit.MultiBitOp, op: pytket._tket.circuit.ClassicalEvalOp, multiplier: int) None

Construct from a basic operation and a multiplier.

property basic_op

Underlying bitwise op.

class pytket.circuit.SetBitsOp

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

__init__(self: pytket._tket.circuit.SetBitsOp, values: 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: pytket._tket.circuit.RangePredicateOp, 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__(*args, **kwargs)

Overloaded function.

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

Construct from a list of bitstring-Op spairs

Parameters:

bitstring_to_op_list – List of bitstring-Op spairs

  1. __init__(self: pytket._tket.circuit.MultiplexorBox, op_map: dict[tuple[bool, …], pytket._tket.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: pytket._tket.circuit.MultiplexorBox) list[tuple[list[bool], pytket._tket.circuit.Op]]
Returns:

the underlying bistring-op pairs

get_circuit(self: pytket._tket.circuit.MultiplexorBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_op_map(self: pytket._tket.circuit.MultiplexorBox) dict[tuple[bool, ...], pytket._tket.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__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.circuit.MultiplexedRotationBox, bistring_to_op_list: Sequence[tuple[Sequence[bool], pytket._tket.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: pytket._tket.circuit.MultiplexedRotationBox, op_map: dict[tuple[bool, …], pytket._tket.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: pytket._tket.circuit.MultiplexedRotationBox, angles: Sequence[float], axis: pytket._tket.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: pytket._tket.circuit.MultiplexedRotationBox) list[tuple[list[bool], pytket._tket.circuit.Op]]
Returns:

the underlying bistring-op pairs

get_circuit(self: pytket._tket.circuit.MultiplexedRotationBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_op_map(self: pytket._tket.circuit.MultiplexedRotationBox) dict[tuple[bool, ...], pytket._tket.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__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.circuit.MultiplexedU2Box, bistring_to_op_list: Sequence[tuple[Sequence[bool], pytket._tket.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: pytket._tket.circuit.MultiplexedU2Box, op_map: dict[tuple[bool, …], pytket._tket.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: pytket._tket.circuit.MultiplexedU2Box) list[tuple[list[bool], pytket._tket.circuit.Op]]
Returns:

the underlying bistring-op pairs

get_circuit(self: pytket._tket.circuit.MultiplexedU2Box) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_impl_diag(self: pytket._tket.circuit.MultiplexedU2Box) bool
Returns:

flag indicating whether to implement the final diagonal gate.

get_op_map(self: pytket._tket.circuit.MultiplexedU2Box) dict[tuple[bool, ...], pytket._tket.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__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.circuit.MultiplexedTensoredU2Box, bistring_to_op_list: Sequence[tuple[Sequence[bool], Sequence[pytket._tket.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: pytket._tket.circuit.MultiplexedTensoredU2Box, op_map: dict[tuple[bool, …], Sequence[pytket._tket.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: pytket._tket.circuit.MultiplexedTensoredU2Box) list[tuple[list[bool], list[pytket._tket.circuit.Op]]]
Returns:

the underlying bistring-op pairs

get_circuit(self: pytket._tket.circuit.MultiplexedTensoredU2Box) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_op_map(self: pytket._tket.circuit.MultiplexedTensoredU2Box) dict[tuple[bool, ...], list[pytket._tket.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: pytket._tket.circuit.StatePreparationBox, statevector: numpy.ndarray[numpy.complex128[m, 1]], 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._tket.circuit.StatePreparationBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_statevector(self: pytket._tket.circuit.StatePreparationBox) numpy.ndarray[numpy.complex128[m, 1]]
Returns:

the statevector

is_inverse(self: pytket._tket.circuit.StatePreparationBox) bool
Returns:

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

with_initial_reset(self: pytket._tket.circuit.StatePreparationBox) 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: pytket._tket.circuit.DiagonalBox, diagonal: numpy.ndarray[numpy.complex128[m, 1]], 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._tket.circuit.DiagonalBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_diagonal(self: pytket._tket.circuit.DiagonalBox) numpy.ndarray[numpy.complex128[m, 1]]
Returns:

the statevector

is_upper_triangle(self: pytket._tket.circuit.DiagonalBox) bool
Returns:

the upper_triangle flag

class pytket.circuit.ConjugationBox

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

__init__(self: pytket._tket.circuit.ConjugationBox, compute: pytket._tket.circuit.Op, action: pytket._tket.circuit.Op, uncompute: pytket._tket.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._tket.circuit.ConjugationBox) pytket._tket.circuit.Op
Returns:

the action operation

get_circuit(self: pytket._tket.circuit.ConjugationBox) pytket._tket.circuit.Circuit
Returns:

the Circuit described by the box

get_compute(self: pytket._tket.circuit.ConjugationBox) pytket._tket.circuit.Op
Returns:

the compute operation

get_uncompute(self: pytket._tket.circuit.ConjugationBox) pytket._tket.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: pytket._tket.circuit.ResourceBounds, min: int, max: int) None

Constructs a ResourceBounds object.

Parameters:
  • min – minimum value

  • max – maximum value

get_max(self: pytket._tket.circuit.ResourceBounds) int
Returns:

the maximum value

get_min(self: pytket._tket.circuit.ResourceBounds) 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: pytket._tket.circuit.ResourceData, op_type_count: dict[pytket._tket.circuit.OpType, pytket._tket.circuit.ResourceBounds], gate_depth: pytket._tket.circuit.ResourceBounds, op_type_depth: dict[pytket._tket.circuit.OpType, pytket._tket.circuit.ResourceBounds], two_qubit_gate_depth: pytket._tket.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: pytket._tket.circuit.ResourceData) str
get_gate_depth(self: pytket._tket.circuit.ResourceData) pytket._tket.circuit.ResourceBounds
Returns:

bounds on the gate depth

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

bounds on the op type count

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

bounds on the op type depth

get_two_qubit_gate_depth(self: pytket._tket.circuit.ResourceData) pytket._tket.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: pytket._tket.circuit.DummyBox, n_qubits: int, n_bits: int, resource_data: pytket._tket.circuit.ResourceData) None

Construct a new instance from some resource data.

get_n_bits(self: pytket._tket.circuit.DummyBox) int
Returns:

the number of bits covered by the box

get_n_qubits(self: pytket._tket.circuit.DummyBox) int
Returns:

the number of qubits covered by the box

get_resource_data(self: pytket._tket.circuit.DummyBox) pytket._tket.circuit.ResourceData
Returns:

the associated resource data