Commit 6e693db2 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding projectq plugin


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 52d56b14
Pipeline #33445 passed with stage
in 8 minutes and 23 seconds
......@@ -12,4 +12,5 @@ include_directories(${XACC_INCLUDE_DIRS})
add_subdirectory(ibm)
add_subdirectory(rigetti)
add_subdirectory(vqe)
add_subdirectory(dwave)
\ No newline at end of file
add_subdirectory(dwave)
add_subdirectory(projectq)
\ No newline at end of file
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/ir/instructions)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/utils)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/ir)
add_subdirectory(compiler)
if(XACC_BUILD_TESTS)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler)
add_subdirectory(tests)
endif()
\ No newline at end of file
#***********************************************************************************
# Copyright (c) 2016, UT-Battelle
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the xacc nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Contributors:
# Initial API and implementation - Alex McCaskey
# ANTLR compiler implementation - H. Charles Zhao
#
#**********************************************************************************/
set (PACKAGE_NAME "ProjectQ XACC Compiler")
set (PACKAGE_DESCIPTION "ProjectQ XACC Compiler Bundle")
set (LIBRARY_NAME xacc-projectq-compiler)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp generated/*.cpp)
include_directories(generated)
# Set up dependencies to resources to track changes
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
# Generate bundle initialization code
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)
add_library(${LIBRARY_NAME} SHARED ${SRC})
set(_bundle_name xacc_projectq_compiler)
set_target_properties(${LIBRARY_NAME} PROPERTIES
# This is required for every bundle
COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
# This is for convenience, used by other CMake functions
US_BUNDLE_NAME ${_bundle_name}
)
# Embed meta-data from a manifest.json file
usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
FILES
manifest.json
)
target_link_libraries(${LIBRARY_NAME} xacc xacc-quantum-gate ${CMAKE_SOURCE_DIR}/dist/libantlr4-runtime.so)
if(APPLE)
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared")
endif()
install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
/***********************************************************************************
* Copyright (c) 2018, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Originally developed by:
* H. Charles Zhao, Oak Ridge National Laboratory, July 2018
*
**********************************************************************************/
grammar ProjectQ;
/* This part of the grammar is particular to XACC */
/**********************************************************************************/
xaccsrc : (NEWLINE* xacckernel NEWLINE*)* ;
xacckernel : '__qpu__' kernelname=IDENTIFIER '(' 'AcceleratorBuffer' acceleratorbuffer=IDENTIFIER (',' typedparam)* ')' '{' projectqprog '}' ;
kernelcall : kernelname=IDENTIFIER '(' IDENTIFIER? (',' IDENTIFIER)* ')' ;
typedparam : TYPE IDENTIFIER ;
TYPE : INTTYPE | DOUBLETYPE | FLOATTYPE ;
fragment INTTYPE : 'int' ;
fragment DOUBLETYPE : 'double';
fragment FLOATTYPE : 'float' ;
/**********************************************************************************/
/********************
* Parser *
*******************/
projectqprog : instr? (NEWLINE+ instr)* NEWLINE* ;
instr : gate
| allocate
| measure
| kernelcall
;
gate : gatename paramlist? '|' qbitarglist ;
gatename : IDENTIFIER ;
allocate : ALLOCATE '|' qbit ;
measure : MEASURE '|' qbit ;
paramlist : '(' param (',' param)* ')' ;
param : expr ;
qbitarglist : qbit
| '(' qbit (',' qbit)* ')'
;
qbit : qreg '[' INT ('-' INT)? ']' ;
qreg : QREG ;
expr : '(' expr ')'
| '-' expr
| expr POWER expr
| expr (TIMES | DIVIDE) expr
| expr (PLUS | MINUS) expr
| real
| IDENTIFIER
;
real : INT
| FLOAT
;
/********************
* Lexer *
*******************/
QREG : 'Qureg' ;
ALLOCATE : 'Allocate' ;
MEASURE : 'Measure' ;
IDENTIFIER : [A-Za-z_] [A-Za-z0-9_]* ;
INT : DIGIT+ ;
FLOAT : INT EXPONENT
| DIGIT* '.' DIGIT+ EXPONENT?
;
PLUS : '+' ;
MINUS : '-' ;
TIMES : '*' ;
DIVIDE : '/' ;
POWER : '^' ;
NEWLINE : ('\r'? '\n') ;
SPACE : ' ' -> skip ;
TAB : '\t' -> skip ;
fragment SIGN : '+' | '-' ;
fragment DIGIT : [0-9]+ ;
fragment EXPONENT : ('e' | 'E') SIGN? [0-9]+ ;
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
* ANTLR compiler implementation - H. Charles Zhao
*
**********************************************************************************/
#include "ProjectQCompiler.hpp"
#include "IRProvider.hpp"
#include "ProjectQLexer.h"
#include "ProjectQParser.h"
#include "XACC.hpp"
#include "ProjectQToXACCListener.hpp"
#include "ProjectQErrorListener.hpp"
using namespace projectq;
using namespace antlr4;
namespace xacc {
namespace quantum {
ProjectQCompiler::ProjectQCompiler() = default;
std::shared_ptr<IR> ProjectQCompiler::compile(const std::string &src,
std::shared_ptr<Accelerator> acc) {
accelerator = acc;
return compile(src);
}
std::shared_ptr<IR> ProjectQCompiler::compile(const std::string &src) {
ANTLRInputStream input(src);
ProjectQLexer lexer(&input);
CommonTokenStream tokens(&lexer);
ProjectQParser parser(&tokens);
parser.removeErrorListeners();
parser.addErrorListener(new ProjectQErrorListener());
auto ir(xacc::getService<IRProvider>("gate")->createIR());
tree::ParseTree *tree(parser.xaccsrc());
ProjectQToXACCListener listener(ir);
tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
return ir;
}
const std::string ProjectQCompiler::translate(const std::string &bufferVariable,
std::shared_ptr<Function> function) {
return "";
}
}
}
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#ifndef IMPLS_PROJECTQ_PROJECTQCOMPILER_HPP_
#define IMPLS_PROJECTQ_PROJECTQCOMPILER_HPP_
#include "Compiler.hpp"
#include "Utils.hpp"
#include <boost/algorithm/string.hpp>
namespace xacc {
namespace quantum {
/**
*/
class ProjectQCompiler: public xacc::Compiler {
public:
ProjectQCompiler();
/**
* Translate Quil to the
* XACC intermediate representation.
*
* @return ir XACC intermediate representation
*/
virtual std::shared_ptr<xacc::IR> compile(const std::string& src,
std::shared_ptr<Accelerator> acc);
/**
*
* @param src
* @return
*/
virtual std::shared_ptr<xacc::IR> compile(const std::string& src);
/**
* This produces a Quil source code representation of the
* given IR Function
*
* @param function The XACC IR Function to translate
* @return src The source code as a string
*/
virtual const std::string translate(const std::string& bufferVariable,
std::shared_ptr<Function> function);
virtual const std::string name() const {
return "projectq-qasm";
}
virtual const std::string description() const {
return "";
}
/**
* The destructor
*/
virtual ~ProjectQCompiler() {}
};
}
}
#endif
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
#include "cppmicroservices/ServiceProperties.h"
#include <memory>
#include <set>
#include "ProjectQCompiler.hpp"
using namespace cppmicroservices;
namespace {
/**
*/
class US_ABI_LOCAL ProjectQCompilerActivator: public BundleActivator {
public:
ProjectQCompilerActivator() {
}
/**
*/
void Start(BundleContext context) {
auto c = std::make_shared<xacc::quantum::ProjectQCompiler>();
context.RegisterService<xacc::Compiler>(c);
context.RegisterService<xacc::OptionsProvider>(c);
}
/**
*/
void Stop(BundleContext /*context*/) {
}
};
}
CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(ProjectQCompilerActivator)
/***********************************************************************************
* Copyright (c) 2018, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial implementation - H. Charles Zhao
*
**********************************************************************************/
#ifndef XACC_PROJECTQ_ERRORLISTENER_HPP
#define XACC_PROJECTQ_ERRORLISTENER_HPP
using namespace antlr4;
class ProjectQErrorListener : public BaseErrorListener {
public:
void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, size_t charPositionInLine,
const std::string &msg, std::exception_ptr e) override {
std::ostringstream output;
output << "Invalid ProjectQ source: ";
output << "line " << line << ":" << charPositionInLine << " " << msg;
xacc::error(output.str());
}
};
#endif //XACC_PROJECTQ_ERRORLISTENER_HPP
/***********************************************************************************
* Copyright (c) 2018, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial implementation - H. Charles Zhao
*
**********************************************************************************/
#include <boost/math/constants/constants.hpp>
#include "ProjectQBaseListener.h"
#include "exprtk.hpp"
#include "XACC.hpp"
#include "IRProvider.hpp"
#include "IR.hpp"
#include "ProjectQToXACCListener.hpp"
using namespace projectq;
using symbol_table_t = exprtk::symbol_table<double>;
using expression_t = exprtk::expression<double>;
using parser_t = exprtk::parser<double>;
namespace xacc {
namespace quantum {
constexpr static double pi = boost::math::constants::pi<double>();
ProjectQToXACCListener::ProjectQToXACCListener(std::shared_ptr<xacc::IR> ir) : ir(ir) {
gateRegistry = xacc::getService<IRProvider>("gate");
}
double evalMathExpression(const std::string &expression) {
symbol_table_t symbol_table;
symbol_table.add_constant("pi", pi);
expression_t expr;
expr.register_symbol_table(symbol_table);
parser_t parser;
parser.compile(expression, expr);
return expr.value();
}
InstructionParameter strToParam(const std::string &str) {
double num = evalMathExpression(str);
if (std::isnan(num)) {
return InstructionParameter(str);
} else {
return InstructionParameter(num);
}
}
void ProjectQToXACCListener::enterXacckernel(projectq::ProjectQParser::XacckernelContext *ctx) {
std::vector<InstructionParameter> params;
for (int i = 0; i < ctx->typedparam().size(); i++) {
params.push_back(InstructionParameter(ctx->typedparam(static_cast<size_t>(i))->IDENTIFIER()->getText()));
}
curFunc = gateRegistry->createFunction(ctx->kernelname->getText(), {}, params);
functions.insert({curFunc->name(), curFunc});
}
void ProjectQToXACCListener::exitXacckernel(projectq::ProjectQParser::XacckernelContext *ctx) {
ir->addKernel(curFunc);
}
void ProjectQToXACCListener::exitKernelcall(projectq::ProjectQParser::KernelcallContext *ctx) {
std::string gateName = ctx->kernelname->getText();
if (functions.count(gateName)) {
curFunc->addInstruction(functions[gateName]);
} else {
xacc::error("Tried calling an undefined kernel.");
}
}
void ProjectQToXACCListener::exitGate(projectq::ProjectQParser::GateContext *ctx) {
std::string gateName = ctx->gatename()->getText();
if (gateName == "CX") gateName = "CNOT";
std::vector<std::shared_ptr<xacc::Instruction>> instructions;
std::shared_ptr<xacc::Instruction> instruction;