pytket.circuit
pytket.circuit#
Classes:
- 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.
create(arg0: pytket.circuit.OpType) -> pytket.circuit.Op
Create an
Op
with given typecreate(arg0: pytket.circuit.OpType, arg1: Expression) -> pytket.circuit.Op
Create an
Op
with given type and parametercreate(arg0: pytket.circuit.OpType, arg1: List[Expression]) -> pytket.circuit.Op
Create an
Op
with given type and parameters
- free_symbols(self: pytket.circuit.Op) Set[Symbol] #
- 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_clifford_type(self: pytket.circuit.Op) bool #
- is_gate(self: pytket.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.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
orUnitType.bit
- class pytket.circuit.Qubit#
A handle to a qubit
- __init__(*args, **kwargs)#
Overloaded function.
__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
__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
__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
__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
__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.
__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
__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
__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
__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
__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.
__eq__(self: pytket.circuit.UnitID, arg0: pytket.circuit.UnitID) -> bool
__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.
__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
__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
__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
__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
__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
.- get_circuit(self: pytket.circuit.CircBox) tket::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) tket::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) tket::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.Unitary3qBox#
A user-defined three-qubit operation specified by a unitary matrix.
- __init__(self: pytket.circuit.Unitary3qBox, m: numpy.ndarray[numpy.complex128[m, n]], 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.Unitary3qBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_matrix(self: pytket.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.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) tket::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) tket::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.ToffoliBox#
An operation that constructs a circuit to implement the specified permutation of classical basis states.
- __init__(self: pytket.circuit.ToffoliBox, n_qubits: int, permutation: Dict[List[bool], List[bool]]) None #
Construct from a permutation of basis states.
- get_circuit(self: pytket.circuit.ToffoliBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- 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) tket::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: tket::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
- static from_dict(arg0: json) pytket.circuit.CustomGateDef #
Construct Circuit instance from JSON serializable dictionary representation of the Circuit.
- to_dict(self: pytket.circuit.CustomGateDef) json #
- 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.CustomGate) tket::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.PhasePolyBox#
Box encapsulating any Circuit made up of CNOT and RZ as a phase polynomial + linear transformation
- __init__(*args, **kwargs)#
Overloaded function.
__init__(self: pytket.circuit.PhasePolyBox, n_qubits: int, qubit_indices: Dict[pytket.circuit.Qubit, int], phase_polynomial: Dict[List[bool], Expression], 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)
__init__(self: pytket.circuit.PhasePolyBox, circuit: tket::Circuit) -> None
Construct a PhasePolyBox from a given circuit containing only Rz and CX gates.
- get_circuit(self: pytket.circuit.PhasePolyBox) tket::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 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.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)
- get_circuit(self: pytket.circuit.ProjectorAssertionBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_matrix(self: pytket.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.
__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
__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
- get_circuit(self: pytket.circuit.StabiliserAssertionBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_stabilisers(self: pytket.circuit.StabiliserAssertionBox) List[pytket.circuit.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.circuit.WASMOp, num_bits: int, num_w: int, n_inputs: List[int], n_outputs: List[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.MultiplexorBox#
A user-defined multiplexor (i.e. uniformly controlled operations) specified by a map from bitstrings to :py:class:`Op`s
- __init__(self: pytket.circuit.MultiplexorBox, op_map: Dict[List[bool], pytket.circuit.Op]) None #
Construct from a map from bitstrings to :py:class:`Op`s
- Parameters
op_map – Map from bitstrings to :py:class:`Op`s
- get_circuit(self: pytket.circuit.MultiplexorBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_op_map(self: pytket.circuit.MultiplexorBox) 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 :py:class:`Op`s
- __init__(*args, **kwargs)#
Overloaded function.
__init__(self: pytket.circuit.MultiplexedRotationBox, op_map: Dict[List[bool], pytket.circuit.Op]) -> None
Construct from a map from bitstrings to :py:class:`Op`s.All :py:class:`Op`s must share the same single-qubit rotation type: Rx, Ry, or Rz.
- Parameters
op_map – Map from bitstrings to :py:class:`Op`s
__init__(self: pytket.circuit.MultiplexedRotationBox, angles: List[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
axis –
OpType.Rx
,OpType.Ry
orOpType.Rz
- get_circuit(self: pytket.circuit.MultiplexedRotationBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_op_map(self: pytket.circuit.MultiplexedRotationBox) 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 :py:class:`Op`s
- __init__(self: pytket.circuit.MultiplexedU2Box, op_map: Dict[List[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 :py:class:`Unitary1qBox
.- Parameters
op_map – Map from bitstrings to :py:class:`Op`s
impl_diag – Whether to implement the final diagonal gate, default to True.
- get_circuit(self: pytket.circuit.MultiplexedU2Box) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_impl_diag(self: pytket.circuit.MultiplexedU2Box) bool #
- Returns
flag indicating whether to implement the final diagonal gate.
- get_op_map(self: pytket.circuit.MultiplexedU2Box) Dict[tuple, 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
- __init__(self: pytket.circuit.StatePreparationBox, statevector: numpy.ndarray[numpy.complex128[m, 1]], is_inverse: bool = False) None #
- Parameters
is_inverse – whether to implement the dagger of the state preparation circuit, default to false
- get_circuit(self: pytket.circuit.StatePreparationBox) tket::Circuit #
- Returns
the
Circuit
described by the box
- get_statevector(self: pytket.circuit.StatePreparationBox) numpy.ndarray[numpy.complex128[m, 1]] #
- Returns
the statevector
- is_inverse(self: pytket.circuit.StatePreparationBox) bool #
- Returns
flag indicating whether to implement the dagger of the state preparation circuit