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

restructure on commongates to remove xacc.hpp inclusion, fix gate clone to clone buffernames


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent de6c5ce7
Pipeline #107455 passed with stage
in 22 minutes and 55 seconds
...@@ -20,6 +20,7 @@ using namespace rapidjson; ...@@ -20,6 +20,7 @@ using namespace rapidjson;
#include "JsonVisitor.hpp" #include "JsonVisitor.hpp"
#include "IRProvider.hpp" #include "IRProvider.hpp"
#include "IRToGraphVisitor.hpp" #include "IRToGraphVisitor.hpp"
#include "xacc_service.hpp"
namespace xacc { namespace xacc {
namespace quantum { namespace quantum {
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "InstructionIterator.hpp" #include "InstructionIterator.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "expression_parsing_util.hpp" #include "expression_parsing_util.hpp"
#include "xacc_service.hpp"
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
......
#include "CommonGates.hpp"
#include "xacc.hpp"
namespace xacc {
namespace quantum {
bool IfStmt::expand(const HeterogeneousMap &runtimeOptions) {
auto buffer = xacc::getBuffer(bufferName);
if ((*buffer)[bitIdx]) {
for (auto &i : instructions) {
i->enable();
}
} else {
// Note: although sub-instructions are initially disabled,
// we need to disable here as well just in case we run multiple shots
// and they may be enabled in the previous run.
disable();
}
return true;
}
} // namespace quantum
} // namespace xacc
\ No newline at end of file
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "Gate.hpp" #include "Gate.hpp"
#include "Circuit.hpp" #include "Circuit.hpp"
#include "xacc.hpp"
namespace xacc { namespace xacc {
namespace quantum { namespace quantum {
...@@ -86,21 +85,8 @@ public: ...@@ -86,21 +85,8 @@ public:
Circuit::addInstruction(instruction); Circuit::addInstruction(instruction);
} }
bool expand(const HeterogeneousMap &runtimeOptions) override { bool expand(const HeterogeneousMap &runtimeOptions) override;
auto buffer = xacc::getBuffer(bufferName);
if ((*buffer)[bitIdx]) {
for (auto &i : instructions) {
i->enable();
}
} else {
// Note: although sub-instructions are initially disabled,
// we need to disable here as well just in case we run multiple shots
// and they may be enabled in the previous run.
disable();
}
return true;
}
void disable() override { void disable() override {
for (auto &i : instructions) { for (auto &i : instructions) {
i->disable(); i->disable();
......
...@@ -29,7 +29,7 @@ Gate::Gate(std::string name, std::vector<std::size_t> qubts, ...@@ -29,7 +29,7 @@ Gate::Gate(std::string name, std::vector<std::size_t> qubts,
: gateName(name), qbits(qubts), parameters(params) {} : gateName(name), qbits(qubts), parameters(params) {}
Gate::Gate(const Gate &inst) Gate::Gate(const Gate &inst)
: gateName(inst.gateName), qbits(inst.qbits), parameters(inst.parameters), : gateName(inst.gateName), qbits(inst.qbits), parameters(inst.parameters),
arguments(inst.arguments), enabled(inst.enabled) {} arguments(inst.arguments), enabled(inst.enabled), buffer_names(inst.buffer_names) {}
const std::string Gate::name() const { return gateName; } const std::string Gate::name() const { return gateName; }
const std::string Gate::description() const { const std::string Gate::description() const {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ObservableTransform.hpp" #include "ObservableTransform.hpp"
#include "xacc_service.hpp" #include "xacc_service.hpp"
#include <Utils.hpp>
namespace xacc { namespace xacc {
namespace quantum { namespace quantum {
...@@ -97,7 +98,7 @@ void FermionOperator::clear() { terms.clear(); } ...@@ -97,7 +98,7 @@ void FermionOperator::clear() { terms.clear(); }
std::vector<std::shared_ptr<CompositeInstruction>> std::vector<std::shared_ptr<CompositeInstruction>>
FermionOperator::observe(std::shared_ptr<CompositeInstruction> function) { FermionOperator::observe(std::shared_ptr<CompositeInstruction> function) {
auto transform = xacc::getService<ObservableTransform>("jw"); auto transform = xacc::getService<ObservableTransform>("jw");
return transform->transform(shared_from_this())->observe(function); return transform->transform(xacc::as_shared_ptr(this))->observe(function);
} }
const std::string FermionOperator::toString() { const std::string FermionOperator::toString() {
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "Circuit.hpp" #include "Circuit.hpp"
#include "IRProvider.hpp" #include "IRProvider.hpp"
#include "Observable.hpp"
#include "xacc_service.hpp"
namespace xacc { namespace xacc {
namespace circuits { namespace circuits {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* Thien Nguyen - initial API and implementation * Thien Nguyen - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#include "ControlledGateApplicator.hpp" #include "ControlledGateApplicator.hpp"
#include "xacc_service.hpp"
namespace xacc { namespace xacc {
namespace circuits { namespace circuits {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Thien Nguyen - initial API and implementation * Thien Nguyen - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#pragma once #pragma once
#include "xacc.hpp"
#include "AllGateVisitor.hpp" #include "AllGateVisitor.hpp"
using namespace xacc::quantum; using namespace xacc::quantum;
......
...@@ -208,6 +208,7 @@ VQE::execute(const std::shared_ptr<AcceleratorBuffer> buffer, ...@@ -208,6 +208,7 @@ VQE::execute(const std::shared_ptr<AcceleratorBuffer> buffer,
for (auto &f : kernels) { for (auto &f : kernels) {
kernelNames.push_back(f->name()); kernelNames.push_back(f->name());
std::complex<double> coeff = f->getCoefficient(); std::complex<double> coeff = f->getCoefficient();
// std::cout << f->name() << "\n" << f->toString() <<"\n";
int nFunctionInstructions = 0; int nFunctionInstructions = 0;
if (f->getInstruction(0)->isComposite()) { if (f->getInstruction(0)->isComposite()) {
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "xacc.hpp" #include "xacc.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "Circuit.hpp" #include "Circuit.hpp"
#include "xacc_service.hpp"
using namespace xacc; using namespace xacc;
TEST(ExpTester, checkSimple) { TEST(ExpTester, checkSimple) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "xacc.hpp" #include "xacc.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "Circuit.hpp" #include "Circuit.hpp"
#include "xacc_service.hpp"
using namespace xacc; using namespace xacc;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
*******************************************************************************/ *******************************************************************************/
#include "InverseQFT.hpp" #include "InverseQFT.hpp"
#include <memory> #include <memory>
#include "xacc_service.hpp"
namespace xacc { namespace xacc {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "xacc.hpp" #include "xacc.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "Circuit.hpp" #include "Circuit.hpp"
#include "xacc_service.hpp"
using namespace xacc; using namespace xacc;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "xacc.hpp" #include "xacc.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "Circuit.hpp" #include "Circuit.hpp"
#include "xacc_service.hpp"
using namespace xacc; using namespace xacc;
......
...@@ -13,10 +13,17 @@ qreg::qreg(const qreg &other) : buffer(other.buffer) {} ...@@ -13,10 +13,17 @@ qreg::qreg(const qreg &other) : buffer(other.buffer) {}
qubit qreg::operator[](const std::size_t i) { qubit qreg::operator[](const std::size_t i) {
return std::make_pair(buffer->name(), i); return std::make_pair(buffer->name(), i);
} }
qreg &qreg::operator=(const qreg &q) {
buffer = q.buffer;
return *this;
}
AcceleratorBuffer *qreg::results() { return buffer; } AcceleratorBuffer *qreg::results() { return buffer; }
std::map<std::string, int> qreg::counts() { std::map<std::string, int> qreg::counts() {
return buffer->getMeasurementCounts(); return buffer->getMeasurementCounts();
} }
std::string qreg::name() { return buffer->name(); }
double qreg::exp_val_z() { return buffer->getExpectationValueZ(); } double qreg::exp_val_z() { return buffer->getExpectationValueZ(); }
void qreg::reset() { buffer->resetBuffer(); } void qreg::reset() { buffer->resetBuffer(); }
void qreg::setName(const char *name) { buffer->setName(name); } void qreg::setName(const char *name) { buffer->setName(name); }
......
...@@ -30,6 +30,7 @@ public: ...@@ -30,6 +30,7 @@ public:
qreg(const int n); qreg(const int n);
qreg (const qreg& other); qreg (const qreg& other);
qubit operator[](const std::size_t i); qubit operator[](const std::size_t i);
qreg& operator=(const qreg& q);
AcceleratorBuffer *results(); AcceleratorBuffer *results();
std::map<std::string, int> counts(); std::map<std::string, int> counts();
double exp_val_z(); double exp_val_z();
...@@ -38,6 +39,7 @@ public: ...@@ -38,6 +39,7 @@ public:
void addChild(qreg& q); void addChild(qreg& q);
void setName(const char *name); void setName(const char *name);
void setNameAndStore(const char *name); void setNameAndStore(const char *name);
std::string name();
void store(); void store();
void print(); void print();
double weighted_sum(Observable* obs); double weighted_sum(Observable* obs);
......
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