Commit 90ded0e5 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Merge branch 'master' into mccaskey/algorithm_optimizer

parents b341629d 53a34eb3
Pipeline #63400 passed with stage
in 9 minutes and 37 seconds
......@@ -332,19 +332,38 @@ void GateFunction::addInstruction(InstPtr instruction) {
xacc::InstructionParameter param = instruction->getParameter(0);
// Check to see if parameter is a string
if (param.isVariable()) {
// check to see if the new parameter is a duplicate parameter
bool dupParam = false;
// strip the parameter of mathematical operators and numbers/doubles
InstructionParameter strippedParam = splitParameter(param);
// check if the instruction parameter is a duplicate
for (auto p : parameters) {
if (p.as<std::string>() == strippedParam.as<std::string>()) {
dupParam = true;
// This could be an expression of constants, so
// lets evaluate and see
symbol_table_t symbol_table;
symbol_table.add_constants();
expression_t expr;
expr.register_symbol_table(symbol_table);
parser_t parser;
if (parser.compile(param.toString(), expr)) {
// std::cout << "Expr Compiled: " << expr.value() << "\n";
auto value = expr.value();
InstructionParameter pp(value);
instruction->setParameter(0, pp);
} else {
// std::cout << "ADDING VAR: " << param.which() << ", " << param.toString()
// << "\n";
// check to see if the new parameter is a duplicate parameter
bool dupParam = false;
// strip the parameter of mathematical operators and numbers/doubles
InstructionParameter strippedParam = splitParameter(param);
// check if the instruction parameter is a duplicate
for (auto p : parameters) {
// std::cout << "LOOPING PARAMS: ";
// std::cout << p.toString() << "\n";
// std::cout << strippedParam.toString() << "\n";
if (p.as<std::string>() == strippedParam.as<std::string>()) {
dupParam = true;
}
}
// if new parameter is not a duplicate, add the stripped version
if (!dupParam) {
parameters.push_back(strippedParam);
}
}
// if new parameter is not a duplicate, add the stripped version
if (!dupParam) {
parameters.push_back(strippedParam);
}
}
}
......
......@@ -62,11 +62,13 @@ public:
return mpark::get<T>(*this);
} catch (std::exception &e) {
std::stringstream s;
s << toString() << "\n";
s << "This InstructionParameter type id is " << this->which() << "\nAllowed Ids to Type\n";
for (auto& kv : whichType) {
s << kv.first << ": " << kv.second << "\n";
}
XACCLogger::instance()->error("Cannot cast Variant:\n" + s.str());
exit(0);
}
return T();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment