MLIR Passes v1.0
Loading...
Searching...
No Matches
QASMToQuake.hpp File Reference

Go to the source code of this file.

Typedefs

using QASMVectorToQuakeVector = std::unordered_map<std::string, mlir::Value>
 The QASMVectorToQuakeVector is a map of type std::unordered_map<std::string, mlir::Value>. The key is a string corresponding to a quantum vector declared in the QASM program and the value corresponds to an mlir::Value associated to a created and inserted quake::veq.
 
using QuantumVectorsOrder = std::vector<std::pair<std::string, int>>
 The QuantumVectorsOrder is list of pairs. Each entry of the pair is composed of a string that is the id in the AST associated to the quantum vector and the int value is the number of qubits in the register.
 

Functions

void mqss::interfaces::insertQASMGateIntoQuakeModule (std::string gateId, OpBuilder &builder, Location loc, std::vector< mlir::Value > vecParams, std::vector< mlir::Value > vecControls, std::vector< mlir::Value > vecTargets, bool adj)
 Given a gate type as a string, this functions inserts the corresponding Quake gate in the given builder.
 
bool mqss::interfaces::isMultiQubitGate (const std::string &gateType)
 Given a gate type as a string, this functions checks if the given gate type has control outputs.
 
size_t mqss::interfaces::getNumControls (const std::string &gateType)
 Given a gate type as a string, this functions returns the number of control outputs associated with the given gate type.
 
double mqss::interfaces::evaluateExpression (const std::shared_ptr< qasm3::Expression > &expr)
 Function that evaluates a numeric expression in the AST.
 
void mqss::interfaces::insertGate (const std::shared_ptr< qasm3::GateCallStatement > &gateCall, OpBuilder &builder, Location loc, mlir::Operation *inOp, QASMVectorToQuakeVector QASMToVectors)
 This function inserts a gate into a MLIR/Quake module.
 
void mqss::interfaces::parseAndInsertMeasurements (const std::vector< std::shared_ptr< qasm3::Statement > > &statements, OpBuilder &builder, Location loc, mlir::Operation *inOp, QASMVectorToQuakeVector QASMToVectors)
 This function inserts measurements into a MLIR/Quake module.
 
std::tuple< QASMVectorToQuakeVector, QuantumVectorsOrdermqss::interfaces::insertAllocatedQubits (const std::vector< std::shared_ptr< qasm3::Statement > > &program, OpBuilder &builder, Location loc, mlir::Operation *inOp)
 This function return the quantum vectors and its order, given a Abstract Syntax Tree of a QASM program.
 

Detailed Description

This header defines a set of functions utilized to parse QASM circuits to MLIR/Quake modules.

This header file is used by the QASM3ToQuakePass to perform the conversion of QASM programs to MLIR/Quake modules.

Function Documentation

◆ evaluateExpression()

double mqss::interfaces::evaluateExpression ( const std::shared_ptr< qasm3::Expression > & expr)

Function that evaluates a numeric expression in the AST.

Parameters
[in]expris as qasm3 numeric expression.
Returns
a double value associated with the input numeric expression.

◆ getNumControls()

size_t mqss::interfaces::getNumControls ( const std::string & gateType)

Given a gate type as a string, this functions returns the number of control outputs associated with the given gate type.

Parameters
[in]gateTypeis a string specifying the type a quantum gate.
Returns
the number of control outputs of the give gate type.

◆ insertAllocatedQubits()

std::tuple< QASMVectorToQuakeVector, QuantumVectorsOrder > mqss::interfaces::insertAllocatedQubits ( const std::vector< std::shared_ptr< qasm3::Statement > > & program,
OpBuilder & builder,
Location loc,
mlir::Operation * inOp )

This function return the quantum vectors and its order, given a Abstract Syntax Tree of a QASM program.

This function receives an AST of QASM program, and create a quake::veq for each quantum register declared in the QASM program. Moreover, returns the order of appearance of each quantum register.

Parameters
[in]programis the AST of a QASM program.
[out]builderis an OpBuilder object associated with a MLIR module. It is used to insert new instructions (quantum registers) to the corresponding MLIR module.
[in]locis the location of the new inserted instruction (quantum registers).
[in]inOpis the return operation in the module associated to the builder. New instructions are inserted before thereturn operation.
Returns
a tuple composed of QASMVectorToQuakeVector and std::vector<std::pair<std::string, int>>. The QASMVectorToQuakeVector is a map of type std::unordered_map<std::string, mlir::Value>. The key is a string corresponding to a quantum vector declared in the QASM program and the value corresponds to an mlir::Value associated to a created and inserted quake::veq. The second argument of the tuple is a vector that preserves the order of the inserted quake::veq, each entry is pair storing the quantum vector id, and the size of the quantum vector.

◆ insertGate()

void mqss::interfaces::insertGate ( const std::shared_ptr< qasm3::GateCallStatement > & gateCall,
OpBuilder & builder,
Location loc,
mlir::Operation * inOp,
QASMVectorToQuakeVector QASMToVectors )

This function inserts a gate into a MLIR/Quake module.

The QASM to Quake parser invokes this function to insert each gate in the AST.

Parameters
[in]gateCallis qasm3 gate declaration.
[out]builderis an OpBuilder object associated with a MLIR module. It is used to insert new instructions (quantum registers) to the corresponding MLIR module.
[in]locis the location of the new inserted instruction (quantum registers).
[in]inOpis the return operation in the module associated to the builder. New instructions are inserted before thereturn operation.
[in]QASMToVectorsmap that returns a mlir::Value associated to a declared quantum vector, given the QASM quantum vector declaration.

◆ insertQASMGateIntoQuakeModule()

void mqss::interfaces::insertQASMGateIntoQuakeModule ( std::string gateId,
OpBuilder & builder,
Location loc,
std::vector< mlir::Value > vecParams,
std::vector< mlir::Value > vecControls,
std::vector< mlir::Value > vecTargets,
bool adj )

Given a gate type as a string, this functions inserts the corresponding Quake gate in the given builder.

This method inserts a quake operation into an MLIR module associated with the builder passed as parameter.

Parameters
[in]gateIdis a string specifying the type of the quantum gate to be inserted.
[out]builderis an OpBuilder object associated with a MLIR module. It is used to insert new instructions to the corresponding MLIR module.
[in]locis the location of the new inserted instruction.
[in]vecParamsis the vector of arguments of the gate to be inserted, e.g., rotation angles in rotation gates.
[in]vecControlsis the vector of control qubits.
[in]vecTargetsis the vector of target qubits.
[in]adjdetermines is the gate is an adjoint operation.

◆ isMultiQubitGate()

bool mqss::interfaces::isMultiQubitGate ( const std::string & gateType)

Given a gate type as a string, this functions checks if the given gate type has control outputs.

Parameters
[in]gateTypeis a string specifying the type of a quantum gate.
Returns
true if a gate is a multi-qubit gate with implicit controls.

◆ parseAndInsertMeasurements()

void mqss::interfaces::parseAndInsertMeasurements ( const std::vector< std::shared_ptr< qasm3::Statement > > & statements,
OpBuilder & builder,
Location loc,
mlir::Operation * inOp,
QASMVectorToQuakeVector QASMToVectors )

This function inserts measurements into a MLIR/Quake module.

The QASM to Quake parser invokes this function to insert measurements into a given MLIR/Quake module.

Parameters
[in]statementsis qasm3 measurements declarations.
[out]builderis an OpBuilder object associated with a MLIR module. It is used to insert new instructions (quantum registers) to the corresponding MLIR module.
[in]locis the location of the new inserted instruction (quantum registers).
[in]inOpis the return operation in the module associated to the builder. New instructions are inserted before thereturn operation.
[in]QASMToVectorsmap that returns a mlir::Value associated to a declared quantum vector, given the QASM quantum vector declaration.