# pytket.passes¶

Module exposing various types of compiler pass.

class pytket.passes.BasePass

Base class for passes.

__init__()

Initialize self. See help(type(self)) for accurate signature.

apply(*args, **kwargs)

1. apply(self: pytket.passes.BasePass, compilation_unit: tket::CompilationUnit, safety_mode: pytket.passes.SafetyMode = SafetyMode.Default) -> bool

Apply to a CompilationUnit. Return true if and only if the pass modified the circuit.

1. apply(self: pytket.passes.BasePass, circuit: pytket.circuit.Circuit) -> bool

Apply to a Circuit in-place. Return true if and only if the pass modified the circuit.

class pytket.passes.RepeatPass

Repeat a pass until it has no effect.

__init__(self: pytket.passes.RepeatPass, compilation_pass: pytket.passes.BasePass)None

Construct from a compilation pass.

class pytket.passes.RepeatUntilSatisfiedPass

Repeat a compilation pass until a predicate on the circuit is satisfied.

__init__(*args, **kwargs)

1. __init__(self: pytket.passes.RepeatUntilSatisfiedPass, compilation_pass: pytket.passes.BasePass, predicate: tket::Predicate) -> None

Construct from a compilation pass and a predicate.

1. __init__(self: pytket.passes.RepeatUntilSatisfiedPass, compilation_pass: pytket.passes.BasePass, check_function: Callable[[pytket.circuit.Circuit], bool]) -> None

Construct from a compilation pass and a user-defined function from Circuit to bool.

class pytket.passes.RepeatWithMetricPass

Repeat a compilation pass until the given metric stops decreasing.

__init__(self: pytket.passes.RepeatWithMetricPass, compilation_pass: pytket.passes.BasePass, metric: Callable[[pytket.circuit.Circuit], int])None

Construct from a compilation pass and a metric function.

class pytket.passes.SafetyMode

Members:

Audit : Checks which predicates a circuit satisfies after the application of each base pass

Default : Only check that a circuit satisfies the preconditions of the overall pass at the start and the postconditions at the end

__init__(self: pytket.passes.SafetyMode, arg0: int)None
property name

(self: handle) -> str

class pytket.passes.SequencePass

A sequence of compilation passes.

__init__(self: pytket.passes.SequencePass, pass_list: List[pytket.passes.BasePass])None

Construct from a list of compilation passes arranged in order of application.

pytket.passes.CXMappingPass(device: pytket.device.Device, placer: pytket.routing.Placement, **kwargs)pytket.passes.BasePass

Construct a pass to convert all gates to CX, relabel Circuit Qubits to :py:class’Device’ Nodes, route to the connectivty graph of a Device and decompose additional routing gates (SWAP and BRIDGE) to CX gates.

Parameters
• device – The Device used for connectivity information.

• placer – The placement used for relabelling.

• **kwargs – Parameters for routing: (int)swap_lookahead=50, (int)bridge_lookahead=4, (int)bridge_interactions=2, (float)bridge_exponent=0, (RoutingMethod)routing_method=RoutingMethod.base, (bool)directed_cx=false, (bool)delay_measures=true

pytket.passes.CliffordSimp(allow_swaps: bool = True)pytket.passes.BasePass

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.

Parameters

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

pytket.passes.CommuteThroughMultis()pytket.passes.BasePass

Moves single-qubit operations past multi-qubit operations that they commute with, towards the front of the circuit.

pytket.passes.DecomposeArbitrarilyControlledGates()pytket.passes.BasePass

Decomposes CnX and CnRy gates into Ry, CX, H, T and Tdg gates.

pytket.passes.DecomposeBoxes()pytket.passes.BasePass

Replaces all boxes by their decomposition into circuits.

pytket.passes.DecomposeMultiQubitsIBM()pytket.passes.BasePass

Converts all multi-qubit gates into CX and single-qubit gates.

pytket.passes.DecomposeSingleQubitsIBM()pytket.passes.BasePass

Converts all single-qubit gates into U1, U2 and U3 gates.

pytket.passes.DecomposeSwapsToCXs(device: pytket.device.Device, respect_direction: bool = False)pytket.passes.BasePass

Construct a pass to decompose SWAP and BRIDGE gates to CX gates, constraining connectivity to a Device, optionally taking the directedness of the connectivity graph into account.

Parameters
• device – The device to use for connectivity information.

• respect_direction – Optionally takes the directedness of the connectivity graph into account.

pytket.passes.DecomposeSwapsToCircuit(replacement_circuit: pytket.circuit.Circuit)pytket.passes.BasePass
Parameters

replacement_circuit – An equivalent circuit to replace a SWAP gate with in the desired basis.

pytket.passes.DefaultMappingPass(device: pytket.device.Device)pytket.passes.BasePass

Construct a pass to relabel Circuit Qubits to Device Nodes, and then route to the connectivity graph of a :py:class: ‘Device’. Edge direction is ignored. Placement used is GraphPlacement.

Parameters
• device – The Device used for connectivity information.

• **kwargs – Parameters for routing: (int)swap_lookahead=50, (int)bridge_lookahead=4, (int)bridge_interactions=2, (float)bridge_exponent=0, (RoutingMethod)routing_method = RoutingMethod.base.

pytket.passes.DelayMeasures()pytket.passes.BasePass

Commutes Measure operations to the end of the circuit. Throws an exception when this is not possible because of gates following the measure which are dependent on either the resulting quantum state or classical values.

pytket.passes.EulerAngleReduction(arg0: pytket.circuit.OpType, arg1: pytket.circuit.OpType)pytket.passes.BasePass

Uses Euler angle decompositions to reduce all chains of P and Q rotations to minimal P-Q-P triples, where P,Q ∈ {Rx,Ry,Rz}.

Parameters
• q – The type of the inner rotation of each triple.

• p – The type of the outer rotations of each triple.

pytket.passes.FlattenRegisters()pytket.passes.BasePass

Merges all quantum and classical registers into their respective default registers with contiguous indexing.

pytket.passes.FullMappingPass(device: pytket.device.Device, placer: pytket.routing.Placement, **kwargs)pytket.passes.BasePass

Construct a pass to relabel Circuit Qubits to Device Nodes, and then route to the connectivity graph of a Device. Edge direction is ignored.

Parameters
• device – The Device to use for connectivity information.

• placer – The Placement used for relabelling.

• **kwargs – Parameters for routing: (int)swap_lookahead=50, (int)bridge_lookahead=4, (int)bridge_interactions=2, (float)bridge_exponent=0, (RoutingMethod)routing_method = RoutingMethod.base.

pytket.passes.FullPeepholeOptimise()pytket.passes.BasePass

Performs full (and slow) peephole optimisation and converts to a circuit containing only CX, U1, U2 and U3 gates.

pytket.passes.GuidedPauliSimp(strat: pytket.transform.PauliSynthStrat = PauliSynthStrat.Sets, cx_config: pytket.transform.CXConfigType = CXConfigType.Snake)pytket.passes.BasePass

Applies the PauliSimp optimisation pass to any region of the circuit contained within a CircBox. This can be useful to focus the synthesis to target specific sets of commuting operations, rather than the default greedy approach.

Parameters
• strat – A synthesis strategy for the Pauli graph.

• cx_config – A configuration of CXs to convert Pauli gadgets into.

pytket.passes.KAKDecomposition()pytket.passes.BasePass

An optimisation pass that performs a Cartan/KAK Decomposition for 2 qubit gate sequences, well explained in Robert Tucci (https://arxiv.org/abs/quant-ph/0507171). Given a circuit with CXs, SWAPs and any single-qubit gates, produces a circuit with the same gates. This will not preserve CX orientation.

pytket.passes.O1Pass()pytket.passes.BasePass

A recommended, all-purpose circuit optimisation pass for fast compilation. Compiles to the gateset {CX, tk1, Reset, Measure}. This should be applied before the default compilation pass of the target backend.

Returns

An optimisation pass that performs only basic circuit simplifications for basic usage.

Return type

BasePass

pytket.passes.O2Pass()pytket.passes.BasePass

A recommended, all-purpose circuit optimisation pass for fast compilation. Compiles to the gateset {CX, tk1, Reset, Measure}. This should be applied before the default compilation pass of the target backend.

Returns

An optimisation pass that performs local circuit simplification techniques.

Return type

BasePass

pytket.passes.OptimisePhaseGadgets(cx_config: pytket.transform.CXConfigType = CXConfigType.Snake)pytket.passes.BasePass

Construct a pass that synthesises phase gadgets and converts to a circuit containing only CX, U1, U2 and U3 gates.

Parameters

cx_config – A configuration of CXs to convert phase gadgets into.

pytket.passes.PauliSimp(strat: pytket.transform.PauliSynthStrat = PauliSynthStrat.Sets, cx_config: pytket.transform.CXConfigType = CXConfigType.Snake)pytket.passes.BasePass

Construct a pass that converts a circuit into a graph of Pauli gadgets to account for commutation and phase folding, and resynthesises them as either individual gagdets, pairwise constructions, or by diagonalising sets of commuting gadgets.

Parameters
• strat – A synthesis strategy for the Pauli graph.

• cx_config – A configuration of CXs to convert Pauli gadgets into.

pytket.passes.PlacementPass(placer: pytket.routing.Placement)pytket.passes.BasePass

Construct a pass to relabel Circuit Qubits to Device Nodes.

Parameters

placer – The Placement used for relabelling.

pytket.passes.RebaseCirq()pytket.passes.BasePass

Converts all gates to CZ, PhasedX and Rz.

pytket.passes.RebaseCustom(multiqs: , cx_replacement: pytket.circuit.Circuit, singleqs: , tk1_replacement: Callable[[Expression, Expression, Expression], pytket.circuit.Circuit])pytket.passes.BasePass

Construct a custom rebase pass. This pass: (1) decomposes multi-qubit gates not in the set of gate types multiqs to CX gates; (2) if CX is not in multiqs, replaces CX gates with cx_replacement; (3) converts any single-qubit gates not in the gate type set singleqs to the form $$\mathrm{Rz}(a)\mathrm{Rx}(b)\mathrm{Rz}(c)$$ (in matrix-multiplication order, i.e. reverse order in the circuit); (4) applies the tk1_replacement function to each of these triples $$(a,b,c)$$ to generate replacement circuits.

Parameters
• multiqs – The allowed multi-qubit operations in the rebased circuit.

• cx_replacement – The equivalent circuit to replace a CX gate in the desired basis.

• singleqs – The allowed single-qubit operations in the rebased circuit.

• tk1_replacement – A function which, given the parameters of an Rz(a)Rx(b)Rz(c) triple, returns an equivalent circuit in the desired basis.

pytket.passes.RebaseHQS()pytket.passes.BasePass

Converts all gates to ZZMax, PhasedX and Rz.

pytket.passes.RebaseIBM()pytket.passes.BasePass

Converts all gates to CX, U1, U2 and U3 gates.

pytket.passes.RebaseProjectQ()pytket.passes.BasePass

Converts all gates to SWAP, CRz, CX, CZ, H, X, Y, Z, S, T, V, Rx, Ry and Rz.

pytket.passes.RebasePyZX()pytket.passes.BasePass

Converts all gates to SWAP, CX, CZ, H, X, Z, S, T, Rx and Rz.

pytket.passes.RebaseQuil()pytket.passes.BasePass

Converts all gates to CZ, Rx and Rz.

pytket.passes.RebaseTket()pytket.passes.BasePass

Converts all gates to CX and tk1.

pytket.passes.RebaseUMD()pytket.passes.BasePass

Converts all gates to XXPhase, PhasedX and Rz.

pytket.passes.RemoveRedundancies()pytket.passes.BasePass

Removes gate-inverse pairs, merges rotations, removes identity rotations, and removes redundant gates before measurement. Does not add any new gate types.

pytket.passes.RoutingPass(device: pytket.device.Device, **kwargs)pytket.passes.BasePass

Construct a pass to route to the connectivity graph of a Device. Edge direction is ignored.

Parameters
• device – The device to use for connectivity information.

• **kwargs – Parameters for routing: (int)swap_lookahead=50, (int)bridge_lookahead=4, (int)bridge_interactions=2, (float)bridge_exponent=0, (RoutingMethod)routing_method = RoutingMethod.base.

pytket.passes.SynthesiseHQS()pytket.passes.BasePass

Optimises and converts a circuit consisting of CX and single-qubit gates into one containing only ZZMax, PhasedX and Rz.

pytket.passes.SynthesiseIBM()pytket.passes.BasePass

Optimises and converts all gates to CX, U1, U2 and U3 gates.

pytket.passes.SynthesiseUMD()pytket.passes.BasePass

Optimises and converts all gates to XXPhase, PhasedX and Rz.

pytket.passes.USquashIBM()pytket.passes.BasePass

Squash U1, U2 and U3 gates by converting to them to Rz-Ry-Rz sequences and back. The only single-qubit gates in the resulting circuit are U1 and U3.