MLIR Passes v1.0
Loading...
Searching...
No Matches
CudaQ Transpiler

CudaQ offers also a transpiler infrastructure that is used by nvq++ quantum compiler. Transpilation can also be handled using MLIR passes as follows:

First, extract the MLIR context and define an MLIR PassManager as follows:

auto [mlirModule, contextPtr] = extractMLIRContext(quakeModule);
mlir::MLIRContext &context = *contextPtr;
// creating pass manager
mlir::PassManager pm(&context);

Next, define a BasisConversionPassOptions object and pass to it a list of gates to be considered as the native gate set. The transpiler will use the defined native gate set to try to apply decomposition passes. For instance, the following native gate set {"h", "s", "t", "rx", "ry", "rz", "x", "y", "z", "x(1)"} is specified.

cudaq::opt::BasisConversionPassOptions options;
options.basis = {"h", "s", "t", "rx", "ry", "rz", "x", "y", "z", "x(1)"};

Next, add a cudaq::opt::createBasisConversionPass to the pass manager. Do not forget to pass options as input parameter of cudaq::opt::createDecompositionPass, as follows:

pm.addPass(createBasisConversionPass(options));

Finally, you can dump and visualize the effects of running the transpiler on your MLIR module as follows:

// running the pass
if(mlir::failed(pm.run(mlirModule)))
std::runtime_error("The pass failed...");
// if pass is applied successfully ...
std::cout << "Circuit after pass:\n";
mlirModule->dump();

The following circuit will be used as a test case. The following section shows the transpiled circuit for IQM.

Input

IQM

The IQM backend supports the following gates: "phased_rx","z(1)". For the sake of clarity, just fragments of the transpiled circuit are shown.

1)

Fragment 1

2)

Fragment 2

...

n)

Fragment 3