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.predicates.CliffordCircuitPredicate

Predicate asserting that a circuit has only Clifford gates.

__init__(self: pytket.predicates.CliffordCircuitPredicate) None

Constructor.

class pytket.predicates.CommutableMeasuresPredicate

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

__init__(self: pytket.predicates.CommutableMeasuresPredicate) None

Constructor.

class pytket.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.predicates.CompilationUnit, circuit: pytket.circuit.Circuit) -> None

Construct from a circuit, with no predicates.

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

Construct from a circuit and some required predicates.

check_all_predicates(self: pytket.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.predicates.ConnectivityPredicate

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

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

Construct from an Architecture.

class pytket.predicates.DefaultRegisterPredicate

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

__init__(self: pytket.predicates.DefaultRegisterPredicate) None

Constructor.

class pytket.predicates.DirectednessPredicate

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

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

Construct from an Architecture.

class pytket.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.predicates.GateSetPredicate, allowed_types: set[pytket.circuit.OpType]) None

Construct from a set of gate types.

class pytket.predicates.MaxNClRegPredicate

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

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

Constructor.

class pytket.predicates.MaxNQubitsPredicate

Predicate asserting that a circuit has at most n qubits.

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

Constructor.

class pytket.predicates.MaxTwoQubitGatesPredicate

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

__init__(self: pytket.predicates.MaxTwoQubitGatesPredicate) None

Constructor.

class pytket.predicates.NoBarriersPredicate

Predicate asserting that a circuit contains no Barrier operations.

__init__(self: pytket.predicates.NoBarriersPredicate) None

Constructor.

class pytket.predicates.NoClassicalBitsPredicate

Predicate asserting that a circuit has no classical wires.

__init__(self: pytket.predicates.NoClassicalBitsPredicate) None

Constructor.

class pytket.predicates.NoClassicalControlPredicate

Predicate asserting that a circuit has no classical controls.

__init__(self: pytket.predicates.NoClassicalControlPredicate) None

Constructor.

class pytket.predicates.NoFastFeedforwardPredicate

Predicate asserting that a circuit has no fast feedforward.

__init__(self: pytket.predicates.NoFastFeedforwardPredicate) None

Constructor.

class pytket.predicates.NoMidMeasurePredicate

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

__init__(self: pytket.predicates.NoMidMeasurePredicate) None

Constructor.

class pytket.predicates.NoSymbolsPredicate

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

__init__(self: pytket.predicates.NoSymbolsPredicate) None

Constructor.

class pytket.predicates.NoWireSwapsPredicate

Predicate asserting that a circuit has no wire swaps.

__init__(self: pytket.predicates.NoWireSwapsPredicate) None

Constructor.

class pytket.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.predicates.NormalisedTK2Predicate) None

Constructor.

class pytket.predicates.PlacementPredicate

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

__init__(*args, **kwargs)

Overloaded function.

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

Construct from an Architecture.

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

Construct from a set of Node.

class pytket.predicates.Predicate

A predicate that may be satisfied by a circuit.

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

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

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

True if predicate implies another one, else False

to_dict(self: pytket.predicates.Predicate) dict

Return a JSON serializable dict representation of the Predicate.

Returns:

dict representation of the Predicate.

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

True if circuit satisfies predicate, else False

class pytket.predicates.UserDefinedPredicate

User-defined predicate.

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

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