pytket.transform

class pytket.transform.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.

__init__(self: pytket.transform.CXConfigType, value: int) None
property name
class pytket.transform.PauliSynthStrat

Enum for available strategies to synthesise Pauli gadgets

Members:

Individual : Synthesise gadgets individually

Pairwise : Synthesise gadgets using an efficient pairwise strategy from Cowtan et al (https://arxiv.org/abs/1906.01734)

Sets : Synthesise gadgets in commuting sets

__init__(self: pytket.transform.PauliSynthStrat, value: int) None
property name
class pytket.transform.Transform

An in-place transformation of a Circuit.

static CommuteSQThroughSWAP(*args, **kwargs)

Overloaded function.

  1. CommuteSQThroughSWAP(avg_node_errors: Dict[pytket.circuit.Node, float]) -> pytket.transform.Transform

Commutes single qubit gates through SWAP gates, leaving them on the physical qubit with best fidelity for given gate type. Assumes the circuit is already mapped onto the architecture.

Parameters

avg_node_errors – a dict mapping Nodes to average single-qubit gate errors

  1. CommuteSQThroughSWAP(op_node_errors: Dict[pytket.circuit.Node, Dict[pytket.circuit.OpType, float]]) -> pytket.transform.Transform

Commutes single qubit gates through SWAP gates, leaving them on the physical qubit with best fidelity for given gate type. Assumes the circuit is already mapped onto the architecture.

Parameters

avg_node_errors – a dict of dicts, mapping Nodes to dicts of OpType to single-qubit gate error maps

static CommuteThroughMultis() pytket.transform.Transform

Applies a collection of commutation rules to move single qubit operations past multiqubit operations they commute with, towards the front of the circuit.

static DecomposeBRIDGE() pytket.transform.Transform

Decomposes all BRIDGE gates into CX gates.

static DecomposeBoxes() pytket.transform.Transform

Decomposes all Boxed operations into elementary gates.

static DecomposeCCX() pytket.transform.Transform

Decomposes all 3-qubit Toffoli (CCX) gates into Clifford+T gates.

static DecomposeCXDirected(arc: pytket.routing.Architecture) pytket.transform.Transform

Decompose CX gates to H+CX to match the direction of the CXs to edges of the Architecture arc. Assumes the circuit already satisfies the connectivity of arc.

Parameters

arc – The architecture for which CXs should be redirected

static DecomposeControlledRys() pytket.transform.Transform

Decomposes all arbitrarily-quantum-controlled Rys into CX and Ry gates.

static DecomposeSWAP(circuit: pytket.circuit.Circuit) pytket.transform.Transform

Decomposes all SWAP gates to provided replacement circuit.

Parameters

circuit – A circuit that is logically equivalent to a SWAP operation

static DecomposeSWAPtoCX(arc: pytket.routing.Architecture = <pytket.routing.Architecture, nodes=0>) pytket.transform.Transform

Decomposes all SWAP gates into triples of CX gates. If the SWAP is adjacent to a CX, it will prefer to insert in the direction that allows for gate cancellation. If an Architecture is provided, this will prefer to insert the CXs such that fewer need redirecting.

Parameters

arc – Device architecture used to specify a preference for CX direction

static KAKDecomposition(cx_fidelity: float = 1.0) pytket.transform.Transform

Identifies two-qubit subcircuits with more than 3 CXs and reduces them via the KAK/Cartan decomposition, using the method detailed in https://arxiv.org/abs/cond-mat/0609750. The replacement subcircuits use CX and TK1 gates. The optional parameter cx_fidelity must be between 0 and 1 and should be the estimated CX gate fidelity of the noisy quantum hardware to be compiled for. It is used to trade off decomposition accuracy for smaller CX gate count. If cx_fidelity < 1, the resulting decomposition will optimise the expected circuit fidelity. In this case, the output circuit will not be logically equivalent. This will not preserve CX orientation.

Parameters

cx_fidelity – The estimated CX gate fidelity

static OptimiseCliffords(allow_swaps: bool = True) pytket.transform.Transform

An optimisation pass that performs a number of rewrite rules for simplifying Clifford gate sequences, similar to Duncan & Fagan (https://arxiv.org/abs/1901.10114). Given a circuit with CXs and any single-qubit gates, produces a circuit with Z, X, S, V, U1, U2, U3, CX gates. This will not preserve CX placement or orientation and may introduce implicit wire swaps.

Parameters

allow_swaps – dictates whether the rewriting will disregard CX placement or orientation and introduce wire swaps.

static OptimisePauliGadgets(cx_config: pytket.transform.CXConfigType = CXConfigType.Snake) pytket.transform.Transform

An optimisation pass that identifies the Pauli gadgets corresponding to any non-Clifford rotations and synthesises them pairwise (see Cowtan, Duncan, Dilkes, Simmons, & Sivarajah https://arxiv.org/abs/1906.01734). Results use tk1, CX gates.

static OptimisePhaseGadgets(cx_config: pytket.transform.CXConfigType = CXConfigType.Snake) pytket.transform.Transform

An optimisation pass that starts by identifying subcircuits corresponding to phase gadgets (see Cowtan, Duncan, Dilkes, Simmons, & Sivarajah https://arxiv.org/abs/1906.01734) and resynthesises them in a balanced-tree form, followed by applying OptimisePostRouting. Results use TK1 and CX gates. This will not preserve CX placement or orientation.

static OptimisePostRouting() pytket.transform.Transform

Fast optimisation pass, performing basic simplifications. Works on any circuit, giving the result in TK1 and CX gates. If all multi-qubit gates are CXs, then this preserves their placement and orientation, so it is safe to perform after routing.

static RebaseToCirq() pytket.transform.Transform

Rebase from any gate set into PhasedX, Rz, CZ.

static RebaseToCliffordSingles() pytket.transform.Transform

Identify Clifford-angle rotations (from U1, U2, U3, Rx, Ry, Rz, tk1, PhasedX), replacing them with Z, X, S, V gates. Any non-Clifford rotations will stay as they are.

static RebaseToProjectQ() pytket.transform.Transform

Rebase from any gate set into the gate set supported by ProjectQ (Rx, Ry, Rz, X, Y, Z, S, T, V, H, CX, CZ, CRz, SWAP).

static RebaseToPyZX() pytket.transform.Transform

Rebase from any gate set into the gate set supported by PyZX (Rx, Rz, X, Z, S, T, H, CX, CZ, SWAP).

static RebaseToQuil() pytket.transform.Transform

Rebase from any gate set into Rx, Rz, CZ.

static RebaseToRzRx() pytket.transform.Transform

Rebase single qubit gates into Rz, Rx.

static RebaseToTket() pytket.transform.Transform

Rebase from any gate set into TK1, CX.

static ReduceSingles() pytket.transform.Transform

Reduces each sequence of single-qubit rotations into a single TK1.

static RemoveRedundancies() pytket.transform.Transform

Applies a collection of simple optimisations, such as removing gate-inverse pairs, merging similar rotation gates, and removing identity gates. Preserves the gate set and any placement/orientation of multi-qubit gates.

static SynthesisePauliGraph(synth_strat: pytket.transform.PauliSynthStrat = PauliSynthStrat.Sets, cx_config: pytket.transform.CXConfigType = CXConfigType.Snake) pytket.transform.Transform

Synthesises Pauli Graphs.

static ThreeQubitSquash() pytket.transform.Transform

Squash three-qubit subcircuits into subcircuits having fewer CX gates, when possible.

static UCCSynthesis(synth_strat: pytket.transform.PauliSynthStrat = PauliSynthStrat.Sets, cx_config: pytket.transform.CXConfigType = CXConfigType.Snake) pytket.transform.Transform

Synthesises UCC circuits in the form that Term Sequencing provides them.

__init__(*args, **kwargs)
apply(self: pytket.transform.Transform, circuit: pytket.circuit.Circuit) bool

Performs the transformation on the circuit in place.

Parameters

circuit – The circuit to be transformed

Returns

True if any changes were made, else False

static repeat(transform: pytket.transform.Transform) pytket.transform.Transform

Applies a given Transform repeatedly to a circuit until no further changes are made (i.e. it no longer returns True). apply() will return True if at least one run returned True.

Parameters

transform – The Transform to be applied repeatedly

Returns

a new Transform representing the iteration

static sequence(sequence: List[pytket.transform.Transform]) pytket.transform.Transform

Composes a list of Transforms together in sequence. The apply() method will return True if ANY of the individual Transforms returned True.

Parameters

sequence – The list of Transforms to be composed

Returns

the combined Transform

static while_repeat(condition: pytket.transform.Transform, body: pytket.transform.Transform) pytket.transform.Transform

Repeatedly applies the condition Transform until it returns False, running body in between each condition application. Intuitively, this corresponds to “WHILE condition DO body”.

Parameters
  • condition – The Transform to be applied repeatedly as the condition of a loop

  • body – The Transform to be applied after each successful test of the condition

Returns

a new Transform representing the iteration

pytket.transform.separate_classical(circ: pytket.circuit.Circuit) Tuple[pytket.circuit.Circuit, pytket.circuit.Circuit]

Separate the input circuit into a ‘main’ circuit and a classical ‘post-processing’ circuit, which are equivalent to the original when composed.

Parameters

circ – circuit to be separated