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:
virtual std::shared_ptr<Function> getKernel(const std::string& name) {
std::shared_ptr<Function> ret;
for (auto f : kernels) {
if (f->getName() == name) {
if (f->name() == name) {
ret = f;
}
}
......@@ -120,7 +120,7 @@ public:
virtual bool kernelExists(const std::string& name) {
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) {
......
......@@ -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
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
......@@ -83,9 +83,9 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc
auto bit = reversedQubitMap[pauli->bits()[0]];
qubits.insert(bit);
if (pauli->getName() == "H") {
if (pauli->name() == "H") {
termMap.insert( { bit, "X" });
} else if (pauli->getName() == "Rx") {
} else if (pauli->name() == "Rx") {
termMap.insert( { bit, "Y" });
}
......
......@@ -14,6 +14,7 @@
#define QUANTUM_GATE_IR_READOUTERRORIRPREPROCESSOR_HPP_
#include "IRPreprocessor.hpp"
#include "InstructionService.hpp"
namespace xacc {
namespace quantum {
......
......@@ -13,6 +13,7 @@
#include "QFT.hpp"
#include "GateInstruction.hpp"
#include "GateFunction.hpp"
#include "XACC.hpp"
namespace xacc {
......@@ -21,13 +22,14 @@ namespace quantum {
std::shared_ptr<Function> QFT::generate(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<InstructionParameter> parameters) {
auto gateRegistry = xacc::getService<InstructionService>("gate");
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;
auto endStart = qubits.size() - 1;
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--;
}
......@@ -46,7 +48,7 @@ std::shared_ptr<Function> QFT::generate(
// just return a hadamard, if not,
// then we need to build up some cphase gates
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};
} else {
......@@ -57,13 +59,13 @@ std::shared_ptr<Function> QFT::generate(
auto n = 1 + qs.size();
// Build up a list of cphase gates
std::vector<std::shared_ptr<GateInstruction>> cphaseGates;
std::vector<std::shared_ptr<Instruction>> cphaseGates;
int idx = 0;
for (int i = n-1; i > 0; --i) {
auto q_idx = qs[idx];
auto angle = 3.1415926 / std::pow(2, n - i);
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);
cphaseGates.push_back(cp);
idx++;
......@@ -81,7 +83,7 @@ std::shared_ptr<Function> QFT::generate(
}
// 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
return insts;
......
......@@ -14,6 +14,7 @@
#define QUANTUM_GATE_IR_ALGORITHMS_QFT_HPP_
#include "IRGenerator.hpp"
#include "InstructionService.hpp"
namespace xacc{
namespace quantum {
......@@ -49,7 +50,7 @@ public:
virtual const std::string description() const {
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) :
CNOT::CNOT(int srcqbit, int 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 {
*/
class CNOT: public virtual GateInstruction {
public:
CNOT() :GateInstruction("CNOT") {}
CNOT(std::vector<int> qbits);
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()
};
......
......@@ -26,6 +26,5 @@ CPhase::CPhase(std::vector<int> qbits) :
}
RegisterGateInstruction<CPhase> CPHASETEMP("CPhase");
}
}
......@@ -19,8 +19,22 @@ namespace xacc {
namespace quantum {
class CPhase: public virtual GateInstruction {
public:
CPhase() :GateInstruction("CPhase", std::vector<InstructionParameter> {
InstructionParameter(0.0) }){}
CPhase(std::vector<int> qbits);
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()
......
......@@ -22,17 +22,6 @@ CZ::CZ(std::vector<int> qbits) :
CZ::CZ(int srcqbit, int 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 {
*/
class CZ: public virtual GateInstruction {
public:
CZ() : GateInstruction("CZ") {}
CZ(std::vector<int> qbits);
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()
};
......
......@@ -35,6 +35,10 @@ public:
virtual const std::string toString(const std::string& bufferVarName);
// virtual std::shared_ptr<GateFunction> clone() {
// return std::make_shared<ConditionalFunction>();
// }
DEFINE_VISITABLE()
};
......
......@@ -23,8 +23,6 @@ Hadamard::Hadamard(int qbit) :
Hadamard(std::vector<int> { qbit }) {
}
RegisterGateInstruction<Hadamard> HTEMP("H");
}
}
......@@ -25,8 +25,20 @@ class Hadamard;
*/
class Hadamard : public virtual GateInstruction {
public:
Hadamard() : GateInstruction("H") {}
Hadamard(std::vector<int> qbits);
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()
......
......@@ -23,8 +23,6 @@ Identity::Identity(int qbit) :
Identity(std::vector<int> { qbit }) {
}
RegisterGateInstruction<Identity> ITEMP("I");
}
}
......@@ -23,8 +23,21 @@ namespace quantum {
*/
class Identity : public virtual GateInstruction {
public:
Identity() : GateInstruction("Identity") {}
Identity(std::vector<int> qbits);
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()
......
......@@ -30,7 +30,6 @@ const std::string Measure::toString(const std::string& bufferVarName) {
return gateName + " " + bufferVarName + std::to_string(bits()[0]);
}
RegisterGateInstruction<Measure> MEASURETEMP("Measure");
}
}
......
......@@ -23,6 +23,8 @@ namespace quantum {
*/
class Measure : public GateInstruction {
public:
Measure() :GateInstruction("Measure", std::vector<InstructionParameter> {
InstructionParameter(0) }) {}
Measure(std::vector<int> qbit);
......@@ -33,6 +35,16 @@ public:
int getClassicalBitIndex() {
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()
......
......@@ -26,6 +26,5 @@ Rx::Rx(std::vector<int> qbits) :
}
RegisterGateInstruction<Rx> RXTEMP("Rx");
}
}
......@@ -19,8 +19,22 @@ namespace xacc {
namespace quantum {
class Rx: public virtual GateInstruction {
public:
Rx(): GateInstruction("Rx", std::vector<InstructionParameter> {
InstructionParameter(0.0) }) {}
Rx(std::vector<int> qbits);
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()
......
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