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

Updating working teleport

parent 8f357a5f
No related branches found
No related tags found
No related merge requests found
......@@ -35,19 +35,22 @@
// qubit state to another.
const std::string src("__qpu__ teleport () {\n"
" cbit creg[2];\n"
" // Init qubit 0 to 1\n"
" X(qreg[0]);\n"
" // Now teleport...\n"
" H(qreg[1]);\n"
" CNOT(qreg[1],qreg[2]);\n"
" CNOT(qreg[0],qreg[1]);\n"
" H(qreg[0]);\n"
" creg[0] = MeasZ(qreg[0]);\n"
" creg[1] = MeasZ(qreg[1]);\n"
" if (creg[0] == 1) Z(qreg[2]);\n"
" if (creg[1] == 1) X(qreg[2]);\n"
" if(creg[0] == 1) Z(qreg[2]);\n"
"}\n");
int main (int argc, char** argv) {
// Create a convenient alias...
using Simple3QubitAcc = xacc::quantum::EigenAccelerator<3>;
// Create a reference to the 3 qubit simulation Accelerator
......
......@@ -99,9 +99,9 @@ public:
gateOperations.emplace_back(n);
}
std::cout << "Initial State:\n";
qubits->printState(std::cout);
std::cout << "\n";
// std::cout << "Initial State:\n";
// qubits->printState(std::cout);
// std::cout << "\n";
for (auto gate : gateOperations) {
......@@ -147,7 +147,7 @@ public:
if (std::get<0>(gateOperations[i].properties) == "FinalState") {
break;
}
std::cout << "Enabling " << graph.getVertexProperty<0>(i) << "\n";
// std::cout << "Enabling " << graph.getVertexProperty<0>(i) << "\n";
std::get<4>(gateOperations[i].properties) = true;
}
}
......@@ -164,14 +164,16 @@ public:
temp = kroneckerProduct(temp, productList[i]).eval();
}
// Get probability qubit is a 0
auto temp2 = temp * rho;
auto probZero = temp2.trace();
// Make the measurement random...
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist(0, 1.0);
int result;
auto val = dist(mt);
std::cout << "Val: " << val << "\n";
if (val < std::real(probZero)) {
result = 0;
Eigen::VectorXcd newState = (temp * qubits->getState());
......@@ -190,7 +192,7 @@ public:
qubits->setState(newState);
}
std::cout << "Measured qubit " << actingQubits[0] << " to be a " << result << ": prob was " << probZero << "\n";
// std::cout << "Measured qubit " << actingQubits[0] << " to be a " << result << ": prob was " << probZero << "\n";
qubitIdToMeasuredResult.insert(std::make_pair(actingQubits[0], result));
} else {
......@@ -240,67 +242,12 @@ public:
qubits->applyUnitary(localU);
std::cout << "Current State after " << gateName << ":\n";
qubits->printState(std::cout);
std::cout << "\n" << localU << "\n";
// std::cout << "Current State after " << gateName << ":\n";
// qubits->printState(std::cout);
// std::cout << "\n" << localU << "\n";
}
}
}
//
// while (layer < finalLayer) {
//
// std::vector<CircuitNode> currentLayerGates;
// std::copy_if(gateOperations.begin(), gateOperations.end(),
// std::back_inserter(currentLayerGates),
// [&](const CircuitNode& c) {return std::get<1>(c.properties) == layer;});
//
// std::vector<Eigen::MatrixXcd> productList(NQubits);
// for (int i = 0; i < NQubits; i++) {
// productList[i] = gates["I"];
// }
//
// // Can parallize this...
// for (auto n : currentLayerGates) {
//
// auto gateName = std::get<0>(n.properties);
// auto actingQubits = std::get<3>(n.properties);
//
// if (gateName != "measure" || gateName != "FinalState" || gateName != "InitialState") {
// auto gate = gates[gateName];
//
// if (actingQubits.size() == 1) {
// productList[actingQubits[0]] = gate;
// } else if (actingQubits.size() == 2) {
// productList[actingQubits[0]] = gate;
// productList.erase(productList.begin() + actingQubits[1]);
// } else {
// QCIError("Can only simulate one and two qubit gates.");
// }
// } else {
//
// if (gateName == "conditional") {
//
// } else if (gateName == "measure") {
//
// }
// }
//
// // Create a total unitary for this layer of the circuit
// Eigen::MatrixXcd result = productList[0];
// for (int i = 1; i < productList.size(); i++) {
// result = kroneckerProduct(result, productList[i]).eval();
// }
// assert(result.rows() == std::pow(2, NQubits) && result.cols() == std::pow(2,NQubits));
//
// // Update the circuit unitary matrix
// U = result * U;
//
// }
//
// layer++;
// }
//
// qubitsType->applyUnitary(U);
}
/**
......
......@@ -225,7 +225,7 @@ public:
// and add them to the main graph after some conditional nodes
// NOTE We assume that the ith conditionalGraph corresponds to the ith
// measurement gate...
// measurement gate... WRONG!!!!
std::vector<int> measurementIds;
std::vector<std::vector<int>>measurementQubits;
for (int i = 0; i < mainGraph.order(); i++) {
......
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