Commit 764ba1da authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

saving work done on removing gate registry, this branch is broken


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 420a6ea4
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
virtual std::shared_ptr<Function> getKernel(const std::string& name) { virtual std::shared_ptr<Function> getKernel(const std::string& name) {
std::shared_ptr<Function> ret; std::shared_ptr<Function> ret;
for (auto f : kernels) { for (auto f : kernels) {
if (f->getName() == name) { if (f->name() == name) {
ret = f; ret = f;
} }
} }
...@@ -120,7 +120,7 @@ public: ...@@ -120,7 +120,7 @@ public:
virtual bool kernelExists(const std::string& name) { virtual bool kernelExists(const std::string& name) {
return std::any_of(kernels.cbegin(), kernels.cend(), return std::any_of(kernels.cbegin(), kernels.cend(),
[=](std::shared_ptr<Function> i) {return i->getName() == name;}); [=](std::shared_ptr<Function> i) {return i->name() == name;});
} }
virtual void mapBits(std::vector<int> bitMap) { virtual void mapBits(std::vector<int> bitMap) {
......
...@@ -26,7 +26,7 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc ...@@ -26,7 +26,7 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc
// Get number of qubits, add 2*nqubit measurement kernels, add readout-error tag to each // Get number of qubits, add 2*nqubit measurement kernels, add readout-error tag to each
int nQubits = 0;//std::stoi(xacc::getOption("n-qubits")); //ir.maxBit() + 1; int nQubits = 0;//std::stoi(xacc::getOption("n-qubits")); //ir.maxBit() + 1;
auto gateRegistry = GateInstructionRegistry::instance(); auto gateRegistry = xacc::getService<InstructionService>("gate");
// Get the true number of qubits // Get the true number of qubits
...@@ -83,9 +83,9 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc ...@@ -83,9 +83,9 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc
auto bit = reversedQubitMap[pauli->bits()[0]]; auto bit = reversedQubitMap[pauli->bits()[0]];
qubits.insert(bit); qubits.insert(bit);
if (pauli->getName() == "H") { if (pauli->name() == "H") {
termMap.insert( { bit, "X" }); termMap.insert( { bit, "X" });
} else if (pauli->getName() == "Rx") { } else if (pauli->name() == "Rx") {
termMap.insert( { bit, "Y" }); termMap.insert( { bit, "Y" });
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#define QUANTUM_GATE_IR_READOUTERRORIRPREPROCESSOR_HPP_ #define QUANTUM_GATE_IR_READOUTERRORIRPREPROCESSOR_HPP_
#include "IRPreprocessor.hpp" #include "IRPreprocessor.hpp"
#include "InstructionService.hpp"
namespace xacc { namespace xacc {
namespace quantum { namespace quantum {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "QFT.hpp" #include "QFT.hpp"
#include "GateInstruction.hpp" #include "GateInstruction.hpp"
#include "GateFunction.hpp" #include "GateFunction.hpp"
#include "XACC.hpp"
namespace xacc { namespace xacc {
...@@ -21,13 +22,14 @@ namespace quantum { ...@@ -21,13 +22,14 @@ namespace quantum {
std::shared_ptr<Function> QFT::generate( std::shared_ptr<Function> QFT::generate(
std::shared_ptr<AcceleratorBuffer> buffer, std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters) { std::vector<InstructionParameter> parameters) {
auto gateRegistry = xacc::getService<InstructionService>("gate");
auto bitReversal = auto bitReversal =
[](std::vector<int> qubits) -> std::vector<std::shared_ptr<Instruction>> { [&](std::vector<int> qubits) -> std::vector<std::shared_ptr<Instruction>> {
std::vector<std::shared_ptr<Instruction>> swaps; std::vector<std::shared_ptr<Instruction>> swaps;
auto endStart = qubits.size() - 1; auto endStart = qubits.size() - 1;
for (auto i = 0; i < std::floor(qubits.size() / 2.0); ++i) { for (auto i = 0; i < std::floor(qubits.size() / 2.0); ++i) {
swaps.push_back(GateInstructionRegistry::instance()->create("Swap", std::vector<int> {qubits[i], qubits[endStart]})); swaps.push_back(gateRegistry->create("Swap", std::vector<int> {qubits[i], qubits[endStart]}));
endStart--; endStart--;
} }
...@@ -46,7 +48,7 @@ std::shared_ptr<Function> QFT::generate( ...@@ -46,7 +48,7 @@ std::shared_ptr<Function> QFT::generate(
// just return a hadamard, if not, // just return a hadamard, if not,
// then we need to build up some cphase gates // then we need to build up some cphase gates
if (qubits.size() == 1) { if (qubits.size() == 1) {
auto hadamard = GateInstructionRegistry::instance()->create("H", std::vector<int> {q}); auto hadamard = gateRegistry->create("H", std::vector<int> {q});
return std::vector<std::shared_ptr<Instruction>> {hadamard}; return std::vector<std::shared_ptr<Instruction>> {hadamard};
} else { } else {
...@@ -57,13 +59,13 @@ std::shared_ptr<Function> QFT::generate( ...@@ -57,13 +59,13 @@ std::shared_ptr<Function> QFT::generate(
auto n = 1 + qs.size(); auto n = 1 + qs.size();
// Build up a list of cphase gates // Build up a list of cphase gates
std::vector<std::shared_ptr<GateInstruction>> cphaseGates; std::vector<std::shared_ptr<Instruction>> cphaseGates;
int idx = 0; int idx = 0;
for (int i = n-1; i > 0; --i) { for (int i = n-1; i > 0; --i) {
auto q_idx = qs[idx]; auto q_idx = qs[idx];
auto angle = 3.1415926 / std::pow(2, n - i); auto angle = 3.1415926 / std::pow(2, n - i);
InstructionParameter p(angle); InstructionParameter p(angle);
auto cp = GateInstructionRegistry::instance()->create("CPhase", std::vector<int> {q, q_idx}); auto cp = gateRegistry->create("CPhase", std::vector<int> {q, q_idx});
cp->setParameter(0, p); cp->setParameter(0, p);
cphaseGates.push_back(cp); cphaseGates.push_back(cp);
idx++; idx++;
...@@ -81,7 +83,7 @@ std::shared_ptr<Function> QFT::generate( ...@@ -81,7 +83,7 @@ std::shared_ptr<Function> QFT::generate(
} }
// add a final hadamard... // add a final hadamard...
insts.push_back(GateInstructionRegistry::instance()->create("H", std::vector<int> {q})); insts.push_back(gateRegistry->create("H", std::vector<int> {q}));
// and return // and return
return insts; return insts;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#define QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_ #define QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_
#include "IRGenerator.hpp" #include "IRGenerator.hpp"
#include "InstructionService.hpp"
namespace xacc{ namespace xacc{
namespace quantum { namespace quantum {
...@@ -49,7 +50,7 @@ public: ...@@ -49,7 +50,7 @@ public:
virtual const std::string description() const { virtual const std::string description() const {
return "The QFT Algorithm Generator generates IR representing " return "The QFT Algorithm Generator generates IR representing "
"an Quantum Fourier Transform."; "a Quantum Fourier Transform.";
} }
/** /**
......
...@@ -22,17 +22,6 @@ CNOT::CNOT(std::vector<int> qbits) : ...@@ -22,17 +22,6 @@ CNOT::CNOT(std::vector<int> qbits) :
CNOT::CNOT(int srcqbit, int tgtqbit) : CNOT::CNOT(int srcqbit, int tgtqbit) :
CNOT(std::vector<int> { srcqbit, tgtqbit }) { CNOT(std::vector<int> { srcqbit, tgtqbit }) {
} }
//
//void CNOT::accept(std::shared_ptr<InstructionVisitor> visitor) {
// auto v = std::dynamic_pointer_cast<GateInstructionVisitor>(visitor);
// if (v) {
// v->visit(*this);
// } else {
// visitor->visit(*this);
// }
//}
RegisterGateInstruction<CNOT> CNOTTEMP("CNOT");
} }
} }
...@@ -23,9 +23,22 @@ namespace quantum { ...@@ -23,9 +23,22 @@ namespace quantum {
*/ */
class CNOT: public virtual GateInstruction { class CNOT: public virtual GateInstruction {
public: public:
CNOT() :GateInstruction("CNOT") {}
CNOT(std::vector<int> qbits); CNOT(std::vector<int> qbits);
CNOT(int srcqbit, int tgtqbit); CNOT(int srcqbit, int tgtqbit);
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<CNOT>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
}; };
......
...@@ -26,6 +26,5 @@ CPhase::CPhase(std::vector<int> qbits) : ...@@ -26,6 +26,5 @@ CPhase::CPhase(std::vector<int> qbits) :
} }
RegisterGateInstruction<CPhase> CPHASETEMP("CPhase");
} }
} }
...@@ -19,8 +19,22 @@ namespace xacc { ...@@ -19,8 +19,22 @@ namespace xacc {
namespace quantum { namespace quantum {
class CPhase: public virtual GateInstruction { class CPhase: public virtual GateInstruction {
public: public:
CPhase() :GateInstruction("CPhase", std::vector<InstructionParameter> {
InstructionParameter(0.0) }){}
CPhase(std::vector<int> qbits); CPhase(std::vector<int> qbits);
CPhase(int controlQubit, int targetQubit, double theta); CPhase(int controlQubit, int targetQubit, double theta);
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<CPhase>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
......
...@@ -22,17 +22,6 @@ CZ::CZ(std::vector<int> qbits) : ...@@ -22,17 +22,6 @@ CZ::CZ(std::vector<int> qbits) :
CZ::CZ(int srcqbit, int tgtqbit) : CZ::CZ(int srcqbit, int tgtqbit) :
CZ(std::vector<int> { srcqbit, tgtqbit }) { CZ(std::vector<int> { srcqbit, tgtqbit }) {
} }
//
//void CZ::accept(std::shared_ptr<InstructionVisitor> visitor) {
// auto v = std::dynamic_pointer_cast<GateInstructionVisitor>(visitor);
// if (v) {
// v->visit(*this);
// } else {
// visitor->visit(*this);
// }
//}
RegisterGateInstruction<CZ> CZTEMP("CZ");
} }
} }
...@@ -23,9 +23,22 @@ namespace quantum { ...@@ -23,9 +23,22 @@ namespace quantum {
*/ */
class CZ: public virtual GateInstruction { class CZ: public virtual GateInstruction {
public: public:
CZ() : GateInstruction("CZ") {}
CZ(std::vector<int> qbits); CZ(std::vector<int> qbits);
CZ(int srcqbit, int tgtqbit); CZ(int srcqbit, int tgtqbit);
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<CZ>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
}; };
......
...@@ -35,6 +35,10 @@ public: ...@@ -35,6 +35,10 @@ public:
virtual const std::string toString(const std::string& bufferVarName); virtual const std::string toString(const std::string& bufferVarName);
// virtual std::shared_ptr<GateFunction> clone() {
// return std::make_shared<ConditionalFunction>();
// }
DEFINE_VISITABLE() DEFINE_VISITABLE()
}; };
......
...@@ -23,8 +23,6 @@ Hadamard::Hadamard(int qbit) : ...@@ -23,8 +23,6 @@ Hadamard::Hadamard(int qbit) :
Hadamard(std::vector<int> { qbit }) { Hadamard(std::vector<int> { qbit }) {
} }
RegisterGateInstruction<Hadamard> HTEMP("H");
} }
} }
...@@ -25,8 +25,20 @@ class Hadamard; ...@@ -25,8 +25,20 @@ class Hadamard;
*/ */
class Hadamard : public virtual GateInstruction { class Hadamard : public virtual GateInstruction {
public: public:
Hadamard() : GateInstruction("H") {}
Hadamard(std::vector<int> qbits); Hadamard(std::vector<int> qbits);
Hadamard(int qbit); Hadamard(int qbit);
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<Hadamard>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
......
...@@ -23,8 +23,6 @@ Identity::Identity(int qbit) : ...@@ -23,8 +23,6 @@ Identity::Identity(int qbit) :
Identity(std::vector<int> { qbit }) { Identity(std::vector<int> { qbit }) {
} }
RegisterGateInstruction<Identity> ITEMP("I");
} }
} }
...@@ -23,8 +23,21 @@ namespace quantum { ...@@ -23,8 +23,21 @@ namespace quantum {
*/ */
class Identity : public virtual GateInstruction { class Identity : public virtual GateInstruction {
public: public:
Identity() : GateInstruction("Identity") {}
Identity(std::vector<int> qbits); Identity(std::vector<int> qbits);
Identity(int qbit); Identity(int qbit);
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<Identity>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
......
...@@ -30,7 +30,6 @@ const std::string Measure::toString(const std::string& bufferVarName) { ...@@ -30,7 +30,6 @@ const std::string Measure::toString(const std::string& bufferVarName) {
return gateName + " " + bufferVarName + std::to_string(bits()[0]); return gateName + " " + bufferVarName + std::to_string(bits()[0]);
} }
RegisterGateInstruction<Measure> MEASURETEMP("Measure");
} }
} }
......
...@@ -23,6 +23,8 @@ namespace quantum { ...@@ -23,6 +23,8 @@ namespace quantum {
*/ */
class Measure : public GateInstruction { class Measure : public GateInstruction {
public: public:
Measure() :GateInstruction("Measure", std::vector<InstructionParameter> {
InstructionParameter(0) }) {}
Measure(std::vector<int> qbit); Measure(std::vector<int> qbit);
...@@ -33,6 +35,16 @@ public: ...@@ -33,6 +35,16 @@ public:
int getClassicalBitIndex() { int getClassicalBitIndex() {
return boost::get<int>(parameters[0]); return boost::get<int>(parameters[0]);
} }
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<Measure>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
......
...@@ -26,6 +26,5 @@ Rx::Rx(std::vector<int> qbits) : ...@@ -26,6 +26,5 @@ Rx::Rx(std::vector<int> qbits) :
} }
RegisterGateInstruction<Rx> RXTEMP("Rx");
} }
} }
...@@ -19,8 +19,22 @@ namespace xacc { ...@@ -19,8 +19,22 @@ namespace xacc {
namespace quantum { namespace quantum {
class Rx: public virtual GateInstruction { class Rx: public virtual GateInstruction {
public: public:
Rx(): GateInstruction("Rx", std::vector<InstructionParameter> {
InstructionParameter(0.0) }) {}
Rx(std::vector<int> qbits); Rx(std::vector<int> qbits);
Rx(int qbit, double theta); Rx(int qbit, double theta);
virtual std::shared_ptr<GateInstruction> clone() {
return std::make_shared<Rx>();
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual const std::string description() const {
return "";
}
DEFINE_VISITABLE() DEFINE_VISITABLE()
......
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