MLIR Passes v1.0
Loading...
Searching...
No Matches
QASMToQuake.hpp
Go to the documentation of this file.
1/* This code and any associated documentation is provided "as is"
2
3Copyright 2024 Munich Quantum Software Stack Project
4
5Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the
6"License"); you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9https://github.com/Munich-Quantum-Software-Stack/passes/blob/develop/LICENSE
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14License for the specific language governing permissions and limitations under
15the License.
16
17SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
18******************************************************************************
19 author Martin Letras
20 date May 2025
21 version 1.0
22******************************************************************************/
33#pragma once
34
35#include "Constants.hpp"
36#include "ir/parsers/qasm3_parser/Parser.hpp"
37#include "ir/parsers/qasm3_parser/Statement.hpp"
38#include "ir/parsers/qasm3_parser/Types.hpp"
39#include "mlir/Pass/Pass.h"
40#include "mlir/Pass/PassManager.h"
41#include "mlir/Pass/PassRegistry.h"
42
43using namespace mlir;
52using QASMVectorToQuakeVector = std::unordered_map<std::string, mlir::Value>;
53
60using QuantumVectorsOrder = std::vector<std::pair<std::string, int>>;
61
62namespace mqss::interfaces {
63
80void insertQASMGateIntoQuakeModule(std::string gateId, OpBuilder &builder,
81 Location loc,
82 std::vector<mlir::Value> vecParams,
83 std::vector<mlir::Value> vecControls,
84 std::vector<mlir::Value> vecTargets,
85 bool adj);
86
94bool isMultiQubitGate(const std::string &gateType);
95
103size_t getNumControls(const std::string &gateType);
104
111double evaluateExpression(const std::shared_ptr<qasm3::Expression> &expr);
112
128void insertGate(const std::shared_ptr<qasm3::GateCallStatement> &gateCall,
129 OpBuilder &builder, Location loc, mlir::Operation *inOp,
130 QASMVectorToQuakeVector QASMToVectors);
131
148 const std::vector<std::shared_ptr<qasm3::Statement>> &statements,
149 OpBuilder &builder, Location loc, mlir::Operation *inOp,
150 QASMVectorToQuakeVector QASMToVectors);
151
175std::tuple<QASMVectorToQuakeVector, QuantumVectorsOrder> insertAllocatedQubits(
176 const std::vector<std::shared_ptr<qasm3::Statement>> &program,
177 OpBuilder &builder, Location loc, mlir::Operation *inOp);
178} // namespace mqss::interfaces
size_t getNumControls(const std::string &gateType)
Given a gate type as a string, this functions returns the number of control outputs associated with t...
void 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 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 build...
double evaluateExpression(const std::shared_ptr< qasm3::Expression > &expr)
Function that evaluates a numeric expression in the AST.
std::vector< std::pair< std::string, int > > QuantumVectorsOrder
The QuantumVectorsOrder is list of pairs. Each entry of the pair is composed of a string that is the ...
Definition QASMToQuake.hpp:60
void 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, QuantumVectorsOrder > 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 progra...
bool isMultiQubitGate(const std::string &gateType)
Given a gate type as a string, this functions checks if the given gate type has control outputs.
std::unordered_map< std::string, mlir::Value > QASMVectorToQuakeVector
The QASMVectorToQuakeVector is a map of type std::unordered_map<std::string, mlir::Value>....
Definition QASMToQuake.hpp:52