Skip to content
Snippets Groups Projects
Commit da1fabb1 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Updating simulatedqubits to use complex Tensor

parent 520ea8f4
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ namespace xacc {
namespace quantum {
using QubitState = fire::Tensor<1>;
using QubitState = fire::Tensor<1, fire::EigenProvider, std::complex<double>>;
using IndexPair = std::pair<int,int>;
/**
......@@ -68,7 +68,7 @@ public:
*
* @param U
*/
void applyUnitary(fire::Tensor<2>& U) {
void applyUnitary(fire::Tensor<2, fire::EigenProvider, std::complex<double>>& U) {
assert(
U.dimension(0) == bufferState.dimension(0)
&& U.dimension(1) == bufferState.dimension(0));
......@@ -83,7 +83,7 @@ public:
void normalize() {
double sum = 0.0;
for (int i = 0; i < bufferState.dimension(0); i++)
sum += bufferState(i) * bufferState(i);
sum += std::real(bufferState(i) * bufferState(i));
for (int i = 0; i < bufferState.dimension(0); i++)
bufferState(i) = bufferState(i) / std::sqrt(sum);
}
......
......@@ -58,7 +58,7 @@ public:
* The constructor, create tensor gates
*/
FireTensorAccelerator() {
fire::Tensor<2> h(2,2), cnot(4,4), I(2,2), x(2,2), p0(2,2), p1(2,2), z(2,2);
fire::Tensor<2, fire::EigenProvider, std::complex<double>> h(2,2), cnot(4,4), I(2,2), x(2,2), p0(2,2), p1(2,2), z(2,2);
h.setValues({{1.0/sqrt2, 1.0/sqrt2},{1.0/sqrt2,-1.0/sqrt2}});
cnot.setValues({{1,0,0,0},{0,0,1,0},{0,0,0,1},{0,0,1,0}});
x.setValues({{0, 1},{1, 0}});
......@@ -121,13 +121,13 @@ public:
}
// Create a list of nQubits Identity gates
std::vector<fire::Tensor<2>> productList;
std::vector<fire::Tensor<2, fire::EigenProvider, std::complex<double>>> productList;
for (int i = 0; i < nQubits; i++) {
productList.push_back(gates.at("I"));
}
// Create a local U gate, initialized to identity
fire::Tensor<2> localU = gates.at("I");
fire::Tensor<2, fire::EigenProvider, std::complex<double>> localU = gates.at("I");
// Get the current gate anme
auto gateName = std::get<0>(gate.properties);
......@@ -179,7 +179,7 @@ public:
std::array<IndexPair, 1> contractionIndices;
contractionIndices[0] = std::make_pair(1, 0);
auto Prob0 = Pi0.contract(rho, contractionIndices);
for (int i = 0; i < Prob0.dimension(0); i++) probZero += Prob0(i,i);
for (int i = 0; i < Prob0.dimension(0); i++) probZero += std::real(Prob0(i,i));
// Make the measurement random...
std::random_device rd;
......@@ -269,7 +269,7 @@ protected:
/**
* Mapping of gate names to actual gate matrices.
*/
std::map<std::string, fire::Tensor<2>> gates;
std::map<std::string, fire::Tensor<2, fire::EigenProvider, std::complex<double>>> gates;
};
}
}
......
......@@ -97,9 +97,9 @@ BOOST_AUTO_TEST_CASE(checkConstruction) {
graphir->read(iss);
acc.execute("qreg", graphir);
BOOST_VERIFY(qreg->getState()(1) * qreg->getState()(1) == 1 ||
qreg->getState()(5) * qreg->getState()(5) == 1 ||
qreg->getState()(3) * qreg->getState()(3) == 1 ||
qreg->getState()(7) * qreg->getState()(7) == 1);
BOOST_VERIFY(std::real(qreg->getState()(1) * qreg->getState()(1)) == 1 ||
std::real(qreg->getState()(5) * qreg->getState()(5)) == 1 ||
std::real(qreg->getState()(3) * qreg->getState()(3)) == 1 ||
std::real(qreg->getState()(7) * qreg->getState()(7)) == 1);
}
......@@ -39,7 +39,7 @@ using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkConstruction) {
fire::Tensor<1> initialState1(8);
fire::Tensor<1, fire::EigenProvider, std::complex<double>> initialState1(8);
initialState1(0) = 1;
SimulatedQubits<3> qubits1("name1");
BOOST_VERIFY(qubits1.size() == 3);
......@@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(checkConstruction) {
BOOST_VERIFY(qubits1.getState().dimension(0) == 8);
BOOST_VERIFY(qubits1.getState() == initialState1);
fire::Tensor<1> initialState2(4);
fire::Tensor<1, fire::EigenProvider, std::complex<double>> initialState2(4);
initialState2(0) = 1;
SimulatedQubits<3> qubits2("name2", 2);
BOOST_VERIFY(qubits2.size() == 2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment