-
-
Notifications
You must be signed in to change notification settings - Fork 74
馃悰 Reject nonlinear Hadamard-lifting inputs safely #2309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,11 @@ | |
| #include <mlir/Dialect/MemRef/IR/MemRef.h> | ||
| #include <mlir/IR/BuiltinOps.h> | ||
| #include <mlir/IR/DialectRegistry.h> | ||
| #include <mlir/IR/OperationSupport.h> | ||
| #include <mlir/IR/OwningOpRef.h> | ||
| #include <mlir/IR/Value.h> | ||
| #include <mlir/IR/Verifier.h> | ||
| #include <mlir/Parser/Parser.h> | ||
| #include <mlir/Pass/PassManager.h> | ||
| #include <mlir/Support/LLVM.h> | ||
| #include <mlir/Support/LogicalResult.h> | ||
|
|
@@ -81,6 +84,56 @@ class QCOHadamardLiftingTest : public testing::Test { | |
|
|
||
| } // namespace | ||
|
|
||
| TEST_F(QCOHadamardLiftingTest, HandlesUnusedPauliOutput) { | ||
| auto input = parseSourceString<ModuleOp>(R"mlir( | ||
| module { | ||
| func.func @main() { | ||
| %q = qco.static 0 : !qco.qubit | ||
| %unused = qco.x %q : !qco.qubit -> !qco.qubit | ||
| return | ||
| } | ||
| } | ||
| )mlir", | ||
|
Comment on lines
+87
to
+96
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is invalid QCO IR. |
||
| &context); | ||
| ASSERT_TRUE(input); | ||
| ASSERT_TRUE(succeeded(verify(*input))); | ||
| OwningOpRef<ModuleOp> original(input->clone()); | ||
|
|
||
| EXPECT_TRUE(failed(runHadamardLiftingPass(*input))); | ||
| EXPECT_TRUE(OperationEquivalence::isEquivalentTo( | ||
| input->getOperation(), original->getOperation(), | ||
| OperationEquivalence::Flags::None)); | ||
| } | ||
|
|
||
| TEST_F(QCOHadamardLiftingTest, HandlesUnusedCnotControlOutput) { | ||
| auto input = parseSourceString<ModuleOp>(R"mlir( | ||
| module { | ||
| func.func @main() { | ||
| %control = qco.static 0 : !qco.qubit | ||
| %target = qco.static 1 : !qco.qubit | ||
| %unused, %target_out = qco.ctrl(%control) targets(%arg = %target) { | ||
| %body = qco.x %arg : !qco.qubit -> !qco.qubit | ||
| qco.yield %body : !qco.qubit | ||
| } : ({!qco.qubit}, {!qco.qubit}) | ||
| -> ({!qco.qubit}, {!qco.qubit}) | ||
| %hadamard = qco.h %target_out : !qco.qubit -> !qco.qubit | ||
| %measured, %result = qco.measure %hadamard : !qco.qubit | ||
| qco.sink %measured : !qco.qubit | ||
| return | ||
| } | ||
| } | ||
| )mlir", | ||
| &context); | ||
| ASSERT_TRUE(input); | ||
| ASSERT_TRUE(succeeded(verify(*input))); | ||
| OwningOpRef<ModuleOp> original(input->clone()); | ||
|
|
||
| EXPECT_TRUE(failed(runHadamardLiftingPass(*input))); | ||
| EXPECT_TRUE(OperationEquivalence::isEquivalentTo( | ||
| input->getOperation(), original->getOperation(), | ||
| OperationEquivalence::Flags::None)); | ||
| } | ||
|
|
||
| // ################################################## | ||
| // # Raise Hadamard over uncontrolled Pauli gate Tests | ||
| // ################################################## | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I am not sure we should actually be adding this in front of every pass.
Passes can expect valid IR. They should not have to verify that it is valid.
I'd rather drop that in cases like here.
Does that make sense?