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

syncing up work on parameterized gates

parent 0be9d335
No related branches found
No related tags found
No related merge requests found
...@@ -149,6 +149,35 @@ void ScaffoldCompiler::modifySource() { ...@@ -149,6 +149,35 @@ void ScaffoldCompiler::modifySource() {
kernelSource.erase(idx, s.size()); kernelSource.erase(idx, s.size());
} }
std::cout << "KERNELSRC: \n" << kernelSource << "\n";
std::regex gates("\\s+*\\w+\\(.*");
it = std::sregex_iterator(kernelSource.begin(), kernelSource.end(),
gates);
counter = 0;
for (auto it = std::sregex_iterator(kernelSource.begin(), kernelSource.end(),
gates); it != std::sregex_iterator(); ++it) {
std::cout << "GateLine? " << (*it).str() << "\n";
auto gateLine = (*it).str();
auto firstParen = gateLine.find_first_of('(');
auto secondParen = gateLine.find_first_of(')', firstParen);
auto functionArguments = gateLine.substr(firstParen+1, (secondParen-firstParen)-1);
auto args = gateLine.substr(firstParen+1, (secondParen-firstParen)-1);
std::cout << "Args for this gate are " << args << "\n";
std::vector<std::string> splitArgs;
boost::split(splitArgs, args, boost::is_any_of(","));
std::vector<std::string> params;
for (auto a : splitArgs) {
boost::trim(a);
if (!boost::contains(a, qbitVarName)) {
// This is a gate parameter... What do we do with it?
params.push_back(a);
}
}
gateIdToParameterMap.insert(std::make_pair(counter, params));
}
// Get the kernel name // Get the kernel name
std::regex functionName("((\\w+)\\s*\\()\\s*"); std::regex functionName("((\\w+)\\s*\\()\\s*");
auto begin = std::sregex_iterator(kernelSource.begin(), kernelSource.end(), auto begin = std::sregex_iterator(kernelSource.begin(), kernelSource.end(),
...@@ -198,6 +227,24 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() { ...@@ -198,6 +227,24 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() {
// Get the Qasm as a Graph... // Get the Qasm as a Graph...
auto circuitGraph = QasmToGraph::getCircuitGraph(qasm); auto circuitGraph = QasmToGraph::getCircuitGraph(qasm);
int counter = 0;
for (int i = 0; i < circuitGraph.order(); i++) {
auto props = circuitGraph.getVertexProperties(i);
auto gateName = std::get<0>(props);
if (gateName != "InitialState" && gateName != "FinalState") {
auto possibleParams = std::get<5>(props);
if (!possibleParams.empty()) {
// This is a parameterized gate
for (int j = 0; j < possibleParams.size(); j++) {
possibleParams[j] = gateIdToParameterMap[counter][j];
std::cout << "Setting " << gateName << " param names to " << gateIdToParameterMap[counter][j] << "\n";
}
}
counter++;
}
}
// HERE we have main circuit graph, before conditional // HERE we have main circuit graph, before conditional
// if branches... So then for each conditional code statement, // if branches... So then for each conditional code statement,
// get its circuit graph and add it to the main graph after // get its circuit graph and add it to the main graph after
...@@ -220,6 +267,7 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() { ...@@ -220,6 +267,7 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() {
conditionalCodeSegmentActingQubits); conditionalCodeSegmentActingQubits);
} }
// Create a GraphIR instance from that graph // Create a GraphIR instance from that graph
auto graphIR = std::make_shared<ScaffoldGraphIR>(circuitGraph); auto graphIR = std::make_shared<ScaffoldGraphIR>(circuitGraph);
......
...@@ -92,6 +92,8 @@ protected: ...@@ -92,6 +92,8 @@ protected:
*/ */
std::vector<int> conditionalCodeSegmentActingQubits; std::vector<int> conditionalCodeSegmentActingQubits;
std::map<int, std::vector<std::string>> gateIdToParameterMap;
}; };
} }
......
...@@ -139,14 +139,18 @@ public: ...@@ -139,14 +139,18 @@ public:
// FIXME Need to differentiate between qubits and parameters here // FIXME Need to differentiate between qubits and parameters here
// First we need the qubit register variable name // First we need the qubit register variable name
int counter = 0;
std::vector<std::string> splitComma; std::vector<std::string> splitComma, props;
boost::split(splitComma, gateCommand[1], boost::is_any_of(",")); boost::split(splitComma, gateCommand[1], boost::is_any_of(","));
for (auto segment : splitComma) { for (auto segment : splitComma) {
if (boost::contains(segment, qubitVarName)) { if (boost::contains(segment, qubitVarName)) {
actingQubits.push_back(qubitVarNameToId[segment]); actingQubits.push_back(qubitVarNameToId[segment]);
} else { } else {
std::cout << "Adding param " << g << ", " << segment << "\n";
// This is not a qubit, it must be a parameter for gate // This is not a qubit, it must be a parameter for gate
props.push_back("PARAM_" + std::to_string(counter));
std::get<5>(node.properties) = props;
counter++;
} }
} }
} }
......
...@@ -58,6 +58,7 @@ public: ...@@ -58,6 +58,7 @@ public:
// by default all circuit nodes // by default all circuit nodes
// are enabled and // are enabled and
std::get<4>(properties) = true; std::get<4>(properties) = true;
} }
}; };
......
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