This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
QirRuntime: support ApplyIf* and ApplyConditionally* intrinsics #527
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f01d98
QirRuntime: support ApplyIf* and ApplyConditionally* intrinsics
2fb1ef1
cleanup after merge and split tests
d291e01
Remove conditional rewrite; other PR feedback
fd155fc
Implement remaining ApplyIf* variants and add more diagnostics to the…
28d97a7
Merge branch 'main' into irinayat/qirruntime-conditionals
b5fd2dd
Update to reflect changes in ApplyIf* consolidation on the Q# side
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include <cassert> | ||
| #include <stdexcept> | ||
|
|
||
| #include "quantum__qis.hpp" | ||
|
|
||
| #include "QirTypes.hpp" | ||
| #include "quantum__rt.hpp" | ||
|
|
||
| static void Apply(QirCallable* clb) | ||
| { | ||
| PTuple argsTuple = quantum__rt__tuple_create(0); | ||
| quantum__rt__callable_invoke(clb, argsTuple /*args*/, nullptr /*result*/); | ||
| quantum__rt__tuple_update_reference_count(argsTuple, -1); | ||
| } | ||
|
|
||
| static bool ArraysContainEqualResults(QirArray* rs1, QirArray* rs2) | ||
| { | ||
| assert(rs1 != nullptr && rs2 != nullptr && rs1->count == rs2->count); | ||
| assert(rs1->itemSizeInBytes == sizeof(void*)); // the array should contain pointers to RESULT | ||
| assert(rs2->itemSizeInBytes == sizeof(void*)); // the array should contain pointers to RESULT | ||
|
|
||
| RESULT** results1 = reinterpret_cast<RESULT**>(rs1->buffer); | ||
| RESULT** results2 = reinterpret_cast<RESULT**>(rs2->buffer); | ||
| for (int64_t i = 0; i < rs1->count; i++) | ||
| { | ||
| if (!quantum__rt__result_equal(results1[i], results2[i])) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| extern "C" | ||
| { | ||
| void quantum__qis__applyifelseintrinsic__body(RESULT* r, QirCallable* clbOnZero, QirCallable* clbOnOne) | ||
| { | ||
| QirCallable* clbApply = quantum__rt__result_equal(r, quantum__rt__result_zero()) ? clbOnZero : clbOnOne; | ||
| Apply(clbApply); | ||
| } | ||
|
|
||
| void quantum__qis__applyconditionallyintrinsic__body( | ||
| QirArray* rs1, | ||
| QirArray* rs2, | ||
| QirCallable* clbOnAllEqual, | ||
| QirCallable* clbOnSomeDifferent) | ||
| { | ||
| QirCallable* clbApply = ArraysContainEqualResults(rs1, rs2) ? clbOnAllEqual : clbOnSomeDifferent; | ||
| Apply(clbApply); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.