Commit d8fc5aa5 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Renaming AlgorithmGenerator to IRGenerator, updating its api to take InstructionParameters (#66)


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 4a33898c
...@@ -42,8 +42,8 @@ public: ...@@ -42,8 +42,8 @@ public:
auto kp = auto kp =
std::make_shared<xacc::quantum::KernelReplacementPreprocessor>(); std::make_shared<xacc::quantum::KernelReplacementPreprocessor>();
context.RegisterService<xacc::Preprocessor>(kp); context.RegisterService<xacc::Preprocessor>(kp);
context.RegisterService<xacc::AlgorithmGenerator>(iqft); context.RegisterService<xacc::IRGenerator>(iqft);
context.RegisterService<xacc::AlgorithmGenerator>(qft); context.RegisterService<xacc::IRGenerator>(qft);
} }
/** /**
......
...@@ -18,7 +18,9 @@ namespace xacc { ...@@ -18,7 +18,9 @@ namespace xacc {
namespace quantum { namespace quantum {
std::shared_ptr<Function> InverseQFT::generateAlgorithm(std::vector<int> qubits) { std::shared_ptr<Function> InverseQFT::generate(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters) {
// Create a function to return // Create a function to return
auto retFunction = std::make_shared<GateFunction>("inverse_qft"); auto retFunction = std::make_shared<GateFunction>("inverse_qft");
...@@ -26,7 +28,7 @@ std::shared_ptr<Function> InverseQFT::generateAlgorithm(std::vector<int> qubits) ...@@ -26,7 +28,7 @@ std::shared_ptr<Function> InverseQFT::generateAlgorithm(std::vector<int> qubits)
// Generate the QFT algorithm and get the // Generate the QFT algorithm and get the
// individual instructions // individual instructions
QFT qft; QFT qft;
auto qftFunction = qft.generateAlgorithm(qubits); auto qftFunction = qft.generate(buffer, parameters);
auto instructions = qftFunction->getInstructions(); auto instructions = qftFunction->getInstructions();
// Reverse those instructions // Reverse those instructions
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#ifndef QUANTUM_GATE_IR_ALGORITHMS_INVERSEQFT_HPP_ #ifndef QUANTUM_GATE_IR_ALGORITHMS_INVERSEQFT_HPP_
#define QUANTUM_GATE_IR_ALGORITHMS_INVERSEQFT_HPP_ #define QUANTUM_GATE_IR_ALGORITHMS_INVERSEQFT_HPP_
#include "AlgorithmGenerator.hpp" #include "IRGenerator.hpp"
namespace xacc{ namespace xacc{
namespace quantum { namespace quantum {
...@@ -23,17 +23,23 @@ namespace quantum { ...@@ -23,17 +23,23 @@ namespace quantum {
* interface that produces an XACC IR representation * interface that produces an XACC IR representation
* of the Inverse Quantum Fourier Transform. * of the Inverse Quantum Fourier Transform.
*/ */
class InverseQFT : public AlgorithmGenerator { class InverseQFT : public IRGenerator {
public: public:
/** /**
* This implementation returns a Function IR representation * Implementations of this method generate a Function IR
* of the inverse quantum fourier transform. * instance corresponding to the implementation's modeled
* algorithm. The algorithm is specified to operate over the
* provided AcceleratorBuffer and can take an optional
* vector of InstructionParameters.
* *
* @param bits The bits this algorithm operates on * @param bits The bits this algorithm operates on
* @return function The algorithm represented as an IR Function * @return function The algorithm represented as an IR Function
*/ */
virtual std::shared_ptr<Function> generateAlgorithm(std::vector<int> qubits); virtual std::shared_ptr<Function> generate(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters = std::vector<
InstructionParameter> { });
virtual const std::string name() const { virtual const std::string name() const {
return "InverseQFT"; return "InverseQFT";
......
...@@ -18,7 +18,9 @@ namespace xacc { ...@@ -18,7 +18,9 @@ namespace xacc {
namespace quantum { namespace quantum {
std::shared_ptr<Function> QFT::generateAlgorithm(std::vector<int> qubits) { std::shared_ptr<Function> QFT::generate(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters) {
auto bitReversal = auto bitReversal =
[](std::vector<int> qubits) -> std::vector<std::shared_ptr<Instruction>> { [](std::vector<int> qubits) -> std::vector<std::shared_ptr<Instruction>> {
...@@ -86,6 +88,12 @@ std::shared_ptr<Function> QFT::generateAlgorithm(std::vector<int> qubits) { ...@@ -86,6 +88,12 @@ std::shared_ptr<Function> QFT::generateAlgorithm(std::vector<int> qubits) {
} }
}; };
auto bufferSize = buffer->size();
std::vector<int> qubits;
for (int i = 0; i < bufferSize; i++) {
qubits.push_back(i);
}
auto qftInstructions = coreqft(qubits); auto qftInstructions = coreqft(qubits);
auto swaps = bitReversal(qubits); auto swaps = bitReversal(qubits);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#ifndef QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_ #ifndef QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_
#define QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_ #define QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_
#include "AlgorithmGenerator.hpp" #include "IRGenerator.hpp"
namespace xacc{ namespace xacc{
namespace quantum { namespace quantum {
...@@ -25,17 +25,23 @@ namespace quantum { ...@@ -25,17 +25,23 @@ namespace quantum {
* *
* @author Alex McCaskey * @author Alex McCaskey
*/ */
class QFT : public AlgorithmGenerator { class QFT : public IRGenerator {
public: public:
/** /**
* This implementation returns a Function IR representation * Implementations of this method generate a Function IR
* of the quantum fourier transform. * instance corresponding to the implementation's modeled
* algorithm. The algorithm is specified to operate over the
* provided AcceleratorBuffer and can take an optional
* vector of InstructionParameters.
* *
* @param bits The bits this algorithm operates on * @param bits The bits this algorithm operates on
* @return function The algorithm represented as an IR Function * @return function The algorithm represented as an IR Function
*/ */
virtual std::shared_ptr<Function> generateAlgorithm(std::vector<int> qubits); virtual std::shared_ptr<Function> generate(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters = std::vector<
InstructionParameter> { });
virtual const std::string name() const { virtual const std::string name() const {
return "QFT"; return "QFT";
......
...@@ -25,7 +25,9 @@ BOOST_AUTO_TEST_CASE(checkCreation) { ...@@ -25,7 +25,9 @@ BOOST_AUTO_TEST_CASE(checkCreation) {
auto iqft = std::make_shared<InverseQFT>(); auto iqft = std::make_shared<InverseQFT>();
auto iqftKernel = iqft->generateAlgorithm(std::vector<int>{0,1,2}); auto buffer = std::make_shared<AcceleratorBuffer>("",3);
auto iqftKernel = iqft->generate(buffer);
auto ir = std::make_shared<GateQIR>(); auto ir = std::make_shared<GateQIR>();
ir->addKernel(iqftKernel); ir->addKernel(iqftKernel);
......
...@@ -25,7 +25,8 @@ BOOST_AUTO_TEST_CASE(checkCreation) { ...@@ -25,7 +25,8 @@ BOOST_AUTO_TEST_CASE(checkCreation) {
auto qft = std::make_shared<QFT>(); auto qft = std::make_shared<QFT>();
auto qftKernel = qft->generateAlgorithm(std::vector<int>{0,1,2}); auto buffer = std::make_shared<AcceleratorBuffer>("",3);
auto qftKernel = qft->generate(buffer);
auto ir = std::make_shared<GateQIR>(); auto ir = std::make_shared<GateQIR>();
ir->addKernel(qftKernel); ir->addKernel(qftKernel);
......
...@@ -10,21 +10,24 @@ ...@@ -10,21 +10,24 @@
* Contributors: * Contributors:
* Alexander J. McCaskey - initial API and implementation * Alexander J. McCaskey - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#ifndef IR_ALGORITHMS_ALGORITHMGENERATOR_HPP_ #ifndef IR_IRGENERATOR_HPP_
#define IR_ALGORITHMS_ALGORITHMGENERATOR_HPP_ #define IR_IRGENERATOR_HPP_
#include "AcceleratorBuffer.hpp"
#include "Function.hpp" #include "Function.hpp"
#include "Identifiable.hpp" #include "Identifiable.hpp"
#include <vector>
#include <memory>
namespace xacc { namespace xacc {
/** /**
* The AlgorithmGenerator interface provides a mechanism for * The IRGenerator interface provides a mechanism for
* generating algorithms modeled as an XACC Function instance. * generating common algorithms modeled as an XACC Function instance.
* *
* @author Alex McCaskey * @author Alex McCaskey
*/ */
class __attribute__((visibility("default"))) AlgorithmGenerator : public Identifiable { class IRGenerator : public Identifiable {
public: public:
...@@ -32,17 +35,21 @@ public: ...@@ -32,17 +35,21 @@ public:
* Implementations of this method generate a Function IR * Implementations of this method generate a Function IR
* instance corresponding to the implementation's modeled * instance corresponding to the implementation's modeled
* algorithm. The algorithm is specified to operate over the * algorithm. The algorithm is specified to operate over the
* provided bits. * provided AcceleratorBuffer and can take an optional
* vector of InstructionParameters.
* *
* @param bits The bits this algorithm operates on * @param bits The bits this algorithm operates on
* @return function The algorithm represented as an IR Function * @return function The algorithm represented as an IR Function
*/ */
virtual std::shared_ptr<Function> generateAlgorithm(std::vector<int> bits) = 0; virtual std::shared_ptr<Function> generate(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters = std::vector<
InstructionParameter> { }) = 0;
/** /**
* The destructor * The destructor
*/ */
virtual ~AlgorithmGenerator() {} virtual ~IRGenerator() {}
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment