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 Passs 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 passes that defines the default compiler which is used when no custom list of Passs is provided:

import trueq as tq

tq.Compiler.HARDWARE_PASSES
(trueq.compilation.two_qubit.Native2Q,
 trueq.compilation.common.Merge,
 trueq.compilation.one_qubit.Native1Q,
 trueq.compilation.common.InvolvingRestrictions,
 trueq.compilation.common.RemoveEmptyCycle)

Each item in the list above is one of True-Q™’s built-in Passs. Notice that RemoveId is applied twice; this is because the passes 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 pass takes a circuit, applies an operation, and returns an altered circuit. Details of how this functions can be found in Compiler.

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

trueq.compilation.CompilePaulis

Pass which adds randomly-chosen Pauli gates before all measurements in the circuit.

trueq.compilation.CycleReplacement

Pass that searches Circuits for a specific Cycle and when found, replaces it with a list of provided cycles.

trueq.compilation.InvolvingRestrictions

A pass which ensures that any NativeGate which is defined from a list of GateFactorys obeys the involving restrictions of the GateFactorys.

trueq.compilation.Justify

Pass that moves operations forward in time.

trueq.compilation.MarkBlocks

Pass that marks cycles which contain multi-qubit gates if none of the existing non-measurement cycles in the circuit have been marked with non-zero values.

trueq.compilation.MarkCycles

Pass that marks cycles which contain multi-qubit gates if none of the existing cycles in the circuit have been marked with non-zero values.

trueq.compilation.Merge

Pass that takes a list of cycles, finds compatabile labels and gates, and merges them to a single gate as much as is possible.

trueq.compilation.Native1Q

A NCyclePass which iteratively attempts to decompose one-qubit gates into gates which are performable by the given list of GateFactorys.

trueq.compilation.Native1QMode

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

trueq.compilation.Native1QRRZ

An OperationReplacement 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.Native2Q

A NCyclePass which iteratively attempts to decompose two-qubit gates into gates which are performable by the given list of GateFactorys.

trueq.compilation.Native2QCX

An OperationReplacement 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 OperationReplacement which checks if a given operation is a two-qubit gate that is equal to some static GateFactory in the provided list of GateFactorys up to single qubit operations, and if so, switch the Gate with a NativeGate built from the factory list plus the approriate single qubit gates.

trueq.compilation.NativeDecomp

An OperationReplacement which attempts to decompose the target gate using the specified number of gates found in the provided list of GateFactorys.

trueq.compilation.NativeExact

An OperationReplacement which checks if the specified gate can be generated directly from a single output of a single factory present in the GateFactory list with an appropriate choice of parameter values, and if so, replaces a Gate with the NativeGate.

trueq.compilation.OneQuditDecomp

A pass which decomposes cycles of arbitrary single-qudit gates into alternations of cycles of native gates with diagonal gates.

trueq.compilation.Parallel

A NCyclePass that splits a cycle into individual operations, passes the operations to provided OperationReplacements in parallel, and recombines the output into a list of cycles.

trueq.compilation.PhaseTrack

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

trueq.compilation.RCCycle

Pass which performs Randomized Compilation (RC) on groups of cycles with matching marker values by adding gates on either side of the cycles, chosen using the provided Twirl.

trueq.compilation.RCLocal

Pass which performs Randomized Compilation (RC) on groups of cycles with matching marker values by adding gates on either side of the cycles.

trueq.compilation.Relabel

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

trueq.compilation.RemarkCycles

Pass that remarks all the marked cycles.

trueq.compilation.RemoveEmptyCycle

Pass which removes empty cycles from groups of cycles with matching markers.

trueq.compilation.RemoveId

Pass that removes single qubit identity gates from one Cycle.

trueq.compilation.TryInOrder

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

trueq.compilation.UnmarkCycles

Pass which sets all cycle markers to 0.