Compiler

Two common issues that come up when attempting to run an algorithm on specific hardware platforms include:

  1. Gates inside of theoretical circuits are not directly compatible with the hardware’s native gateset.

  2. Gates or circuits are specified as unitary matrices, rather than specific gate decompositions.

If True-Q™ has access to the configuration of the system, it is possible to solve both of these issues. Our compilation tools take a circuit and rewrite it using only the gates and connections specified in a given device configuration file.

../../_images/transpilation.svg

Note

The same circuit can be transpiled for implementation on any number of hardware devices. Below we show an example of this.

How it Works

True-Q™ has a number of compilation tools which rely upon device-specific configurations. The compilation tools work by applying an ordered list of built-in and/or user-specified Patterns to a circuit in order, see (Compiler for more details).

To give a feel for what a compiler definition looks like, here is the list of patterns that defines the default compiler which is used when no custom list of Patterns is provided:

import trueq as tq
tq.compilation.DEFAULT_PATTERNS
(trueq.compilation.two_qubit.Native2Q,
 trueq.compilation.common.Justify,
 trueq.compilation.common.Merge,
 trueq.compilation.common.RemoveId,
 trueq.compilation.common.RemoveEmptyCycle,
 trueq.compilation.one_qubit.Native1Q,
 functools.partial(<class 'trueq.compilation.common.RemoveId'>, skip_immutable=False),
 trueq.compilation.common.InvolvingRestrictions,
 trueq.compilation.common.RemoveEmptyCycle)

Each item in the list above is one of True-Q™’s built-in Patterns. Notice that RemoveId is applied twice; this is because the patterns in a compiler are applied sequentially and in the order listed above it is possible that new identity gates may have appeared between the first application of RemoveId and the second.

Each pattern takes a specific number of cycles, applies an operation to them, and returns an altered list of cycles. Details of how this functions can be found in Compiler.

Here are the premade Patterns available for use with the compiler:

trueq.compilation.CycleSandwich

Pattern that searches Circuits for a specific Cycle and when found, sandwiches it between two other (optional) cycles.

trueq.compilation.InvolvingRestrictions

A pattern which ensures that any NativeGate that is defined from a Config obeys the involving restrictions of its GateFactorys.

trueq.compilation.Justify

Pattern that takes two Cycles, and moves gates preferentially to one side.

trueq.compilation.Merge

Pattern that takes two cycles, finds compatabile labels and gates, then merges them to a single gate as much as is possible.

trueq.compilation.Native1Q

A Pattern which iteratively attempts to decompose one-qubit gates into gates which are performable by the given Config.

trueq.compilation.Native1QRRZ

An OperationPattern which decomposes single qubit gates into 3 gates \(R(\theta) R(\phi) Z(\gamma)\), where the R gates are defined by \(Z(\theta) X(90) Z(-\theta)\) in time.

trueq.compilation.Native1QMode

An OperationPattern which expands arbitrary single qubit gates into the decomposition mode provided in a given Config.

trueq.compilation.Native1QUGates

An OperationPattern which decomposes single qubit gates into U1, U2, or U3 gates found inside of the provided Config.

trueq.compilation.Native2Q

A Pattern which iteratively attempts to decompose two-qubit gates into gates which are performable by the given Config.

trueq.compilation.Native2QCX

An OperationPattern which decomposes any SU(4) into a gate which is locally equivalent to CNOT, as long as such a gate exists inside of the given Config.

trueq.compilation.Native2QKAK

An OperationPattern which checks if a given operation is a two-qubit gate that is equal to some static GateFactory in the provided Config up to single qubit operations, and if so, switch the Gate with a NativeGate from the config plus the approriate single qubit gates.

trueq.compilation.Native2QFastDecomp

An OperationPattern which attempts to decompose the provided gate up to a given depth using gates found in the provided Config.

trueq.compilation.NativeExact

Checks to see if each gate is present in the provided Config exactly as defined, and if so, switch the Gate with a NativeGate from the config.

trueq.compilation.Parallel

A Pattern that splits a cycle into individual operations, passes the operations to other patterns in parallel, and recombines the output into a list of cycles.

trueq.compilation.PhaseTrack

This pattern tracks phase accumulation on each qubit throughout a circuit, and compiles this phase information into parametric gates.

trueq.compilation.Relabel

Pattern which relabels all the labels and keys in a Circuit.

trueq.compilation.RemoveEmptyCycle

Pattern which accepts one cycle and only returns it if it’s not empty.

trueq.compilation.RemoveId

Pattern that removes single qubit identity gates from 1 Cycle.

trueq.compilation.TryInOrder

An OperationPattern where a list of OperationPatterns is stored, and each is attempted in order until no CompilationError is raised.

Examples

../../_images/sphx_glr_compiler_thumb1.png

Compiler: Converting to a Gateset

../../_images/sphx_glr_phase_tracking_thumb1.png

Phase Tracking with the Compiler

../../_images/sphx_glr_synthesis_thumb1.png

Gate synthesis