pytket.predicates

In pytket, predicates enforce properties of circuits. Each pytket Backend has its own set of predicates which must be satisfied before a quantum circuit can be executed. There are predicates that enforce restrictions including gateset, number of qubits and classical control.

For more on predicates read the corresponding section of the user manual. See also the Compilation example notebook.

class pytket._tket.predicates.CliffordCircuitPredicate

Predicate asserting that a circuit has only Clifford gates.

__init__(self: pytket._tket.predicates.CliffordCircuitPredicate) None

Constructor.

class pytket._tket.predicates.CommutableMeasuresPredicate

Predicate asserting that all measurements can be delayed to the end of the circuit.

__init__(self: pytket._tket.predicates.CommutableMeasuresPredicate) None

Constructor.

class pytket._tket.predicates.CompilationUnit

This class comprises a circuit and the predicates that the circuit is required to satisfy, for example to run on a backend.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.predicates.CompilationUnit, circuit: pytket._tket.circuit.Circuit) -> None

Construct from a circuit, with no predicates.

  1. __init__(self: pytket._tket.predicates.CompilationUnit, circuit: pytket._tket.circuit.Circuit, predicates: Sequence[pytket._tket.predicates.Predicate]) -> None

Construct from a circuit and some required predicates.

check_all_predicates(self: pytket._tket.predicates.CompilationUnit) bool
Returns:

True if all predicates are satisfied, else False

property circuit

Return a copy of the circuit.

property final_map

Returns the map from the original qubits to their corresponding qubits at the end of the current circuit.

property initial_map

Returns the map from the original qubits to the corresponding qubits at the start of the current circuit.

class pytket._tket.predicates.ConnectivityPredicate

Predicate asserting that a circuit satisfies a given connectivity graph. The graph is always considered to be undirected.

__init__(self: pytket._tket.predicates.ConnectivityPredicate, architecture: pytket._tket.architecture.Architecture) None

Construct from an Architecture.

class pytket._tket.predicates.DefaultRegisterPredicate

Predicate asserting that a circuit only uses the default quantum and classical registers.

__init__(self: pytket._tket.predicates.DefaultRegisterPredicate) None

Constructor.

class pytket._tket.predicates.DirectednessPredicate

Predicate asserting that a circuit satisfies a given connectivity graph. The graph is always considered to be directed.

__init__(self: pytket._tket.predicates.DirectednessPredicate, architecture: pytket._tket.architecture.Architecture) None

Construct from an Architecture.

class pytket._tket.predicates.GateSetPredicate

Predicate asserting that all operations are in the specified set of types.

Note that the following are always permitted and do not need to be included in the specified set:

  • ‘meta’ operations (inputs, outputs, barriers);

  • OpType.Phase gates (which have no input or output wires).

Classically conditioned operations are permitted provided that the conditioned operation is of a permitted type.

__init__(self: pytket._tket.predicates.GateSetPredicate, allowed_types: set[pytket._tket.circuit.OpType]) None

Construct from a set of gate types.

class pytket._tket.predicates.MaxNClRegPredicate

Predicate asserting that a circuit has at most n classical registers.

__init__(self: pytket._tket.predicates.MaxNClRegPredicate, arg0: int) None

Constructor.

class pytket._tket.predicates.MaxNQubitsPredicate

Predicate asserting that a circuit has at most n qubits.

__init__(self: pytket._tket.predicates.MaxNQubitsPredicate, arg0: int) None

Constructor.

class pytket._tket.predicates.MaxTwoQubitGatesPredicate

Predicate asserting that a circuit has no gates with more than two input wires.

__init__(self: pytket._tket.predicates.MaxTwoQubitGatesPredicate) None

Constructor.

class pytket._tket.predicates.NoBarriersPredicate

Predicate asserting that a circuit contains no Barrier operations.

__init__(self: pytket._tket.predicates.NoBarriersPredicate) None

Constructor.

class pytket._tket.predicates.NoClassicalBitsPredicate

Predicate asserting that a circuit has no classical wires.

__init__(self: pytket._tket.predicates.NoClassicalBitsPredicate) None

Constructor.

class pytket._tket.predicates.NoClassicalControlPredicate

Predicate asserting that a circuit has no classical controls.

__init__(self: pytket._tket.predicates.NoClassicalControlPredicate) None

Constructor.

class pytket._tket.predicates.NoFastFeedforwardPredicate

Predicate asserting that a circuit has no fast feedforward.

__init__(self: pytket._tket.predicates.NoFastFeedforwardPredicate) None

Constructor.

class pytket._tket.predicates.NoMidMeasurePredicate

Predicate asserting that all measurements occur at the end of the circuit.

__init__(self: pytket._tket.predicates.NoMidMeasurePredicate) None

Constructor.

class pytket._tket.predicates.NoSymbolsPredicate

Predicate asserting that no gates in the circuit have symbolic parameters.

__init__(self: pytket._tket.predicates.NoSymbolsPredicate) None

Constructor.

class pytket._tket.predicates.NoWireSwapsPredicate

Predicate asserting that a circuit has no wire swaps.

__init__(self: pytket._tket.predicates.NoWireSwapsPredicate) None

Constructor.

class pytket._tket.predicates.NormalisedTK2Predicate

Asserts that all TK2 gates are normalised

A gate TK2(a, b, c) is considered normalised if

  • If all expressions are non symbolic, then it must hold 0.5 ≥ a ≥ b ≥ |c|.

  • In the ordering (a, b, c), any symbolic expression must appear before non-symbolic ones. The remaining non-symbolic expressions must still be ordered in non-increasing order and must be in the interval [0, 1/2], with the exception of the last one that may be in [-1/2, 1/2].

__init__(self: pytket._tket.predicates.NormalisedTK2Predicate) None

Constructor.

class pytket._tket.predicates.PlacementPredicate

Predicate asserting that a circuit has been acted on by some Placement object.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket._tket.predicates.PlacementPredicate, architecture: pytket._tket.architecture.Architecture) -> None

Construct from an Architecture.

  1. __init__(self: pytket._tket.predicates.PlacementPredicate, nodes: set[pytket._tket.unit_id.Node]) -> None

Construct from a set of Node.

class pytket._tket.predicates.Predicate

A predicate that may be satisfied by a circuit.

__init__(*args, **kwargs)
static from_dict(arg0: dict) pytket._tket.predicates.Predicate

Construct Predicate instance from JSON serializable dict representation of the Predicate.

implies(self: pytket._tket.predicates.Predicate, other: pytket._tket.predicates.Predicate) bool
Returns:

True if predicate implies another one, else False

to_dict(self: pytket._tket.predicates.Predicate) dict

Return a JSON serializable dict representation of the Predicate.

Returns:

dict representation of the Predicate.

verify(self: pytket._tket.predicates.Predicate, circuit: pytket._tket.circuit.Circuit) bool
Returns:

True if circuit satisfies predicate, else False

class pytket._tket.predicates.UserDefinedPredicate

User-defined predicate.

__init__(self: pytket._tket.predicates.UserDefinedPredicate, check_function: Callable[[pytket._tket.circuit.Circuit], bool]) None

Construct from a user-defined function from Circuit to bool.