Commit 1d801d5a authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

making algorithm cloneable


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 31a6d847
Pipeline #80601 failed with stage
in 3 minutes and 23 seconds
......@@ -209,6 +209,7 @@ DDCL::execute(const std::shared_ptr<AcceleratorBuffer> buffer,
auto lossStrategy = xacc::getService<LossStrategy>(loss);
// Execute!
std::cout << "RUNNING ON " << accelerator->name() << "\n";
auto tmpBuffer = xacc::qalloc(buffer->size());
accelerator->execute(tmpBuffer, circuits);
auto buffers = tmpBuffer->getChildren();
......
......@@ -78,6 +78,9 @@ public:
const std::vector<double> &parameters) override;
const std::string name() const override { return "ddcl"; }
const std::string description() const override { return ""; }
DEFINE_ALGORITHM_CLONE(DDCL)
};
} // namespace algorithm
} // namespace xacc
......
......@@ -65,6 +65,7 @@ public:
void execute(const std::shared_ptr<AcceleratorBuffer> buffer) const override;
const std::string name() const override { return "rbm-classification"; }
const std::string description() const override { return ""; }
DEFINE_ALGORITHM_CLONE(RBMClassification)
};
} // namespace algorithm
} // namespace xacc
......
......@@ -31,6 +31,7 @@ public:
void execute(const std::shared_ptr<AcceleratorBuffer> buffer) const override;
const std::string name() const override { return "rdm"; }
const std::string description() const override { return ""; }
DEFINE_ALGORITHM_CLONE(RDM)
};
} // namespace algorithm
} // namespace xacc
......
......@@ -34,6 +34,8 @@ public:
const std::string name() const override { return "vqe-energy"; }
const std::string description() const override { return ""; }
DEFINE_ALGORITHM_CLONE(VQEEnergy)
};
} // namespace algorithm
} // namespace xacc
......
......@@ -34,6 +34,7 @@ public:
void execute(const std::shared_ptr<AcceleratorBuffer> buffer) const override;
const std::string name() const override { return "vqe"; }
const std::string description() const override { return ""; }
DEFINE_ALGORITHM_CLONE(VQE)
};
} // namespace algorithm
} // namespace xacc
......
......@@ -31,7 +31,7 @@ namespace xacc {
//
// Algorithms expose an execute method that persists results
// to the AcceleratorBuffer.
class Algorithm : public xacc::Identifiable {
class Algorithm : public xacc::Identifiable, public xacc::Cloneable<Algorithm> {
public:
bool initialize(const HeterogeneousMap &&parameters) {
......@@ -42,7 +42,7 @@ public:
virtual void
execute(const std::shared_ptr<AcceleratorBuffer> buffer) const = 0;
virtual std::vector<double> execute(const std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<double> &parameters) {
XACCLogger::instance()->error(
......@@ -51,6 +51,11 @@ public:
exit(0);
return {};
}
#define DEFINE_ALGORITHM_CLONE(CLASS) \
std::shared_ptr<Algorithm> clone() override { \
return std::make_shared<CLASS>(); \
}
};
} // namespace xacc
......
......@@ -30,6 +30,7 @@ public:
const std::vector<std::string> requiredParameters() const override {
return {"observable"};
}
DEFINE_ALGORITHM_CLONE(TestAlgorithm)
void execute(const std::shared_ptr<AcceleratorBuffer> buffer) const override {
return;
......
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