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

syncing up work on parameterized gates

parent 94c5d222
No related branches found
No related tags found
No related merge requests found
......@@ -193,6 +193,8 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() {
// This will throw if it fails.
auto qasm = scaffcc.getFlatQASMFromSource(kernelSource);
std::cout << "QASM:\n" << qasm << "\n";
// Get the Qasm as a Graph...
auto circuitGraph = QasmToGraph::getCircuitGraph(qasm);
......
......@@ -110,7 +110,6 @@ BOOST_AUTO_TEST_CASE(checkCodeWithArgument) {
BOOST_VERIFY(compiler);
const std::string src("__qpu__ kernel (qbit qreg[1], double phi) {\n"
// " qbit qreg[1];\n"
" Rz(qreg[0], phi);\n"
"}\n");
......
......@@ -66,6 +66,7 @@ public:
std::regex qubitDeclarations("\\s*qubit\\s*\\w+");
std::sregex_token_iterator first{flatQasmStr.begin(), flatQasmStr.end(), newLineDelim, -1}, last;
int nQubits = 0, qbitId = 0, layer = 1, gateId = 1;
std::string qubitVarName;
qasmLines = {first, last};
// Let's now loop over the qubit declarations,
......@@ -78,6 +79,10 @@ public:
std::sregex_token_iterator first{qubitLine.begin(), qubitLine.end(), spaceDelim, -1}, last;
std::vector<std::string> splitQubitLine = {first, last};
qubitVarNameToId[splitQubitLine[1]] = qbitId;
splitQubitLine[1].erase(
std::remove_if(splitQubitLine[1].begin(), splitQubitLine[1].end(), &isdigit),
splitQubitLine[1].end());
qubitVarName = splitQubitLine[1];
allQbitIds.push_back(qbitId);
qbitId++;
}
......@@ -88,7 +93,7 @@ public:
// First create a starting node for the initial
// wave function - it should have nQubits outgoing
// edges
graph.addVertex("InitialState", 0, 0, allQbitIds, true);
graph.addVertex("InitialState", 0, 0, allQbitIds, true, std::vector<std::string>{});
std::vector<CircuitNode> gateOperations;
for (auto line : qasmLines) {
......@@ -103,7 +108,6 @@ public:
line.end(), spaceDelim, -1 }, last;
std::vector<std::string> gateCommand = {first, last};
std::cout << "GSTER: " << gateCommand[0] << "\n";
// Set the gate as a lowercase gate name string
auto g = boost::to_lower_copy(gateCommand[0]);
boost::trim(g);
......@@ -130,10 +134,20 @@ public:
if (!boost::contains(gateCommand[1], ",")) {
actingQubits.push_back(qubitVarNameToId[gateCommand[1]]);
} else {
std::vector<std::string> qbits;
boost::split(qbits, gateCommand[1], boost::is_any_of(","));
for (auto q : qbits) {
actingQubits.push_back(qubitVarNameToId[q]);
// FIXME Need to differentiate between qubits and parameters here
// First we need the qubit register variable name
std::vector<std::string> splitComma;
boost::split(splitComma, gateCommand[1], boost::is_any_of(","));
for (auto segment : splitComma) {
if (boost::contains(segment, qubitVarName)) {
actingQubits.push_back(qubitVarNameToId[segment]);
} else {
// This is not a qubit, it must be a parameter for gate
}
}
}
......
......@@ -41,10 +41,10 @@ namespace quantum {
* parameters in the given order:
*
* Parameters: Gate, Layer (ie time sequence), Gate Vertex Id,
* Qubit Ids that the gate acts on
* Qubit Ids that the gate acts on, enabled state, vector of parameters names
*/
class CircuitNode: public qci::common::QCIVertex<std::string, int, int,
std::vector<int>, bool> {
std::vector<int>, bool, std::vector<std::string>> {
public:
CircuitNode() :
QCIVertex() {
......@@ -53,6 +53,7 @@ public:
propertyNames[2] = "Gate Vertex Id";
propertyNames[3] = "Gate Acting Qubits";
propertyNames[4] = "Enabled";
propertyNames[5] = "RuntimeParameters";
// by default all circuit nodes
// are enabled and
......
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