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

adding a couple functions to qreg for use in qcor


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 98ca9c07
Pipeline #97952 passed with stage
in 9 minutes and 55 seconds
......@@ -27,8 +27,14 @@ void qreg::store() {
buffer, empty_delete<AcceleratorBuffer>());
xacc::storeBuffer(buffer_as_shared);
}
int qreg::size() { return buffer->size(); }
void qreg::addChild(qreg &q) {
for (auto &child : buffer->getChildren()) {
results()->appendChild(child->name(), child);
}
}
void qreg::print() {buffer->print();}
void qreg::print() { buffer->print(); }
double qreg::weighted_sum(Observable *obs) {
auto terms = obs->getNonIdentitySubTerms();
......@@ -37,20 +43,21 @@ double qreg::weighted_sum(Observable *obs) {
auto children = buffer->getChildren();
double sum = 0.0;
if (terms.size() != children.size()) {
xacc::error("[qreg::weighted_sum()] error, number of observable terms != number of children buffers.");
xacc::error("[qreg::weighted_sum()] error, number of observable terms != "
"number of children buffers.");
}
for (int i = 0; i < children.size(); i++) {
// std::cout << children[i]->name() << ", "
// << children[i]->getExpectationValueZ() << ", "
// << terms[i]->coefficient() << "\n";
// std::cout << children[i]->name() << ", "
// << children[i]->getExpectationValueZ() << ", "
// << terms[i]->coefficient() << "\n";
sum += children[i]->getExpectationValueZ() *
std::real(terms[i]->coefficient());
sum += children[i]->getExpectationValueZ() *
std::real(terms[i]->coefficient());
}
if (id) {
sum += std::real(id->coefficient());
sum += std::real(id->coefficient());
}
return sum;
}
......
......@@ -33,6 +33,8 @@ public:
std::map<std::string, int> counts();
double exp_val_z();
void reset();
int size();
void addChild(qreg& q);
void setName(const char *name);
void setNameAndStore(const char *name);
void store();
......
......@@ -257,6 +257,7 @@ template const int& HeterogeneousMap::get<int>(const std::string key) const;
template const double& HeterogeneousMap::get<double>(const std::string key) const;
template const std::vector<std::complex<double>>& HeterogeneousMap::get<std::vector<std::complex<double>>>(const std::string key) const;
template const std::vector<double>& HeterogeneousMap::get<std::vector<double>>(const std::string key) const;
template const std::vector<double>& HeterogeneousMap::get_with_throw<std::vector<double>>(const std::string key) const;
template <typename... Types> class Variant : public mpark::variant<Types...> {
......
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