pytket.passes
- class pytket.passes.BasePass
Base class for passes.
- __init__(*args, **kwargs)
- apply(*args, **kwargs)
Overloaded function.
apply(self: pytket.passes.BasePass, compilation_unit: pytket.predicates.CompilationUnit, safety_mode: pytket.passes.SafetyMode = <SafetyMode.Default: 1>) -> bool
Apply to a
CompilationUnit
.- Returns
True if pass modified the circuit, else False
apply(self: pytket.passes.BasePass, circuit: pytket.circuit.Circuit) -> bool
Apply to a
Circuit
in-place.- Returns
True if pass modified the circuit, else False
apply(self: pytket.passes.BasePass, circuit: pytket.circuit.Circuit, before_apply: Callable[[pytket.predicates.CompilationUnit, json], None], after_apply: Callable[[pytket.predicates.CompilationUnit, json], None]) -> bool
Apply to a
Circuit
in-place and invoke callbacks for all nested passes.- Parameters
before_apply – Invoked before a pass is applied. The CompilationUnit and a summary of the pass configuration are passed into the callback.
after_apply – Invoked after a pass is applied. The CompilationUnit and a summary of the pass configuration are passed into the callback.
- Returns
True if pass modified the circuit, else False
- static from_dict(arg0: json) pytket.passes.BasePass
Construct a new Pass instance from a JSON serializable dictionary representation.
- to_dict(self: pytket.passes.BasePass) json
- Returns
A JSON serializable dictionary representation of the Pass.
- class pytket.passes.CNotSynthType
Members:
SWAP : swap-based algorithm for CNOT synthesis
HamPath : Hamilton-path-based method for CNOT synthesis; this method will fail if there is no Hamilton path in the given architecture
Rec : recursive Steiner–Gauss method for CNOT synthesis
- __init__(self: pytket.passes.CNotSynthType, value: int) None
- property name
- 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.
- get_pass(self: pytket.passes.RepeatPass) pytket.passes.BasePass
- Returns
The underlying compilation pass.
- class pytket.passes.RepeatUntilSatisfiedPass
Repeat a compilation pass until a predicate on the circuit is satisfied.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pytket.passes.RepeatUntilSatisfiedPass, compilation_pass: pytket.passes.BasePass, predicate: pytket.predicates.Predicate) -> None
Construct from a compilation pass and a predicate.
__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.
- get_pass(self: pytket.passes.RepeatUntilSatisfiedPass) pytket.passes.BasePass
- Returns
The underlying compilation pass.
- get_predicate(self: pytket.passes.RepeatUntilSatisfiedPass) pytket.predicates.Predicate
- Returns
The underlying predicate.
- 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.
- get_metric(self: pytket.passes.RepeatWithMetricPass) Callable[[pytket.circuit.Circuit], int]
- Returns
The underlying metric.
- get_pass(self: pytket.passes.RepeatWithMetricPass) pytket.passes.BasePass
- Returns
The underlying compilation pass.
- 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, value: int) None
- property name
- 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.
- get_sequence(self: pytket.passes.SequencePass) List[pytket.passes.BasePass]
- Returns
The underlying sequence of passes.
- pytket.passes.AASRouting(arc: pytket.architecture.Architecture, **kwargs) pytket.passes.BasePass
Construct a pass to relabel
Circuit
Qubits toDevice
Nodes, and then use architecture-aware synthesis to route the circuit. In the steps of the pass the circuit will be converted to CX, Rz, H gateset. The limited connectivity of theArchitecture
is used for the routing. The direction of the edges is ignored. The placement used is GraphPlacement. This pass can take a few parameters for the routing, described below:(unsigned) lookahead=1: parameter for the recursive iteration
(CNotSynthType) cnotsynthtype=CNotSynthType.Rec: CNOT synthesis type
NB: The circuit needs to have at most as many qubits as the architecture has nodes. The resulting circuit will always have the same number of qubits as the architecture has nodes, even if the input circuit had fewer.
- Parameters
arc – target architecture
**kwargs – parameters for routing (described above)
- Returns
a pass to perform the remapping
- pytket.passes.CXMappingPass(arc: pytket.architecture.Architecture, placer: pytket.placement.Placement, **kwargs) pytket.passes.BasePass
Construct a pass to convert all gates to CX, relabel
Circuit
Qubits to :py:class’Architecture’ Nodes, route to the connectivty graph of aArchitecture
and decompose additional routing gates (SWAP and BRIDGE) to CX gates.- Parameters
arc – The Architecture used for connectivity information.
placer – The placement used for relabelling.
**kwargs – Parameters for routing: (bool)directed_cx=false, (bool)delay_measures=true
- Returns
a pass to perform the remapping
- 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 TK1, CX gates.
- Parameters
allow_swaps – dictates whether the rewriting will disregard CX placement or orientation and introduce wire swaps.
- Returns
a pass to perform the rewriting
- 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.ComposePhasePolyBoxes(**kwargs) pytket.passes.BasePass
Pass to convert a given
Circuit
to the CX, Rz, H gateset and compose phase polynomial boxes from the groups of the CX+Rz gates.(unsigned) min_size=0: minimal number of CX gates in each phase polynominal box: groups with a smaller number of CX gates are not affected by this transformation
- Parameters
**kwargs – parameters for composition (described above)
- Returns
a pass to perform the composition
- pytket.passes.ContextSimp(allow_classical: bool = True, xcirc: pytket.circuit.Circuit = None) pytket.passes.BasePass
Applies simplifications enabled by knowledge of qubit state and discarded qubits.
- Parameters
allow_classical – allow replacement of measurements on known state with classical set-bit operations
xcirc – 1-qubit circuit implementing an X gate in the transformed circuit (if omitted, an X gate is used)
- Returns
a pass to perform the simplification
- pytket.passes.CustomPass(transform: Callable[[pytket.circuit.Circuit], pytket.circuit.Circuit], label: str = '') pytket.passes.BasePass
Generate a custom pass from a user-provided circuit transfomation function.
It is the caller’s responsibility to provide a valid transform.
- Parameters
transform – function taking a
Circuit
as an argument and returning a new transformed circuit:param label: optional label for the pass- Returns
a pass to perform the transformation
- pytket.passes.CustomRoutingPass(arc: pytket.architecture.Architecture, config: List[pytket.mapping.RoutingMethod]) pytket.passes.BasePass
Construct a pass to route to the connectivity graph of an
Architecture
. Edge direction is ignored. :return: a pass that routes to the given device architecture
- 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.DecomposeClassicalExp() pytket.passes.BasePass
Replaces each
ClassicalExpBox
by a sequence of classical gates.
- pytket.passes.DecomposeMultiQubitsCX() pytket.passes.BasePass
Converts all multi-qubit gates into CX and single-qubit gates.
- pytket.passes.DecomposeSingleQubitsTK1() pytket.passes.BasePass
Converts all single-qubit gates into TK1 gates.
- pytket.passes.DecomposeSwapsToCXs(arc: pytket.architecture.Architecture, respect_direction: bool = False) pytket.passes.BasePass
Construct a pass to decompose SWAP and BRIDGE gates to CX gates, constraining connectivity to an
Architecture
, optionally taking the directedness of the connectivity graph into account.- Parameters
arc – The architecture to use for connectivity information.
respect_direction – Optionally takes the directedness of the connectivity graph into account.
- Returns
a pass to perform the decomposition
- 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.
- Returns
a pass to replace all SWAP gates with the given circuit
- pytket.passes.DecomposeTK2(allow_swaps: bool = True, **kwargs) pytket.passes.BasePass
Decompose each TK2 gate into two-qubit gates.
Gate fidelities can be passed as keyword arguments to perform noise-aware decompositions. If the fidelities of several gate types are provided, the best will be chosen.
We currently support CX_fidelity, ZZMax_fidelity and ZZPhase_fidelity. If provided, the CX and ZZMax fidelities must be given by a single floating point fidelity. The ZZPhase fidelity is given as a lambda float -> float, mapping a ZZPhase angle parameter to its fidelity. These parameters will be used to return the optimal decomposition of each TK2 gate, taking noise into consideration.
If no fidelities are provided, the TK2 gates will be decomposed exactly using CX gates.
All TK2 gate parameters must be normalised, i.e. they must satisfy NormalisedTK2Predicate.
Using the allow_swaps=True (default) option, qubits will be swapped when convenient to reduce the two-qubit gate count of the decomposed TK2.
If the TK2 angles are symbolic values, the decomposition will be exact (i.e. not noise-aware). It is not possible in general to obtain optimal decompositions for arbitrary symbolic parameters, so consider substituting for concrete values if possible.
- Parameters
allow_swaps – Whether to allow implicit wire swaps.
- pytket.passes.DefaultMappingPass(arc: pytket.architecture.Architecture, delay_measures: bool = True) pytket.passes.BasePass
Construct a pass to relabel
Circuit
Qubits toArchitecture
Nodes, and then route to the connectivity graph of the given :py:class: ‘Architecture’. Edge direction is ignored. Placement used is GraphPlacement.- Parameters
arc – The Architecture used for connectivity information.
delay_measures – Whether to commute measurements to the end of the circuit, defaulting to true.
- Returns
a pass to perform the remapping
- 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(q: pytket.circuit.OpType, p: pytket.circuit.OpType, strict: bool = False) pytket.passes.BasePass
Uses Euler angle decompositions to squash all chains of P and Q rotations, where P,Q ∈ {Rx,Ry,Rz}. By default (strict=False), this pass will try to decompose the chains into pairs of -P-Q- or -Q-P- rotations, commuting any third rotation past multi-qubit gates. If strict=True, all chains will be decomposed to P-Q-P triples and no further optimisation is performed.
- Parameters
q – The type of the Q rotation (Q ∈ {Rx,Ry,Rz}).
p – The type of the P rotation (P ∈ {Rx,Ry,Rz}, P ≠ Q).
strict – Optionally performs strict P-Q-P Euler decomposition
- Returns
a pass that squashes chains of P and Q rotations
- pytket.passes.FlattenRegisters() pytket.passes.BasePass
Merges all quantum and classical registers into their respective default registers with contiguous indexing.
- pytket.passes.FullMappingPass(arc: pytket.architecture.Architecture, placer: pytket.placement.Placement, config: List[pytket.mapping.RoutingMethod]) pytket.passes.BasePass
Construct a pass to relabel
Circuit
Qubits toArchitecture
Nodes, and then route to the connectivity graph of anArchitecture
. Edge direction is ignored.- Parameters
arc – The architecture to use for connectivity information.
placer – The Placement used for relabelling.
config – Parameters for routing, a list of RoutingMethod, each method is checked and run if applicable in turn.
- Returns
a pass to perform the remapping
- pytket.passes.FullPeepholeOptimise(allow_swaps: bool = True, target_2qb_gate: pytket.circuit.OpType = OpType.CX) pytket.passes.BasePass
Performs peephole optimisation including resynthesis of 2- and 3-qubit gate sequences, and converts to a circuit containing only the given 2-qubit gate (which may be CX or TK2) and TK1 gates.
- Parameters
allow_swaps – whether to allow implicit wire swaps
- pytket.passes.GlobalisePhasedX(squash: bool = True) pytket.passes.BasePass
Turns all PhasedX and NPhasedX gates into global gates
Replaces any PhasedX gates with global NPhasedX gates. By default, this transform will squash all single-qubit gates to PhasedX and Rz gates before proceeding further. Existing non-global NPhasedX will not be preserved. This is the recommended setting for best performance. If squashing is disabled, each non-global PhasedX gate will be replaced with two global NPhasedX, but any other gates will be left untouched.
- Parameters
squash – Whether to squash the circuit in pre-processing (default: true).
If squash=true (default), the GlobalisePhasedX().apply method will always return true. For squash=false, apply() will return true if the circuit was changed and false otherwise.
It is not recommended to use this pass with symbolic expressions, as in certain cases a blow-up in symbolic expression sizes may occur.
- 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 aCircBox
. 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.
- Returns
a pass to perform the simplification
- pytket.passes.KAKDecomposition(*args, **kwargs)
Overloaded function.
KAKDecomposition(target_2qb_gate: pytket.circuit.OpType = <OpType.CX: 39>, cx_fidelity: float = 1.0, allow_swaps: bool = True) -> pytket.passes.BasePass
Squash sequences of two-qubit operations into minimal form.
Pass to squash together sequences of single- and two-qubit gates into minimal form. Can decompose to TK2 or CX gates.
Two-qubit operations can always be expressed in a minimal form of maximum three CXs, or as a single TK2 gate (a result also known as the KAK or Cartan decomposition).
It is in general recommended to squash to TK2 gates, and to then use the DecomposeTK2 pass for noise-aware decompositions to other gatesets. For backward compatibility, decompositions to CX are also supported. In this case, cx_fidelity can be provided to perform approximate decompositions to CX gates.
When decomposing to TK2 gates, any sequence of two or more two-qubit gates on the same set of qubits are replaced by a single TK2 gate. When decomposing to CX, the substitution is only performed if it results in a reduction of the number of CX gates, or if at least one of the two-qubit gates is not a CX.
Using the allow_swaps=True (default) option, qubits will be swapped when convenient to further reduce the two-qubit gate count (only applicable when decomposing to CX gates).
- Parameters
target_2qb_gate – OpType to decompose to. Either TK2 or CX.
cx_fidelity – Estimated CX gate fidelity, used when target_2qb_gate=CX.
allow_swaps – Whether to allow implicit wire swaps.
KAKDecomposition(cx_fidelity: float) -> pytket.passes.BasePass
- pytket.passes.NaivePlacementPass(arc: pytket.architecture.Architecture) pytket.passes.BasePass
- Parameters
architecture – The Architecture used for relabelling.
- Returns
a pass to relabel
Circuit
Qubits toArchitecture
Nodes
- pytket.passes.NormaliseTK2() pytket.passes.BasePass
Normalises all TK2 gates.
TK2 gates have three angles in the interval [0, 4], but these can always be normalised to be within the so-called Weyl chamber by adding single-qubit gates.
- More precisely, the three angles a, b, c of TK2(a, b, c) are normalised exactly when the two following conditions are met:
numerical values must be in the Weyl chamber, ie 1/2 >= a >= b >= |c|,
symbolic values must come before any numerical value in the array.
After this pass, all TK2 angles will be normalised and the circuit will satisfy NormalisedTK2Predicate.
- 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 and TK1 gates.
- Parameters
cx_config – A configuration of CXs to convert phase gadgets into.
- Returns
a pass to perform the synthesis
- 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.
This pass will not preserve the global phase of the circuit.
- Parameters
strat – A synthesis strategy for the Pauli graph.
cx_config – A configuration of CXs to convert Pauli gadgets into.
- Returns
a pass to perform the simplification
- pytket.passes.PauliSquash(strat: pytket.transform.PauliSynthStrat = PauliSynthStrat.Sets, cx_config: pytket.transform.CXConfigType = CXConfigType.Snake) pytket.passes.BasePass
Applies
PauliSimp()
followed byFullPeepholeOptimise()
.- Parameters
strat – a synthesis strategy for the Pauli graph
cx_config – a configuration of CXs to convert Pauli gadgets into
- Returns
a pass to perform the simplification
- pytket.passes.PeepholeOptimise2Q() pytket.passes.BasePass
Performs peephole optimisation including resynthesis of 2-qubit gate sequences, and converts to a circuit containing only CX and TK1 gates.
- pytket.passes.PlacementPass(placer: pytket.placement.Placement) pytket.passes.BasePass
- Parameters
placer – The Placement used for relabelling.
- Returns
a pass to relabel
Circuit
Qubits toArchitecture
Nodes
- pytket.passes.RebaseCustom(*args, **kwargs)
Overloaded function.
RebaseCustom(gateset: Set[pytket.circuit.OpType], cx_replacement: pytket.circuit.Circuit, tk1_replacement: Callable[[Expression, Expression, Expression], pytket.circuit.Circuit]) -> pytket.passes.BasePass
Construct a custom rebase pass, given user-defined rebases for TK1 and CX. This pass:
decomposes multi-qubit gates not in the set of gate types gateset to CX gates;
if CX is not in gateset, replaces CX gates with cx_replacement;
converts any single-qubit gates not in the gate type set to the form \(\mathrm{Rz}(a)\mathrm{Rx}(b)\mathrm{Rz}(c)\) (in matrix-multiplication order, i.e. reverse order in the circuit);
applies the tk1_replacement function to each of these triples \((a,b,c)\) to generate replacement circuits.
- Parameters
gateset – the allowed operations in the rebased circuit
cx_replacement – the equivalent circuit to replace a CX gate using two qubit gates from the desired basis (can use any single qubit OpTypes)
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
- Returns
a pass that rebases to the given gate set
RebaseCustom(arg0: Set[pytket.circuit.OpType], arg1: Callable[[Expression, Expression, Expression], pytket.circuit.Circuit], arg2: Callable[[Expression, Expression, Expression], pytket.circuit.Circuit]) -> pytket.passes.BasePass
Construct a custom rebase pass, given user-defined rebases for TK1 and TK2. This pass:
decomposes multi-qubit gates not in the set of gate types gateset to TK2 gates;
if TK2 is not in gateset, replaces TK2(a,b,c) gates via the tk2_replacement function;
converts any single-qubit gates not in the gate type set to TK1;
if TK2 is not in gateset. applies the tk1_replacement function to each TK1(a,b,c).
- Parameters
gateset – the allowed operations in the rebased circuit
tk2_replacement – a function which, given the parameters (a,b,c) of an XXPhase(a)YYPhase(b)ZZPhase(c) triple, returns an equivalent circuit in the desired basis
tk1_replacement – a function which, given the parameters (a,b,c) of an Rz(a)Rx(b)Rz(c) triple, returns an equivalent circuit in the desired basis
- Returns
a pass that rebases to the given gate set
- pytket.passes.RebaseTket() pytket.passes.BasePass
Converts all gates to CX and TK1.
- pytket.passes.RemoveBarriers() pytket.passes.BasePass
A pass to remove all barrier instructions from the circuit.
- pytket.passes.RemoveDiscarded() pytket.passes.BasePass
A pass to remove all operations that have no
OpType.Output
orOpType.ClOutput
in their causal future (in other words, all operations whose causal future is discarded).
- 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.
When merging rotations with the same op group name, the mergedoperation keeps the same name.
- pytket.passes.RenameQubitsPass(qubit_map: Dict[pytket.circuit.Qubit, pytket.circuit.Qubit]) pytket.passes.BasePass
- Parameters
qubit_map – map from old to new qubit names
- pytket.passes.RoutingPass(arc: pytket.architecture.Architecture) pytket.passes.BasePass
Construct a pass to route to the connectivity graph of an
Architecture
. Edge direction is ignored. UsesLexiLabellingMethod
andLexiRouteRoutingMethod
. :return: a pass that routes to the given device architecture
- pytket.passes.SimplifyInitial(allow_classical: bool = True, create_all_qubits: bool = False, remove_redundancies: bool = True, xcirc: pytket.circuit.Circuit = None) pytket.passes.BasePass
Simplify the circuit using knowledge of qubit state.
- Parameters
allow_classical – allow replacement of measurements on known state with classical set-bit operations
create_all_qubits – automatically annotate all qubits as initialized to the zero state
remove_redundancies – apply a
RemoveRedundancies()
pass after the initial simplificationxcirc – 1-qubit circuit implementing an X gate in the transformed circuit (if omitted, an X gate is used)
- Returns
a pass to perform the simplification
- pytket.passes.SimplifyMeasured() pytket.passes.BasePass
A pass to replace all ‘classical maps’ followed by measure operations whose quantum output is discarded with classical operations following the measure. (A ‘classical map’ is a quantum operation that acts as a permutation of the computational basis states followed by a diagonal operation.)
- pytket.passes.SquashCustom(singleqs: Set[pytket.circuit.OpType], tk1_replacement: Callable[[Expression, Expression, Expression], pytket.circuit.Circuit]) pytket.passes.BasePass
Squash sequences of single qubit gates from the target gate set into an optimal form given by tk1_replacement.
- Parameters
singleqs – The types of single qubit gates in the target gate set. This pass will only affect sequences of gates that are already in this set.
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.SquashTK1() pytket.passes.BasePass
Squash sequences of single-qubit gates to TK1 gates.
- 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.SynthesiseOQC() pytket.passes.BasePass
Optimises and converts all gates to ECR, Rz and SX.
- pytket.passes.SynthesiseTK() pytket.passes.BasePass
Optimises and converts all gates to TK2 and TK1 gates.
- pytket.passes.SynthesiseTket() pytket.passes.BasePass
Optimises and converts all gates to CX and TK1 gates.
- pytket.passes.SynthesiseUMD() pytket.passes.BasePass
Optimises and converts all gates to XXPhase, PhasedX and Rz.
- pytket.passes.ThreeQubitSquash(allow_swaps: bool = True) pytket.passes.BasePass
Squash three-qubit subcircuits into subcircuits having fewer CX gates, when possible, and apply Clifford simplification.
- Parameters
allow_swaps – whether to allow implicit wire swaps
- pytket.passes.ZZPhaseToRz() pytket.passes.BasePass
Converts ZZPhase gates with angle pi or -pi to two Rz gates withangle pi. :return: a pass to convert ZZPhase gates to Rz
pytket.passes.script
- pytket.passes.script.compilation_pass_from_script(script: str) BasePass
Generate a compilation pass from a specification.
The specification must conform to a simple grammar. For example, the following are valid specifications:
“RemoveRedundancies”
“[RemoveBarriers, RemoveRedundancies]” (a sequence of passes)
“repeat(FullPeepholeOptimise)” (repeat a pass until it doesn’t change the circuit)
Sequences and repeats can be nested arbitrarily. Whitespace is ignored.
Most passes are specified using their Python names. For those that take enums as parameters, non-default values can be specified using their Python names:
“PauliSimp” (default parameters)
“PauliSimp(Pairwise, Tree)”
“EulerAngleReduction(Ry, Rz)”
For some passes with optional boolean parameters the name can be modified as follows:
“CliffordSimp” (default parameters)
“CliffordSimpNoSwaps”
“SimplifyInitial” (default parameters)
“SimplifyInitialNoClassical”
There is currently no support for passes requiring more complex parameters such as lambdas or circuits.
The full formal grammar can be inspected using
compilation_pass_grammar()
.- Parameters
script – specification of pass
pytket.passes.auto_rebase
- pytket.passes.auto_rebase.auto_rebase_pass(gateset: Set[OpType]) RebaseCustom
Attempt to generate a rebase pass automatically for the given target gateset.
Checks if there are known existing decompositions to target gateset and TK1 to target gateset and uses those to construct a custom rebase. Raises an error if no known decompositions can be found, in which case try using RebaseCustom with your own decompositions.
- Parameters
gateset (FrozenSet[OpType]) – Set of supported OpTypes, target gate set.
- Raises
NoAutoRebase – No suitable decomposition found.
- Returns
Rebase pass.
- Return type
RebaseCustom