pytket.circuit.Circuit

Circuit objects provide an abstraction of quantum circuits. They consist of a set of qubits/quantum wires and a collection of operations applied to them in a given order. These wires have open inputs and outputs, rather than assuming any fixed input state.

See the Pytket User Manual for a step-by-step tutorial on constructing circuits.

Many of the Circuit methods described below append a gate or box to the end of the circuit. Where kwargs are indicated in these methods, the following keyword arguments are supported:

  • opgroup (str): name of the associated operation group, if any

  • condition (Bit, BitLogicExp or ConstPredicate): classical condition for applying operation

  • condition_bits (list of Bit): classical bits on which to condition operation

  • condition_value (int): required value of condition bits (little-endian), defaulting to all-1s if not specified

(Thus there are two ways to express classical conditions: either using a general condition, or using the pair condition_bits and condition_value to condition on a specified set of bit values.)

class pytket.circuit.Circuit

Encapsulates a quantum circuit using a DAG representation.

>>> from pytket import Circuit
>>> c = Circuit(4) # Create a circuit with 4 qubits
>>> c.H(0) # Apply a gate to qubit 0
>>> c.Rx(0.5,1) # Angles of rotation are expressed in half-turns (i.e. 0.5 means PI/2)
>>> c.Measure(1)
CCX(*args, **kwargs)

Overloaded function.

  1. CCX(self: pytket.circuit.Circuit, control_0: int, control_1: int, target: int, **kwargs) -> pytket.circuit.Circuit

Appends a CCX gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CCX(self: pytket.circuit.Circuit, control_0: pytket.circuit.Qubit, control_1: pytket.circuit.Qubit, target: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CCX gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CH(*args, **kwargs)

Overloaded function.

  1. CH(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CH gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CH(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CH gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CRx(*args, **kwargs)

Overloaded function.

  1. CRx(self: pytket.circuit.Circuit, angle: Expression, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CRx gate with a symbolic angle (specified in half-turns) on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CRx(self: pytket.circuit.Circuit, angle: Expression, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CRx gate with a symbolic angle (specified in half-turns) on the wires for the specified control and target qubits.

Returns

the new Circuit

CRy(*args, **kwargs)

Overloaded function.

  1. CRy(self: pytket.circuit.Circuit, angle: Expression, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CRy gate with a symbolic angle (specified in half-turns) on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CRy(self: pytket.circuit.Circuit, angle: Expression, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CRy gate with a symbolic angle (specified in half-turns) on the wires for the specified control and target qubits.

Returns

the new Circuit

CRz(*args, **kwargs)

Overloaded function.

  1. CRz(self: pytket.circuit.Circuit, angle: Expression, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CRz gate with a symbolic angle (specified in half-turns) on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CRz(self: pytket.circuit.Circuit, angle: Expression, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CRz gate with a symbolic angle (specified in half-turns) on the wires for the specified control and target qubits.

Returns

the new Circuit

CSWAP(*args, **kwargs)

Overloaded function.

  1. CSWAP(self: pytket.circuit.Circuit, control: int, target_0: int, target_1: int, **kwargs) -> pytket.circuit.Circuit

Appends a CSWAP gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CSWAP(self: pytket.circuit.Circuit, control: pytket.circuit.Qubit, target_0: pytket.circuit.Qubit, target_1: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CSWAP gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CSX(*args, **kwargs)

Overloaded function.

  1. CSX(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CSX gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CSX(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CSX gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CSXdg(*args, **kwargs)

Overloaded function.

  1. CSXdg(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CSXdg gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CSXdg(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CSXdg gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CV(*args, **kwargs)

Overloaded function.

  1. CV(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CV gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CV(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CV gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CVdg(*args, **kwargs)

Overloaded function.

  1. CVdg(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CVdg gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CVdg(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CVdg gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CX(*args, **kwargs)

Overloaded function.

  1. CX(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CX gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CX(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CX gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CY(*args, **kwargs)

Overloaded function.

  1. CY(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CY gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CY(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CY gate on the wires for the specified control and target qubits.

Returns

the new Circuit

CZ(*args, **kwargs)

Overloaded function.

  1. CZ(self: pytket.circuit.Circuit, control_qubit: int, target_qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a CZ gate on the wires for the specified control and target qubits.

Returns

the new Circuit

  1. CZ(self: pytket.circuit.Circuit, control_qubit: pytket.circuit.Qubit, target_qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a CZ gate on the wires for the specified control and target qubits.

Returns

the new Circuit

ECR(*args, **kwargs)

Overloaded function.

  1. ECR(self: pytket.circuit.Circuit, qubit_0: int, qubit_1: int, **kwargs) -> pytket.circuit.Circuit

Appends an ECR gate on the wires for the specified qubits.

Returns

the new Circuit

  1. ECR(self: pytket.circuit.Circuit, qubit_0: pytket.circuit.Qubit, qubit_1: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an ECR gate on the wires for the specified qubits.

Returns

the new Circuit

H(*args, **kwargs)

Overloaded function.

  1. H(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a Hadamard gate.

Returns

the new Circuit

  1. H(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a Hadamard gate.

Returns

the new Circuit

Measure(*args, **kwargs)

Overloaded function.

  1. Measure(self: pytket.circuit.Circuit, qubit: int, bit_index: int, **kwargs) -> pytket.circuit.Circuit

Appends a single-qubit measurement in the computational (Z) basis.

Returns

the new Circuit

  1. Measure(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, bit: pytket.circuit.Bit, **kwargs) -> pytket.circuit.Circuit

Appends a single-qubit measurement in the computational (Z) basis.

Returns

the new Circuit

Rx(*args, **kwargs)

Overloaded function.

  1. Rx(self: pytket.circuit.Circuit, angle: Expression, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends an Rx gate with a possibly symbolic angle (specified in half-turns).

Returns

the new Circuit

  1. Rx(self: pytket.circuit.Circuit, angle: Expression, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an Rx gate with a possibly symbolic angle (specified in half-turns).

Returns

the new Circuit

Ry(*args, **kwargs)

Overloaded function.

  1. Ry(self: pytket.circuit.Circuit, angle: Expression, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends an Ry gate with a possibly symbolic angle (specified in half-turns).

Returns

the new Circuit

  1. Ry(self: pytket.circuit.Circuit, angle: Expression, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an Ry gate with a possibly symbolic angle (specified in half-turns).

Returns

the new Circuit

Rz(*args, **kwargs)

Overloaded function.

  1. Rz(self: pytket.circuit.Circuit, angle: Expression, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends an Rz gate with a possibly symbolic angle (specified in half-turns).

Returns

the new Circuit

  1. Rz(self: pytket.circuit.Circuit, angle: Expression, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an Rz gate with a possibly symbolic angle (specified in half-turns).

Returns

the new Circuit

S(*args, **kwargs)

Overloaded function.

  1. S(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends an S gate (equivalent to U1(0.5,-)).

Returns

the new Circuit

  1. S(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an S gate (equivalent to Rz(0.5,-)).

Returns

the new Circuit

SWAP(*args, **kwargs)

Overloaded function.

  1. SWAP(self: pytket.circuit.Circuit, qubit_0: int, qubit_1: int, **kwargs) -> pytket.circuit.Circuit

Appends a SWAP gate on the wires for the specified qubits.

Returns

the new Circuit

  1. SWAP(self: pytket.circuit.Circuit, qubit_0: pytket.circuit.Qubit, qubit_1: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a SWAP gate on the wires for the specified qubits.

Returns

the new Circuit

SX(*args, **kwargs)

Overloaded function.

  1. SX(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a SX gate (equivalent to Rx(0.5,-) up to a 0.25 global phase).

Returns

the new Circuit

  1. SX(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a SX gate (equivalent to Rx(0.5,-) up to a 0.25 global phase).

Returns

the new Circuit

SXdg(*args, **kwargs)

Overloaded function.

  1. SXdg(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a SXdg gate (equivalent to Rx(-0.5,-) up to a -0.25 global phase).

Returns

the new Circuit

  1. SXdg(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a SXdg gate (equivalent to Rx(-0.5,-) up to a -0.25 global phase).

Returns

the new Circuit

Sdg(*args, **kwargs)

Overloaded function.

  1. Sdg(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends an S-dagger gate (equivalent to U1(-0.5,-)).

Returns

the new Circuit

  1. Sdg(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an S-dagger gate (equivalent to Rz(-0.5,-)).

Returns

the new Circuit

T(*args, **kwargs)

Overloaded function.

  1. T(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a T gate (equivalent to U1(0.25,-)).

Returns

the new Circuit

  1. T(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a T gate (equivalent to Rz(0.25,-)).

Returns

the new Circuit

Tdg(*args, **kwargs)

Overloaded function.

  1. Tdg(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a T-dagger gate (equivalent to U1(-0.25,-)).

Returns

the new Circuit

  1. Tdg(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a T-dagger gate (equivalent to Rz(-0.25,-)).

Returns

the new Circuit

V(*args, **kwargs)

Overloaded function.

  1. V(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a V gate (equivalent to Rx(0.5,-)).

Returns

the new Circuit

  1. V(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a V gate (equivalent to Rx(0.5,-)).

Returns

the new Circuit

Vdg(*args, **kwargs)

Overloaded function.

  1. Vdg(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Appends a V-dagger gate (equivalent to Rx(-0.5,-)).

Returns

the new Circuit

  1. Vdg(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a V-dagger gate (equivalent to Rx(-0.5,-)).

Returns

the new Circuit

X(*args, **kwargs)

Overloaded function.

  1. X(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Returns

the new Circuit

  1. X(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends an X gate.

Returns

the new Circuit

XXPhase(*args, **kwargs)

Overloaded function.

  1. XXPhase(self: pytket.circuit.Circuit, angle: Expression, qubit0: int, qubit1: int, **kwargs) -> pytket.circuit.Circuit

Appends a XX gate with a symbolic angle (specified in half-turns) on the wires for the specified two qubits.

Returns

the new Circuit

  1. XXPhase(self: pytket.circuit.Circuit, qubit0: Expression, qubit1: pytket.circuit.Qubit, angle: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a XX gate with a symbolic angle (specified in half-turns) on the wires for the specified two qubits.

Returns

the new Circuit

XXPhase3(*args, **kwargs)

Overloaded function.

  1. XXPhase3(self: pytket.circuit.Circuit, angle: Expression, qubit0: int, qubit1: int, qubit2: int, **kwargs) -> pytket.circuit.Circuit

Appends a 3-qubit XX gate with a symbolic angle (specified in half-turns) on the wires for the specified three qubits.

Returns

the new Circuit

  1. XXPhase3(self: pytket.circuit.Circuit, angle: Expression, qubit0: pytket.circuit.Qubit, qubit1: pytket.circuit.Qubit, qubit2: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a 3-qubit XX gate with a symbolic angle (specified in half-turns) on the wires for the specified three qubits.

Returns

the new Circuit

Y(*args, **kwargs)

Overloaded function.

  1. Y(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Returns

the new Circuit

  1. Y(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a Y gate.

Returns

the new Circuit

YYPhase(*args, **kwargs)

Overloaded function.

  1. YYPhase(self: pytket.circuit.Circuit, angle: Expression, qubit0: int, qubit1: int, **kwargs) -> pytket.circuit.Circuit

Appends a YY gate with a symbolic angle (specified in half-turns) on the wires for the specified two qubits.

Returns

the new Circuit

  1. YYPhase(self: pytket.circuit.Circuit, qubit0: Expression, qubit1: pytket.circuit.Qubit, angle: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a YY gate with a symbolic angle (specified in half-turns) on the wires for the specified two qubits.

Returns

the new Circuit

Z(*args, **kwargs)

Overloaded function.

  1. Z(self: pytket.circuit.Circuit, qubit: int, **kwargs) -> pytket.circuit.Circuit

Returns

the new Circuit

  1. Z(self: pytket.circuit.Circuit, qubit: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a Z gate.

Returns

the new Circuit

ZZPhase(*args, **kwargs)

Overloaded function.

  1. ZZPhase(self: pytket.circuit.Circuit, angle: Expression, qubit0: int, qubit1: int, **kwargs) -> pytket.circuit.Circuit

Appends a ZZ gate with a symbolic angle (specified in half-turns) on the wires for the specified two qubits.

Returns

the new Circuit

  1. ZZPhase(self: pytket.circuit.Circuit, qubit0: Expression, qubit1: pytket.circuit.Qubit, angle: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Appends a ZZ gate with a symbolic angle (specified in half-turns) on the wires for the specified two qubits.

Returns

the new Circuit

__eq__(self: pytket.circuit.Circuit, arg0: pytket.circuit.Circuit) bool
__getstate__(self: object) tuple
__init__(*args, **kwargs)

Overloaded function.

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

Constructs a circuit with a completely empty DAG.

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

Constructs a named circuit with a completely empty DAG.

Parameters

name – name for the circuit

  1. __init__(self: pytket.circuit.Circuit, n_qubits: int, name: Optional[str] = None) -> None

Constructs a circuit with a given number of qubits/blank wires.

>>> c = Circuit()
>>> c.add_blank_wires(3)

is equivalent to

>>> c = Circuit(3)
Parameters
  • n_qubits – The number of qubits in the circuit

  • name – Optional name for the circuit.

  1. __init__(self: pytket.circuit.Circuit, n_qubits: int, n_bits: int, name: Optional[str] = None) -> None

Constructs a circuit with a given number of quantum and classical bits

Parameters
  • n_qubits – The number of qubits in the circuit

  • c_bits – The number of classical bits in the circuit

  • name – Optional name for the circuit.

__iter__(self: pytket.circuit.Circuit) Iterator

Iterate through the circuit, a Command at a time.

__mul__(self: pytket.circuit.Circuit, arg0: pytket.circuit.Circuit) pytket.circuit.Circuit

Creates a new Circuit, corresponding to the parallel composition of the given Circuits. This will fail if the circuits share qubits/bits with the same ids.

__repr__(self: pytket.circuit.Circuit) str
__rshift__(self: pytket.circuit.Circuit, arg0: pytket.circuit.Circuit) pytket.circuit.Circuit

Creates a new Circuit, corresponding to the sequential composition of the given Circuits. Any qubits/bits with the same ids will be unified. Any ids without a match will be added in parallel.

__setstate__(self: pytket.circuit.Circuit, arg0: tuple) None
__str__(self: pytket.circuit.Circuit) str
add_assertion(*args, **kwargs)

Overloaded function.

  1. add_assertion(self: pytket.circuit.Circuit, box: tket::ProjectorAssertionBox, qubits: List[int], ancilla: Optional[int] = None, name: Optional[str] = None) -> capsule

Append a ProjectorAssertionBox to the circuit.

Parameters
  • box – ProjectorAssertionBox to append

  • qubits – indices of target qubits

  • ancilla – index of ancilla qubit

  • name – name used to identify this assertion

Returns

the new Circuit

  1. add_assertion(self: pytket.circuit.Circuit, box: tket::ProjectorAssertionBox, qubits: List[pytket.circuit.Qubit], ancilla: Optional[pytket.circuit.Qubit] = None, name: Optional[str] = None) -> capsule

Append a ProjectorAssertionBox to the circuit.

Parameters
  • box – ProjectorAssertionBox to append

  • qubits – target qubits

  • ancilla – ancilla qubit

  • name – name used to identify this assertion

Returns

the new Circuit

  1. add_assertion(self: pytket.circuit.Circuit, box: tket::StabiliserAssertionBox, qubits: List[int], ancilla: int, name: Optional[str] = None) -> capsule

Append a StabiliserAssertionBox to the circuit.

Parameters
  • box – StabiliserAssertionBox to append

  • qubits – indices of target qubits

  • ancilla – index of ancilla qubit

  • name – name used to identify this assertion

Returns

the new Circuit

  1. add_assertion(self: pytket.circuit.Circuit, box: tket::StabiliserAssertionBox, qubits: List[pytket.circuit.Qubit], ancilla: pytket.circuit.Qubit, name: Optional[str] = None) -> capsule

Append a StabiliserAssertionBox to the circuit.

Parameters
  • box – StabiliserAssertionBox to append

  • qubits – target qubits

  • ancilla – ancilla qubit

  • name – name used to identify this assertion

Returns

the new Circuit

add_barrier(*args, **kwargs)

Overloaded function.

  1. add_barrier(self: pytket.circuit.Circuit, qubits: List[int], bits: List[int] = []) -> pytket.circuit.Circuit

Append a Barrier on the given units

Returns

the new Circuit

  1. add_barrier(self: pytket.circuit.Circuit, units: List[pytket.circuit.UnitID]) -> pytket.circuit.Circuit

Append a Barrier on the given units

Returns

the new Circuit

add_bit(self: pytket.circuit.Circuit, id: pytket.circuit.Bit, reject_dups: bool = True) None

Constructs a single bit with the given id.

Parameters
  • id – Unique id for the bit

  • reject_dups – Fail if there is already a bit in this circuit with the id. Default to True

add_blank_wires(self: pytket.circuit.Circuit, number: int) None

Adds a number of new qubits to the circuit. These will be added to the default register (‘q’) if possible, filling out the unused indices from 0.

Parameters

number – Number of qubits to add

add_c_and(*args, **kwargs)

Overloaded function.

  1. add_c_and(self: pytket.circuit.Circuit, arg0_in: int, arg1_in: int, arg_out: int) -> capsule

Appends a binary AND operation to the end of the circuit.

Parameters
  • arg0_in – first input bit

  • arg1_in – second input bit

  • arg_out – output bit

Returns

the new Circuit

  1. add_c_and(self: pytket.circuit.Circuit, arg0_in: pytket.circuit.Bit, arg1_in: pytket.circuit.Bit, arg_out: pytket.circuit.Bit) -> capsule

See add_c_and().

add_c_and_to_registers(self: pytket.circuit.Circuit, reg0_in: pytket.circuit.BitRegister, reg1_in: pytket.circuit.BitRegister, reg_out: pytket.circuit.BitRegister) pytket.circuit.Circuit

Applies bitwise AND to linear registers.

The operation is applied to the bits with indices 0, 1, 2, … in each register, up to the size of the smallest register.

Parameters
  • reg0_in – first input register

  • reg1_in – second input register

  • reg_out – output register

Returns

the new Circuit

add_c_copybits(*args, **kwargs)

Overloaded function.

  1. add_c_copybits(self: pytket.circuit.Circuit, args_in: List[int], args_out: List[int]) -> capsule

Appends a classical copy operation

Parameters
  • args_in – source bits

  • args_out – destination bits

Returns

the new Circuit

  1. add_c_copybits(self: pytket.circuit.Circuit, args_in: List[pytket.circuit.Bit], args_out: List[pytket.circuit.Bit]) -> capsule

See add_c_copybits().

add_c_modifier(*args, **kwargs)

Overloaded function.

  1. add_c_modifier(self: pytket.circuit.Circuit, values: List[bool], args_in: List[int], arg_inout: int, name: str = ‘ExplicitModifier’) -> capsule

Parameters

name – operation name

Returns

the new Circuit

  1. add_c_modifier(self: pytket.circuit.Circuit, values: List[bool], args_in: List[pytket.circuit.Bit], arg_inout: pytket.circuit.Bit, name: str = ‘ExplicitModifier’) -> capsule

See add_c_modifier().

add_c_not(*args, **kwargs)

Overloaded function.

  1. add_c_not(self: pytket.circuit.Circuit, arg_in: int, arg_out: int) -> capsule

Appends a NOT operation to the end of the circuit.

Parameters
  • arg_in – input bit

  • arg_out – output bit

Returns

the new Circuit

  1. add_c_not(self: pytket.circuit.Circuit, arg_in: pytket.circuit.Bit, arg_out: pytket.circuit.Bit) -> capsule

See add_c_not().

add_c_not_to_registers(self: pytket.circuit.Circuit, reg_in: pytket.circuit.BitRegister, reg_out: pytket.circuit.BitRegister) pytket.circuit.Circuit

Applies bitwise NOT to linear registers.

The operation is applied to the bits with indices 0, 1, 2, … in each register, up to the size of the smallest register.

Parameters
  • reg_in – input register

  • reg_out – name of output register

Returns

the new Circuit

add_c_or(*args, **kwargs)

Overloaded function.

  1. add_c_or(self: pytket.circuit.Circuit, arg0_in: int, arg1_in: int, arg_out: int) -> capsule

Appends a binary OR operation to the end of the circuit.

Parameters
  • arg0_in – first input bit

  • arg1_in – second input bit

  • arg_out – output bit

Returns

the new Circuit

  1. add_c_or(self: pytket.circuit.Circuit, arg0_in: pytket.circuit.Bit, arg1_in: pytket.circuit.Bit, arg_out: pytket.circuit.Bit) -> capsule

See add_c_or().

add_c_or_to_registers(self: pytket.circuit.Circuit, reg0_in: pytket.circuit.BitRegister, reg1_in: pytket.circuit.BitRegister, reg_out: pytket.circuit.BitRegister) pytket.circuit.Circuit

Applies bitwise OR to linear registers.

The operation is applied to the bits with indices 0, 1, 2, … in each register, up to the size of the smallest register.

Parameters
  • reg0_in – first input register

  • reg1_in – second input register

  • reg_out – output register

Returns

the new Circuit

add_c_predicate(*args, **kwargs)

Overloaded function.

  1. add_c_predicate(self: pytket.circuit.Circuit, values: List[bool], args_in: List[int], arg_out: int, name: str = ‘ExplicitPredicate’) -> capsule

Parameters

name – operation name

Returns

the new Circuit

  1. add_c_predicate(self: pytket.circuit.Circuit, values: List[bool], args_in: List[pytket.circuit.Bit], arg_out: pytket.circuit.Bit, name: str = ‘ExplicitPredicate’) -> capsule

See add_c_predicate().

add_c_range_predicate(*args, **kwargs)

Overloaded function.

  1. add_c_range_predicate(self: pytket.circuit.Circuit, minval: int = 0, maxval: int = 4294967295, args_in: List[int], arg_out: int) -> capsule

Appends a range-predicate operation to the end of the circuit.

Parameters
  • minval – lower bound of input in little-endian encoding

  • maxval – upper bound of input in little-endian encoding

  • args_in – input bits

  • arg_out – output bit (distinct from input bits)

Returns

the new Circuit

  1. add_c_range_predicate(self: pytket.circuit.Circuit, minval: int = 0, maxval: int = 4294967295, args_in: List[pytket.circuit.Bit], arg_out: pytket.circuit.Bit) -> capsule

Appends a range-predicate operation to the end of the circuit.

Parameters
  • minval – lower bound of input in little-endian encoding

  • maxval – upper bound of input in little-endian encoding

  • args_in – input bits

  • arg_out – output bit (distinct from input bits)

Returns

the new Circuit

add_c_register(*args, **kwargs)

Overloaded function.

  1. add_c_register(self: pytket.circuit.Circuit, name: str, size: int) -> pytket.circuit.BitRegister

Constructs a new classical register with a given name and number of bits.

Parameters
  • name – Unique readable name for the register

  • size – Number of bits required

Returns

a map from index to the corresponding UnitIDs

  1. add_c_register(self: pytket.circuit.Circuit, register: pytket.circuit.BitRegister) -> pytket.circuit.BitRegister

Adds BitRegister to Circuit

Parameters

register – BitRegister

add_c_setbits(*args, **kwargs)

Overloaded function.

  1. add_c_setbits(self: pytket.circuit.Circuit, values: List[bool], args: List[int]) -> capsule

Appends an operation to set some bit values.

Parameters
  • values – values to set

  • args – bits to set

Returns

the new Circuit

  1. add_c_setbits(self: pytket.circuit.Circuit, values: List[bool], args: List[pytket.circuit.Bit]) -> capsule

See add_c_setbits().

add_c_transform(*args, **kwargs)

Overloaded function.

  1. add_c_transform(self: pytket.circuit.Circuit, values: List[int], args: List[int], name: str = ‘ClassicalTransform’) -> capsule

Appends a purely classical transformation, defined by a table of values, to the end of the circuit.

Parameters
  • values – table of values: bit \(j\) (in little-endian order) of the term indexed by \(sum_i a_i 2^i\) is output \(j\) of the transform applied to inputs \((a_i)\).

  • args – bits to which the transform is applied

  • name – operation name

Returns

the new Circuit

  1. add_c_transform(self: pytket.circuit.Circuit, values: List[int], args: List[pytket.circuit.Bit], name: str = ‘ClassicalTransform’) -> capsule

See add_c_transform().

add_c_xor(*args, **kwargs)

Overloaded function.

  1. add_c_xor(self: pytket.circuit.Circuit, arg0_in: int, arg1_in: int, arg_out: int) -> capsule

Appends a binary XOR operation to the end of the circuit.

Parameters
  • arg0_in – first input bit

  • arg1_in – second input bit

  • arg_out – output bit

Returns

the new Circuit

  1. add_c_xor(self: pytket.circuit.Circuit, arg0_in: pytket.circuit.Bit, arg1_in: pytket.circuit.Bit, arg_out: pytket.circuit.Bit) -> capsule

See add_c_xor().

add_c_xor_to_registers(self: pytket.circuit.Circuit, reg0_in: pytket.circuit.BitRegister, reg1_in: pytket.circuit.BitRegister, reg_out: pytket.circuit.BitRegister) pytket.circuit.Circuit

Applies bitwise XOR to linear registers.

The operation is applied to the bits with indices 0, 1, 2, … in each register, up to the size of the smallest register.

Parameters
  • reg0_in – first input register

  • reg1_in – second input register

  • reg_out – output register

Returns

the new Circuit

add_circbox(*args, **kwargs)

Overloaded function.

  1. add_circbox(self: pytket.circuit.Circuit, circbox: pytket.circuit.CircBox, args: List[int], **kwargs) -> pytket.circuit.Circuit

Append a CircBox to the circuit.

Parameters
  • circbox – The box to append

  • args – Indices of the qubits/bits to append the box to

Returns

the new Circuit

  1. add_circbox(self: pytket.circuit.Circuit, circbox: pytket.circuit.CircBox, args: List[pytket.circuit.UnitID], **kwargs) -> pytket.circuit.Circuit

Append a CircBox to the circuit.

Parameters
  • circbox – The box to append

  • args – The qubits/bits to append the box to

Returns

the new Circuit

add_circuit(*args, **kwargs)

Overloaded function.

  1. add_circuit(self: pytket.circuit.Circuit, circuit: pytket.circuit.Circuit, qubits: List[pytket.circuit.Qubit], bits: List[pytket.circuit.Bit] = []) -> pytket.circuit.Circuit

In-place sequential composition of circuits, appending a copy of the argument onto the end of the circuit. Connects qubits and bits with the same behaviour as add_gate().

Parameters
  • circuit – The circuit to be appended to the end of self

  • qubits – List mapping the (default register) qubits of circuit to the qubits of self

  • bits – List mapping the (default register) bits of circuit to the bits of self

Returns

the new Circuit

  1. add_circuit(self: pytket.circuit.Circuit, circuit: pytket.circuit.Circuit, qubits: List[int], bits: List[int] = []) -> pytket.circuit.Circuit

In-place sequential composition of circuits, appending a copy of the argument onto the end of the circuit. Connects qubits and bits with the same behaviour as add_gate().

Parameters
  • circuit – The circuit to be appended to the end of self

  • qubits – List mapping the (default register) qubits of circuit to the (default register) qubits of self

  • bits – List mapping the (default register) bits of circuit to the (default register) bits of self

Returns

the new Circuit

add_classicalexpbox_bit(self: pytket.circuit.Circuit, expression: object, target: List[pytket.circuit.Bit], **kwargs) pytket.circuit.Circuit

Append a ClassicalExpBox over Bit to the circuit.

Parameters
  • classicalexpbox – The box to append

  • args – Indices of the qubits to append the box to

Returns

the new Circuit

add_classicalexpbox_register(self: pytket.circuit.Circuit, expression: object, target: List[pytket.circuit.Bit], **kwargs) pytket.circuit.Circuit

Append a ClassicalExpBox over BitRegister to the circuit.

Parameters
  • classicalexpbox – The box to append

  • args – Indices of the qubits to append the box to

Returns

the new Circuit

add_custom_gate(*args, **kwargs)

Overloaded function.

  1. add_custom_gate(self: pytket.circuit.Circuit, def: pytket.circuit.CustomGateDef, params: List[Expression], qubits: List[int], **kwargs) -> pytket.circuit.Circuit

Append an instance of a CustomGateDef to the circuit.

Parameters
  • def – The custom gate definition

  • params – List of parameters to instantiate the gate with, in halfturns

  • qubits – Indices of the qubits to append the box to

Returns

the new Circuit

  1. add_custom_gate(self: pytket.circuit.Circuit, def: pytket.circuit.CustomGateDef, params: List[Expression], qubits: List[pytket.circuit.Qubit], **kwargs) -> pytket.circuit.Circuit

Append an instance of a CustomGateDef to the circuit.

Parameters
  • def – The custom gate definition

  • params – List of parameters to instantiate the gate with, in halfturns

  • qubits – The qubits to append the box to

Returns

the new Circuit

add_expbox(*args, **kwargs)

Overloaded function.

  1. add_expbox(self: pytket.circuit.Circuit, expbox: pytket.circuit.ExpBox, qubit_0: int, qubit_1: int, **kwargs) -> pytket.circuit.Circuit

Append an ExpBox to the circuit.

The matrix representation is ILO-BE.

Parameters
  • expbox – The box to append

  • qubit_0 – Index of the first target qubit

  • qubit_1 – Index of the second target qubit

Returns

the new Circuit

  1. add_expbox(self: pytket.circuit.Circuit, expbox: pytket.circuit.ExpBox, qubit_0: pytket.circuit.Qubit, qubit_1: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Append an ExpBox to the circuit.

The matrix representation is ILO-BE.

Parameters
  • expbox – The box to append

  • qubit_0 – The first target qubit

  • qubit_1 – The second target qubit

Returns

the new Circuit

add_gate(*args, **kwargs)

Overloaded function.

  1. add_gate(self: pytket.circuit.Circuit, Op: pytket.circuit.Op, args: List[int], **kwargs) -> pytket.circuit.Circuit

Appends a single operation to the end of the circuit on some particular qubits/bits. The number of qubits/bits specified must match the arity of the gate.

  1. add_gate(self: pytket.circuit.Circuit, Op: pytket.circuit.Op, args: List[pytket.circuit.UnitID], **kwargs) -> pytket.circuit.Circuit

Appends a single operation to the end of the circuit on some particular qubits/bits. The number of qubits/bits specified must match the arity of the gate.

  1. add_gate(self: pytket.circuit.Circuit, type: pytket.circuit.OpType, args: List[int], **kwargs) -> pytket.circuit.Circuit

Appends a single (non-parameterised) gate to the end of the circuit on some particular qubits from the default register (‘q’). The number of qubits specified must match the arity of the gate. For OpType.Measure operations the bit from the default register should follow the qubit.

>>> c.add_gate(OpType.H, [0]) # equivalent to c.H(0)
>>> c.add_gate(OpType.CX, [0,1]) # equivalent to c.CX(0,1)
Parameters
  • type – The type of operation to add

  • args – The list of indices for the qubits/bits to which the operation is applied

  • kwargs – Additional properties for classical conditions

Returns

the new Circuit

  1. add_gate(self: pytket.circuit.Circuit, type: pytket.circuit.OpType, args: List[pytket.circuit.UnitID], **kwargs) -> pytket.circuit.Circuit

Appends a single (non-parameterised) gate to the end of the circuit on some particular qubits from the default register (‘q’). The number of qubits specified must match the arity of the gate. For OpType.Measure operations the bit from the default register should follow the qubit.

>>> c.add_gate(OpType.H, [0]) # equivalent to c.H(0)
>>> c.add_gate(OpType.CX, [0,1]) # equivalent to c.CX(0,1)
Parameters
  • type – The type of operation to add

  • args – The qubits/bits to apply the gate to

  • kwargs – Additional properties for classical conditions

Returns

the new Circuit

  1. add_gate(self: pytket.circuit.Circuit, type: pytket.circuit.OpType, angle: Expression, args: List[int], **kwargs) -> pytket.circuit.Circuit

Appends a single gate, parameterised by an expression, to the end of circuit on some particular qubits from the default register (‘q’).

Parameters
  • type – The type of gate to add

  • angle – The parameter for the gate in halfturns

  • args – The list of indices for the qubits to which the operation is applied

  • kwargs – Additional properties for classical conditions

Returns

the new Circuit

  1. add_gate(self: pytket.circuit.Circuit, type: pytket.circuit.OpType, angle: Expression, args: List[pytket.circuit.UnitID], **kwargs) -> pytket.circuit.Circuit

Appends a single gate, parameterised by an expression, to the end of circuit on some particular qubits from the default register (‘q’).

Parameters
  • type – The type of gate to add

  • angle – The parameter for the gate in halfturns

  • args – The qubits/bits to apply the gate to

  • kwargs – Additional properties for classical conditions

Returns

the new Circuit

  1. add_gate(self: pytket.circuit.Circuit, type: pytket.circuit.OpType, angles: List[Expression], args: List[int], **kwargs) -> pytket.circuit.Circuit

Appends a single gate, parameterised with a vector of expressions corresponding to halfturns, to the end of circuit on some particular qubits from the default register (‘q’).

Parameters
  • type – The type of gate to add

  • angles – The parameters for the gate in halfturns

  • args – The list of indices for the qubits to which the operation is applied

  • kwargs – Additional properties for classical conditions

Returns

the new Circuit

  1. add_gate(self: pytket.circuit.Circuit, type: pytket.circuit.OpType, angles: List[Expression], args: List[pytket.circuit.UnitID], **kwargs) -> pytket.circuit.Circuit

Appends a single gate to the end of the circuit

Parameters
  • type – The type of gate to add

  • params – The parameters for the gate in halfturns

  • args – The qubits/bits to apply the gate to

  • kwargs – Additional properties for classical conditions

Returns

the new Circuit

add_pauliexpbox(*args, **kwargs)

Overloaded function.

  1. add_pauliexpbox(self: pytket.circuit.Circuit, pauliexpbox: pytket.circuit.PauliExpBox, qubits: List[int], **kwargs) -> pytket.circuit.Circuit

Append a PauliExpBox to the circuit.

Parameters
  • pauliexpbox – The box to append

  • qubits – Indices of the qubits to append the box to

Returns

the new Circuit

  1. add_pauliexpbox(self: pytket.circuit.Circuit, pauliexpbox: pytket.circuit.PauliExpBox, qubits: List[pytket.circuit.Qubit], **kwargs) -> pytket.circuit.Circuit

Append a PauliExpBox to the circuit.

Parameters
  • pauliexpbox – The box to append

  • qubits – The qubits to append the box to

Returns

the new Circuit

add_phase(self: pytket.circuit.Circuit, a: Expression) pytket.circuit.Circuit

Add a global phase to the circuit.

Parameters

a – Phase to add, in halfturns

Returns

circuit with added phase

add_phasepolybox(*args, **kwargs)

Overloaded function.

  1. add_phasepolybox(self: pytket.circuit.Circuit, phasepolybox: tket::PhasePolyBox, qubits: List[int], **kwargs) -> pytket.circuit.Circuit

Append a PhasePolyBox to the circuit.

Parameters
  • phasepolybox – The box to append

  • qubits – Indices of the qubits to append the box to

Returns

the new Circuit

  1. add_phasepolybox(self: pytket.circuit.Circuit, phasepolybox: tket::PhasePolyBox, qubits: List[pytket.circuit.Qubit], **kwargs) -> pytket.circuit.Circuit

Append a PhasePolyBox to the circuit.

Parameters
  • phasepolybox – The box to append

  • qubits – The qubits to append the box to

Returns

the new Circuit

add_q_register(*args, **kwargs)

Overloaded function.

  1. add_q_register(self: pytket.circuit.Circuit, name: str, size: int) -> pytket.circuit.QubitRegister

Constructs a new quantum register with a given name and number of qubits.

Parameters
  • name – Unique readable name for the register

  • size – Number of qubits required

Returns

a map from index to the corresponding UnitIDs

  1. add_q_register(self: pytket.circuit.Circuit, register: pytket.circuit.QubitRegister) -> pytket.circuit.QubitRegister

Adds QubitRegister to Circuit

Parameters

register – QubitRegister

add_qcontrolbox(*args, **kwargs)

Overloaded function.

  1. add_qcontrolbox(self: pytket.circuit.Circuit, qcontrolbox: pytket.circuit.QControlBox, args: List[int], **kwargs) -> pytket.circuit.Circuit

Append a QControlBox to the circuit.

Parameters
  • qcontrolbox – The box to append

  • args – Indices of the qubits to append the box to

Returns

the new Circuit

  1. add_qcontrolbox(self: pytket.circuit.Circuit, qcontrolbox: pytket.circuit.QControlBox, args: List[pytket.circuit.UnitID], **kwargs) -> pytket.circuit.Circuit

Append a QControlBox to the circuit.

Parameters
  • qcontrolbox – The box to append

  • args – The qubits to append the box to

Returns

the new Circuit

add_qubit(self: pytket.circuit.Circuit, id: pytket.circuit.Qubit, reject_dups: bool = True) None

Constructs a single qubit with the given id.

Parameters
  • id – Unique id for the qubit

  • reject_dups – Fail if there is already a qubit in this circuit with the id. Default to True

add_unitary1qbox(*args, **kwargs)

Overloaded function.

  1. add_unitary1qbox(self: pytket.circuit.Circuit, unitarybox: pytket.circuit.Unitary1qBox, qubit_0: int, **kwargs) -> pytket.circuit.Circuit

Append a Unitary1qBox to the circuit.

Parameters
  • unitarybox – The box to append

  • qubit_0 – Index of the qubit to append the box to

Returns

the new Circuit

  1. add_unitary1qbox(self: pytket.circuit.Circuit, unitarybox: pytket.circuit.Unitary1qBox, qubit_0: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Append a Unitary1qBox to the circuit.

Parameters
  • unitarybox – The box to append

  • qubit_0 – The qubit to append the box to

Returns

the new Circuit

add_unitary2qbox(*args, **kwargs)

Overloaded function.

  1. add_unitary2qbox(self: pytket.circuit.Circuit, unitarybox: pytket.circuit.Unitary2qBox, qubit_0: int, qubit_1: int, **kwargs) -> pytket.circuit.Circuit

Append a Unitary2qBox to the circuit.

The matrix representation is ILO-BE.

Parameters
  • unitarybox – The box to append

  • qubit_0 – Index of the first target qubit

  • qubit_1 – Index of the second target qubit

Returns

the new Circuit

  1. add_unitary2qbox(self: pytket.circuit.Circuit, unitarybox: pytket.circuit.Unitary2qBox, qubit_0: pytket.circuit.Qubit, qubit_1: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Append a Unitary2qBox to the circuit.

The matrix representation is ILO-BE.

Parameters
  • unitarybox – The box to append

  • qubit_0 – The first target qubit

  • qubit_1 – The second target qubit

Returns

the new Circuit

add_unitary3qbox(*args, **kwargs)

Overloaded function.

  1. add_unitary3qbox(self: pytket.circuit.Circuit, unitarybox: tket::Unitary3qBox, qubit_0: int, qubit_1: int, qubit_2: int, **kwargs) -> pytket.circuit.Circuit

Append a Unitary3qBox to the circuit.

Parameters
  • unitarybox – box to append

  • qubit_0 – index of target qubit 0

  • qubit_1 – index of target qubit 1

  • qubit_2 – index of target qubit 2

Returns

the new Circuit

  1. add_unitary3qbox(self: pytket.circuit.Circuit, unitarybox: tket::Unitary3qBox, qubit_0: pytket.circuit.Qubit, qubit_1: pytket.circuit.Qubit, qubit_2: pytket.circuit.Qubit, **kwargs) -> pytket.circuit.Circuit

Append a Unitary3qBox to the circuit.

Parameters
  • unitarybox – box to append

  • qubit_0 – index of target qubit 0

  • qubit_1 – index of target qubit 1

  • qubit_2 – index of target qubit 2

Returns

the new Circuit

append(self: pytket.circuit.Circuit, circuit: pytket.circuit.Circuit) None

In-place sequential composition of circuits, appending a copy of the argument onto the end of the circuit. Inputs and Outputs are unified if they share the same id, defaulting to parallel composition if there is no match.

Parameters

circuit – The circuit to be appended to the end of self

commands_of_type(self: pytket.circuit.Circuit, optype: pytket.circuit.OpType) List[pytket.circuit.Command]

Get all commands in a circuit of a given type.

The order is consistent with the causal order of the operations in the circuit.

Parameters

optype – operation type

Returns

list of Command

copy(self: pytket.circuit.Circuit) pytket.circuit.Circuit
Returns

an identical copy of the circuit

dagger(self: pytket.circuit.Circuit) pytket.circuit.Circuit

Given a pure circuit (i.e. without any measurements or conditional gates), produces a new circuit for the inverse/adjoint operation.

Returns

a new Circuit corresponding to the inverse operation

depth(self: pytket.circuit.Circuit) int

Returns the number of interior vertices on the longest path through the DAG, excluding vertices representing barrier operations.

>>> c = Circuit(3)
>>> c.depth()
0
>>> c.CX(0,1)
>>> c.CX(1,2)
>>> c.CX(2,0)
>>> c.depth()
3
Returns

the circuit depth

depth_by_type(*args, **kwargs)

Overloaded function.

  1. depth_by_type(self: pytket.circuit.Circuit, type: pytket.circuit.OpType) -> int

Returns the number of vertices in the longest path through the sub-DAG consisting of vertices representing operations of the given type.

>>> c = Circuit(3)
>>> c.CX(0,1)
>>> c.Z(1)
>>> c.CX(1,2)
>>> c.depth_by_type(OpType.CX)
2
Parameters

type – the operation type of interest

Returns

the circuit depth with respect to operations matching type

  1. depth_by_type(self: pytket.circuit.Circuit, types: Set[pytket.circuit.OpType]) -> int

Returns the number of vertices in the longest path through the sub-DAG consisting of vertices representing operations of the given types.

>>> c = Circuit(3)
>>> c.CZ(0,1)
>>> c.Z(1)
>>> c.CX(1,2)
>>> c.depth_by_type({OpType.CZ, OpType.CX})
2
Parameters

types – the set of operation types of interest

Returns

the circuit depth with respect to operations matching an element of types

flatten_registers(self: pytket.circuit.Circuit) None

Combines all qubits into a single register namespace with the default name, and likewise for bits

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

set of symbolic parameters in the circuit

static from_dict(arg0: json) pytket.circuit.Circuit

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

get_commands(self: pytket.circuit.Circuit) List[pytket.circuit.Command]
Returns

a list of all the Commands in the circuit

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

Calculate the unitary matrix of the circuit, using ILO-BE convention, applied to the column vector (1,0,0…), which is thus another column vector. Due to pybind11 and numpy peculiarities, to treat the result as a genuine column vector and perform further matrix multiplication, you need to call .reshape(rows,1) to get a 2D matrix with the correct dimensions.

Returns

The calculated vector.

get_unitary(self: pytket.circuit.Circuit) numpy.ndarray[numpy.complex128[m, n]]
Returns

The numerical unitary matrix of the circuit, using ILO-BE convention.

get_unitary_times_other(self: pytket.circuit.Circuit, matr: numpy.ndarray[numpy.complex128[m, n]]) numpy.ndarray[numpy.complex128[m, n]]

Calculate UM, where U is the numerical unitary matrix of the circuit, with ILO-BE convention, and M is another matrix. This is more efficient than calculating U separately, if M has fewer columns than U.

Parameters

matr – The matrix to be multiplied.

Returns

The product of the circuit unitary and the given matrix.

implicit_qubit_permutation(self: pytket.circuit.Circuit) Dict[pytket.circuit.Qubit, pytket.circuit.Qubit]
Returns

dictionary mapping input qubit to output qubit on the same path

is_symbolic(self: pytket.circuit.Circuit) bool
Returns

True if the circuit contains any free symbols, False otherwise.

measure_all(self: pytket.circuit.Circuit) pytket.circuit.Circuit

Appends a measure gate to all qubits, storing the results in the default classical register. Bits are added to the circuit if they do not already exist.

Returns

the new Circuit

n_gates_of_type(self: pytket.circuit.Circuit, type: pytket.circuit.OpType) int

Returns the number of vertices in the dag of a given operation type.

>>> c.CX(0,1)
>>> c.H(0)
>>> c.CX(0,1)
>>> c.n_gates_of_type(OpType.CX)
2
Parameters

type – The operation type to search for

Returns

the number of operations matching type

ops_of_type(self: pytket.circuit.Circuit, optype: pytket.circuit.OpType) List[pytket.circuit.Op]

Get all operations in the circuit of a given type.

The order is not guaranteed.

Parameters

optype – operation type

Returns

list of Op

qubit_create(self: pytket.circuit.Circuit, arg0: pytket.circuit.Qubit) None

Make a quantum input a Create operation (initialized to 0

qubit_create_all(self: pytket.circuit.Circuit) None

Make all quantum inputs Create operations (initialized to 0)

qubit_discard(self: pytket.circuit.Circuit, arg0: pytket.circuit.Qubit) None

Make a quantum output a Discard operation

qubit_discard_all(self: pytket.circuit.Circuit) None

Make all quantum outputs Discard operations

qubit_is_created(self: pytket.circuit.Circuit, arg0: pytket.circuit.Qubit) bool

Query whether a qubit has its initial state set to zero

qubit_is_discarded(self: pytket.circuit.Circuit, arg0: pytket.circuit.Qubit) bool

Query whether a qubit has its final state discarded

remove_blank_wires(self: pytket.circuit.Circuit) None

Removes any Input-Output pairs in the DAG with no intervening operations, i.e. removes untouched qubits/bits from the circuit. This may occur when optimisations recognise that the operations on a qubit reduce to the identity, or when routing adds wires to “fill out” the architecture.

rename_units(self: pytket.circuit.Circuit, map: Dict[pytket.circuit.UnitID, pytket.circuit.UnitID]) bool

Rename qubits and bits simultaneously according to the map of ids provided

Parameters

map – Dictionary from current ids to new ids

substitute_named(*args, **kwargs)

Overloaded function.

  1. substitute_named(self: pytket.circuit.Circuit, op: pytket.circuit.Op, opgroup: str) -> bool

Substitute all ops with the given name for the given op.The replacement operations retain the same name.

Parameters
  • op – the replacement operation

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, repl: pytket.circuit.Circuit, opgroup: str) -> bool

Substitute all ops with the given name for the given circuit.Named operations in the replacement circuit must not match any named operations in the circuit being modified.

Parameters
  • repl – the replacement circuit

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.CircBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement CircBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.Unitary1qBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement Unitary1qBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.Unitary2qBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement Unitary2qBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: tket::Unitary3qBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement Unitary3qBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.ExpBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement ExpBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.PauliExpBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement PauliExpBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.QControlBox, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement QControlBox

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

  1. substitute_named(self: pytket.circuit.Circuit, box: pytket.circuit.CustomGate, opgroup: str) -> bool

Substitute all ops with the given name for the given box.The replacement boxes retain the same name.

Parameters
  • box – the replacement CustomGate

  • opgroup – the name of the operations group to replace

Returns

whether any replacements were made

symbol_substitution(*args, **kwargs)

Overloaded function.

  1. symbol_substitution(self: pytket.circuit.Circuit, symbol_map: Dict[Symbol, Expression]) -> None

In-place substitution for symbolic expressions; iterates through each parameterised gate and performs the substitution. This will not affect any symbols captured within boxed operations.

Parameters

symbol_map – A map from SymPy symbols to SymPy expressions

  1. symbol_substitution(self: pytket.circuit.Circuit, symbol_map: Dict[Symbol, float]) -> None

In-place substitution for symbolic expressions; iterates through each parameterised gate and performs the substitution. This will not affect any symbols captured within boxed operations.

Parameters

symbol_map – A map from SymPy symbols to floating-point values

to_dict(self: pytket.circuit.Circuit) json
Returns

a JSON serializable dictionary representation of the Circuit

to_latex_file(self: pytket.circuit.Circuit, filename: str) None

Produces a latex file with a visualisation of the circuit using the Quantikz package.

Parameters

filename – Name of file to write output to (must end in “.tex”)

transpose(self: pytket.circuit.Circuit) pytket.circuit.Circuit

Given a pure circuit (i.e. without any measurements or conditional gates), produces a new circuit for the transpose operation.

Returns

a new Circuit corresponding to the transpose operation

valid_connectivity(self: pytket.circuit.Circuit, arch: pytket.routing.Architecture, directed: bool, allow_bridge: bool = False) bool

Confirms whether all two qubit gates in given circuit are along some edge of the architecture.

Parameters
  • arch – The architecture capturing the desired connectivity

  • directed – If true, also checks that CX or ECR gates are in the same direction as the edges of the architecture

  • allow_bridge – Accept BRIDGEs as valid, assuming the middle qubit neighbours the others

Returns

True or False

__hash__ = None
property bit_readout

A map from bit to its (left-to-right) index in readouts from backends (following the increasing lexicographic order convention)

property bits

A list of all classical bit ids in the circuit

property is_simple

Checks that the circuit has only 1 quantum and 1 classic register using the default names (‘q’ and ‘c’). This means it is suitable to refer to qubits simply by their integer indices.

property n_gates
Returns

the number of gates in the Circuit

property n_qubits
Returns

the number of qubits in the circuit

property phase
Returns

the global phase applied to the circuit, in halfturns (not meaningful for circuits with classical interactions)

property qubit_readout

A map from qubit to its (left-to-right) index in readouts from backends. A qubit will feature in this map if it is measured and neither it nor the bit containing the measurement result is subsequently acted on

property qubit_to_bit_map

A map from qubit to the bit it is measured to. A qubit will feature in this map if it is measured and neither it nor the bit containing the measurement result is subsequently acted on

property qubits

A list of all qubit ids in the circuit