diff --git a/quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp b/quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp index 79e670b2eabf045bb56a3f2c22dda4b6e7d6ef74..990c19519354483a48db7216ed04764696589642 100644 --- a/quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp +++ b/quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp @@ -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); diff --git a/quantum/gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp b/quantum/gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp index 44ed9a20063dc0906569da2ef21f21c2142b0a02..a96ae406a900e42db03946dd545e62b673687821 100644 --- a/quantum/gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp +++ b/quantum/gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp @@ -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"); diff --git a/quantum/gate/utils/QasmToGraph.hpp b/quantum/gate/utils/QasmToGraph.hpp index 0e515f9dbc8d6779d95b04bd91549e102a108c5b..c3e613b735810f91ad422c08d4f5dc0e56c8331b 100644 --- a/quantum/gate/utils/QasmToGraph.hpp +++ b/quantum/gate/utils/QasmToGraph.hpp @@ -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 + } } } diff --git a/quantum/gate/utils/QuantumCircuit.hpp b/quantum/gate/utils/QuantumCircuit.hpp index 1d61f892b4dc346b028d042cdb06182988e249aa..c855b642e76f1e145b5b006e632045e3bbd61a5f 100644 --- a/quantum/gate/utils/QuantumCircuit.hpp +++ b/quantum/gate/utils/QuantumCircuit.hpp @@ -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