Skip to content

Commit

Permalink
Fix #1464: control setting was being dropped. (#1466)
Browse files Browse the repository at this point in the history
Although the control shorthands were being recognized in the bridge,
they were inadverently being promoted to non-control forms of the same
quantum gate.

Fixes #1464.
  • Loading branch information
schweitzpgi committed Apr 2, 2024
1 parent d34c714 commit 8174e14
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions lib/Frontend/nvqpp/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,8 @@ bool QuakeBridgeVisitor::VisitCallExpr(clang::CallExpr *x) {

if (isInNamespace(func, "cudaq")) {
// Check and see if this quantum operation is adjoint
bool isAdjoint = false, isControl = false;
bool isAdjoint = false;
bool isControl = false;
auto *functionDecl = x->getCalleeDecl()->getAsFunction();
if (auto *templateArgs = functionDecl->getTemplateSpecializationArgs())
if (templateArgs->size() > 0) {
Expand Down Expand Up @@ -1482,25 +1483,53 @@ bool QuakeBridgeVisitor::VisitCallExpr(clang::CallExpr *x) {
auto reportNegateError = [&]() {
reportClangError(x, mangler, "target qubit cannot be negated");
};
if (funcName.equals("h") || funcName.equals("ch"))
if (funcName.equals("h"))
return buildOp<quake::HOp>(builder, loc, args, negations,
reportNegateError, false, isControl);
if (funcName.equals("x") || funcName.equals("cnot") ||
funcName.equals("cx") || funcName.equals("ccx"))
reportNegateError, /*adjoint=*/false,
isControl);
if (funcName.equals("ch"))
return buildOp<quake::HOp>(builder, loc, args, negations,
reportNegateError, /*adjoint=*/false,
/*control=*/true);
if (funcName.equals("x"))
return buildOp<quake::XOp>(builder, loc, args, negations,
reportNegateError, /*adjoint=*/false,
isControl);
if (funcName.equals("cnot") || funcName.equals("cx") ||
funcName.equals("ccx"))
return buildOp<quake::XOp>(builder, loc, args, negations,
reportNegateError, false, isControl);
if (funcName.equals("y") || funcName.equals("cy"))
reportNegateError, /*adjoint=*/false,
/*control=*/true);
if (funcName.equals("y"))
return buildOp<quake::YOp>(builder, loc, args, negations,
reportNegateError, /*adjoint=*/false,
isControl);
if (funcName.equals("cy"))
return buildOp<quake::YOp>(builder, loc, args, negations,
reportNegateError, false, isControl);
if (funcName.equals("z") || funcName.equals("cz"))
reportNegateError, /*adjoint=*/false,
/*control=*/true);
if (funcName.equals("z"))
return buildOp<quake::ZOp>(builder, loc, args, negations,
reportNegateError, false, isControl);
if (funcName.equals("s") || funcName.equals("cs"))
reportNegateError, /*adjoint=*/false,
isControl);
if (funcName.equals("cz"))
return buildOp<quake::ZOp>(builder, loc, args, negations,
reportNegateError, /*adjoint=*/false,
/*control=*/true);
if (funcName.equals("s"))
return buildOp<quake::SOp>(builder, loc, args, negations,
reportNegateError, isAdjoint, isControl);
if (funcName.equals("t") || funcName.equals("ct"))
if (funcName.equals("cs"))
return buildOp<quake::SOp>(builder, loc, args, negations,
reportNegateError, isAdjoint,
/*control=*/true);
if (funcName.equals("t"))
return buildOp<quake::TOp>(builder, loc, args, negations,
reportNegateError, isAdjoint, isControl);
if (funcName.equals("ct"))
return buildOp<quake::TOp>(builder, loc, args, negations,
reportNegateError, isAdjoint,
/*control=*/true);

if (funcName.equals("reset")) {
if (!negations.empty())
Expand Down

0 comments on commit 8174e14

Please sign in to comment.