Class cudaq_ir_converter

Inheritance Relationships

Base Type

  • public xacc::quantum::AllGateVisitor

Class Documentation

class cudaq_ir_converter : public xacc::quantum::AllGateVisitor

Utility class to perform XACC IR -> CUDAQ Quake IR (MLIR-based) conversion. This is performed by implementing an AllGateVisitor and constructing the corresponding Quake IR node using CUDAQ’s kernel_builder utility. This can also handle (classical) argument conversion (parameterized quantum circuit). Notes: (1) XACC IR (CompositeInstruction) only accepts a single kernel argument of type: double or std::vector<double>. Quake IR (MLIR) can accepts a much wider range of types and not limit the number of arguments. (2) The argument evaluation is XACC IR is very rudimentary. (based on the C++ Mathematical Expression Parsing And Evaluation Library, https://github.com/ArashPartow/exprtk) Hence, we need to do a ‘hacky’ conversion into QUAKE IR only supporting scaling (by multiplication) an argument in a rotation angle. e.g., Ry(0.1234*theta, q[0]), where theta is a parameterized angle bound to argument ‘theta’.

Public Functions

cudaq_ir_converter(std::shared_ptr<xacc::CompositeInstruction> xacc_ir)

Constructor.

Taking the root XACC IR node of a kernel and construct the corresponding CUDAQ kernel_builder by visiting all the child nodes.

Parameters:

xacc_ir – Input XACC IR

cudaq::kernel_builder<std::vector<double>> &get_cudaq_builder()

Get a reference to the constructed CUDAQ kernel_builder, e.g., to feed it to CUDAQ runtime (execution/vqe, etc.)

Returns:

CUDAQ kernel_builder

void visit(xacc::quantum::Hadamard &h) override

Hadamard gate.

void visit(xacc::quantum::X &x) override

Pauli X gate.

void visit(xacc::quantum::Y &y) override

Pauli Y gate.

void visit(xacc::quantum::Z &z) override

Pauli Z gate.

void visit(xacc::quantum::S &s) override

S gate.

void visit(xacc::quantum::Sdg &sdg) override

Inverse S gate.

void visit(xacc::quantum::T &t) override

T gate.

void visit(xacc::quantum::Tdg &tdg) override

Inverse T gate.

void visit(xacc::quantum::CNOT &cnot) override

Controlled NOT gate.

void visit(xacc::quantum::CZ &cz) override

Controlled Z gate.

void visit(xacc::quantum::CH &ch) override

Controlled Hadamard gate.

void visit(xacc::quantum::Rx &rx) override

Rotation about x axis.

void visit(xacc::quantum::Ry &ry) override

Rotation about y axis.

void visit(xacc::quantum::Rz &rz) override

Rotation about z axis.

void visit(xacc::quantum::CPhase &cphase) override

Controlled phase (aka u1) gate.

void visit(xacc::quantum::Swap &swap) override

Swap gate.

void visit(xacc::quantum::iSwap &iswap) override

iSwap gate

void visit(xacc::quantum::CY &cy) override

Controlled Y gate.

void visit(xacc::quantum::CRZ &crz) override

Controlled Rz gate.

void visit(xacc::quantum::U1 &u1) override

U1 gate (equivalent to Rz up to a global phase)

void visit(xacc::quantum::U &u3) override

U3 gate.

void visit(xacc::quantum::Reset &reset) override

Reset gate.

Private Functions

std::pair<double, std::string> get_mul_factor_expression(const std::string &expr_str)

Helper to parse expression of type <constant> * <var_name> This can handle the no explicit constant multiplication in the expression (constant = 1.0)

Parameters:

expr_str – Input expression string

Returns:

<constant> and <var_name> pair

cudaq::QuakeValue instruction_variable_to_quake(const xacc::InstructionParameter &xacc_var)

Helper to convert an instruction variable to a QuakeValue, aka, a CUDAQ kernel variable.

Private Members

cudaq::kernel_builder<std::vector<double>> m_cudaq_builder

Underlying CUDAQ kernel_builder.

cudaq::QuakeValue m_cudaq_qreg

Qubit register in Quake IR.

std::vector<std::string> m_var_names

List of argument names in the XACC IR.

std::shared_ptr<xacc::ExpressionParsingUtil> m_parsing_util

XACC expression parsing utility to handle string-based rotation angles (parameterized).