TKET Quantum Compiler

repository·main·Indexed 43 days ago

https://github.com/quantinuum/tket

A high-performance quantum compiler designed to optimize circuits for various quantum computing architectures. It features a high-speed C++ core (tket) and a comprehensive Python API (pytket) for circuit construction, optimization, and hardware execution.

Tokens
27.8K
Snippets
75
Records
151
Agent score
55%

What's inside TKET

  1. Use the pytket.circuit_library module for gate decompositions

    main

    The pytket.circuit_library module provides methods for generating small circuits, primarily used to represent one gate in terms of others. This is useful for custom decomposition logic, such as within the .passes.AutoRebase pass.

    The library is organized into four main categories:

    1. Exact multi-qubit gate decompositions: Decomposes multi-qubit gates into other multi-qubit gates (allowing any single-qubit gates). Some methods may trade approximation error for reduced gate costs.
    2. Approximate multi-qubit gate decompositions: Provides decompositions that may involve approximation error to achieve lower gate costs.
    3. Single-qubit gate decompositions: Decomposes single-qubit gates into specific universal gatesets. These are typically intended to be run after multi-qubit gates have been decomposed.
    4. Constant circuits: Returns small, fixed circuits consisting of 1-3 gates (e.g., standard gates like X, CX, or CCX).

    Parameters for the gates being decomposed are passed directly as arguments to the respective methods.

  2. Key features of the WSM solver

    main

    The WSM solver provides several controls for managing the search process:

    • Timeouts and Iteration Limits: You can specify a timeout in milliseconds or an exact maximum number of iterations (useful for reproducible testing).
    • Resumable Solving: If the solver terminates due to a timeout or reaching the maximum iteration count, you can retain the solver object and resume the search later.
    • Early Termination: You can configure the solver to terminate immediately upon finding the first valid solution. This is particularly efficient for unweighted (standard subgraph monomorphism) problems.
    • Optimality Guarantees: If the solver terminates without hitting a timeout or iteration limit, it is guaranteed to have either found the optimal solution or proved that no solution exists (unless early termination was explicitly enabled).
  3. Use pytket.zx for ZX calculus operations

    main

    The pytket.zx module provides tools for working with ZX calculus, including diagram manipulation, rewriting, and generators. Key components include:

    • ZXDiagram: The primary object representing a ZX diagram. It allows for adding vertices, wires, and boxes, as well as querying the diagram's structure (e.g., n_vertices, n_wires, get_boundary).
    • ZXBox: Represents a box within a diagram, characterized by its diagram, n_ports, and signature.
    • Rewrite: A class used to apply various ZX rewriting rules to a diagram, such as spider_fusion, rebase_to_zx, and reduce_graphlike_form.
    • ZXGen: A base class for generating ZX diagrams.
    • CliffordGen, DirectedGen, and PhasedGen: Specific generators for creating different types of ZX structures.
    • Flow: Used for analyzing flows within a diagram (e.g., identify_pauli_flow, identify_causal_flow).

    You can convert a standard circuit to a ZX diagram using pytket.zx.circuit_to_zx.

  4. Use pytket.backends components for quantum execution

    main

    The pytket.backends module provides the following core components for managing quantum jobs and results:

    • Backend: The base interface for all quantum devices and simulators.
    • ResultHandle: A handle used to track and retrieve the results of a submitted job.
    • BackendResult and StoredResult: Objects representing the data returned from a quantum execution.
    • CircuitStatus and StatusEnum: Used to check the current state of a job or circuit execution.
    • BackendInfo: Provides metadata about the backend, such as its connectivity (e.g., via fully_connected_backendinfo).
  5. What is a pytket Backend and how does it work?

    main

    In pytket, a Backend is an abstract class that serves as the interface between pytket and a quantum device or simulator. While the core Backend class is defined in the main library, specific implementations for different hardware and simulators are provided via various pytket extension modules. All extension backends inherit from this core Backend class.

    If you need to develop your own custom backend or a new pytket extension, refer to the creating backends tutorial.

  6. What is Weighted Subgraph Monomorphism (WSM)?

    main

    Weighted Subgraph Monomorphism (WSM) is a problem where, given a pattern graph $P$ and a target graph $T$, you must find an injective function $f: V(P) o V(T)$ that maps vertices of $P$ to vertices of $T$ such that if two vertices are adjacent in $P$, their mapped counterparts are adjacent in $T$.

    In the Weighted version, every edge in both $P$ and $T$ has an integer weight $w \ge 0$. The goal is to find a monomorphism $f$ that minimizes the scalar product $S(f)$:

    $$S(f) = \sum_{e \in E(P)} w(e) \cdot w(f(e))$$

    Applications in Qubit Routing:

    • Pattern Graph ($P$): Represents the interaction graph between logical qubits in a quantum circuit.
    • Target Graph ($T$): Represents the interaction graph of the physical hardware.
    • Weighting Strategy:
      • $P$-edge weights can be adjusted to prioritize certain interactions (e.g., those occurring earlier in a circuit).
      • $T$-edge weights can reflect hardware fidelity.
      • Extra target edges can be added to allow for 'near-miss' mappings, which can then be resolved using SWAP gates.
  7. Use classical logic expressions in pytket

    main
    The pytket.circuit.logic_exp module provides tools for defining and working with classical logic expressions within a circuit. These expressions allow for complex conditional logic that can be used to control the execution of quantum gates or other classical operations.
  8. What are pytket passes and how do they differ from Transforms?

    main

    In pytket, compilation passes are used to perform in-place transformations of circuits. While they are conceptually similar to Transforms, passes provide additional capabilities including:

    • Predicate checking: The ability to check specific conditions before or after a transformation.
    • Compositionality: Advanced ways to combine multiple passes into complex workflows.

    Common use cases for passes include general-purpose circuit optimization, converting circuits to specific gatesets (rebasing), and targeting specific structures like phase gadgets or Pauli gadgets.

  9. System requirements and compatibility for pytket

    main

    Ensure your system meets the following requirements to avoid receiving outdated versions or installation failures:

    • Python Version: As of release 1.24.0, Python 3.10 or above is required for the latest version.
    • Operating System (MacOS): As of release 1.34.0, MacOS 13 or above is required. MacOS 12 is no longer supported.
    • Operating System (Windows): Versions 0.6 and above are compatible with most recent Windows versions. Note that LTSC versions of Windows are not supported.
    • Pip Version: Wheels are built for pip version 20.0.0+.
    • Conda on MacOS: There is a known issue installing versions newer than 1.11.0 in a conda environment on MacOS. The recommended remedy is to use an official Python distribution instead.
  10. What are pytket predicates and how are they used

    main

    In pytket, predicates are tools used to enforce specific properties on quantum circuits. Each pytket.Backend has its own set of predicates that a circuit must satisfy before it can be executed on that specific hardware or simulator.

    Predicates are commonly used to enforce restrictions such as:

    • Gate sets: Ensuring only supported gates are used.
    • Qubit counts: Limiting the number of qubits in a circuit.
    • Classical control: Restricting or allowing classical bits and control logic.
    • Connectivity: Ensuring gates are applied to compatible qubits.

    You can use the CompilationUnit class to manage a collection of predicates and verify them against a circuit.

  11. Understand qubit placement in pytket

    main

    Qubit placement is the process of assigning device-independent (program) qubits to specific device qubits to satisfy the constraints of a Backend. This module provides several methods to perform this assignment, which is a prerequisite for solving backend constraints during circuit compilation.

    There are three primary placement strategies available in pytket.placement:

    1. GraphPlacement: Uses the connectivity graph of the device.
    2. LinePlacement: Maps qubits onto a linear chain.
    3. NoiseAwarePlacement: Considers device noise profiles when assigning qubits.

    For more detailed information on mapping and routing, refer to the qubit mapping and routing tutorial.

  12. How the Token Swapping Algorithms work

    main

    The library uses a distance-based approach where $L$ is the sum of distances of each token from its final destination. The goal is to reduce $L$ to zero using as few swaps as possible.

    Algorithmic Classes

    • BestFullTsa: The main end-to-end mapping. It uses HybridTsa to find a solution and then applies SwapListOptimiser, SwapListSegmentOptimiser, and SwapListTableOptimiser to reduce the total number of swaps.
    • HybridTsa: A hybrid approach that runs CyclesPartialTsa whenever possible. If it gets stuck, it switches to TrivialTSA. It switches back to CyclesPartialTsa as soon as TrivialTSA manages to decrease $L$.
    • CyclesPartialTsa: A cycle-finding class that constructs "concrete" paths in the graph to perform "abstract" cyclic shifts. It is not guaranteed to find a complete sequence on its own.
    • TrivialTSA: A fallback algorithm that guarantees a solution by decomposing the desired permutation into disjoint cycles and then decomposing those into concrete swaps via paths. It is guaranteed to work but is generally less efficient than cycle-based methods.
    • RiverFlowPathFinder: A utility used by TrivialTSA to compute paths. It deliberately overlaps paths to facilitate better optimization later.