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:
auto kp =
std::make_shared<xacc::quantum::KernelReplacementPreprocessor>();
context.RegisterService<xacc::Preprocessor>(kp);
context.RegisterService<xacc::AlgorithmGenerator>(iqft);
context.RegisterService<xacc::AlgorithmGenerator>(qft);
context.RegisterService<xacc::IRGenerator>(iqft);
context.RegisterService<xacc::IRGenerator>(qft);
}
/**
......
......@@ -18,7 +18,9 @@ namespace xacc {
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
auto retFunction = std::make_shared<GateFunction>("inverse_qft");
......@@ -26,7 +28,7 @@ std::shared_ptr<Function> InverseQFT::generateAlgorithm(std::vector<int> qubits)
// Generate the QFT algorithm and get the
// individual instructions
QFT qft;
auto qftFunction = qft.generateAlgorithm(qubits);
auto qftFunction = qft.generate(buffer, parameters);
auto instructions = qftFunction->getInstructions();
// Reverse those instructions
......
......@@ -13,7 +13,7 @@
#ifndef QUANTUM_GATE_IR_ALGORITHMS_INVERSEQFT_HPP_
#define QUANTUM_GATE_IR_ALGORITHMS_INVERSEQFT_HPP_
#include "AlgorithmGenerator.hpp"
#include "IRGenerator.hpp"
namespace xacc{
namespace quantum {
......@@ -23,17 +23,23 @@ namespace quantum {
* interface that produces an XACC IR representation
* of the Inverse Quantum Fourier Transform.
*/
class InverseQFT : public AlgorithmGenerator {
class InverseQFT : public IRGenerator {
public:
/**
* This implementation returns a Function IR representation
* of the inverse quantum fourier transform.
* Implementations of this method generate a Function IR
* 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
* @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 {
return "InverseQFT";
......
......@@ -18,7 +18,9 @@ namespace xacc {
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 =
[](std::vector<int> qubits) -> std::vector<std::shared_ptr<Instruction>> {
......@@ -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 swaps = bitReversal(qubits);
......
......@@ -13,7 +13,7 @@
#ifndef QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_
#define QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_
#include "AlgorithmGenerator.hpp"
#include "IRGenerator.hpp"
namespace xacc{
namespace quantum {
......@@ -25,17 +25,23 @@ namespace quantum {
*
* @author Alex McCaskey
*/
class QFT : public AlgorithmGenerator {
class QFT : public IRGenerator {
public:
/**
* This implementation returns a Function IR representation
* of the quantum fourier transform.
* Implementations of this method generate a Function IR
* 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
* @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 {
return "QFT";
......
......@@ -25,7 +25,9 @@ BOOST_AUTO_TEST_CASE(checkCreation) {
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>();
ir->addKernel(iqftKernel);
......
......@@ -25,7 +25,8 @@ BOOST_AUTO_TEST_CASE(checkCreation) {
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>();
ir->addKernel(qftKernel);
......
......@@ -10,21 +10,24 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#ifndef IR_ALGORITHMS_ALGORITHMGENERATOR_HPP_
#define IR_ALGORITHMS_ALGORITHMGENERATOR_HPP_
#ifndef IR_IRGENERATOR_HPP_
#define IR_IRGENERATOR_HPP_
#include "AcceleratorBuffer.hpp"
#include "Function.hpp"
#include "Identifiable.hpp"
#include <vector>
#include <memory>
namespace xacc {
/**
* The AlgorithmGenerator interface provides a mechanism for
* generating algorithms modeled as an XACC Function instance.
* The IRGenerator interface provides a mechanism for
* generating common algorithms modeled as an XACC Function instance.
*
* @author Alex McCaskey
*/
class __attribute__((visibility("default"))) AlgorithmGenerator : public Identifiable {
class IRGenerator : public Identifiable {
public:
......@@ -32,17 +35,21 @@ public:
* Implementations of this method generate a Function IR
* instance corresponding to the implementation's modeled
* 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
* @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
*/
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