-
Notifications
You must be signed in to change notification settings - Fork 190
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a few state-related cc ops #2354
base: main
Are you sure you want to change the base?
Changes from all commits
78c0a44
6682c39
102f819
6b2c015
5ea1d97
074c60f
310f6ca
f0176ae
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 |
---|---|---|
|
@@ -898,6 +898,68 @@ def cc_AddressOfOp : CCOp<"address_of", [Pure, | |
}]; | ||
} | ||
|
||
def cc_CreateStateOp : CCOp<"create_state", [Pure] > { | ||
let summary = "Create state from data"; | ||
let description = [{ | ||
This operation takes a pointer to state data and creates a quantum state. | ||
The operation can be optimized away in DeleteStates pass, or replaced | ||
by an intrinsic runtime call on simulators. | ||
|
||
```mlir | ||
%0 = cc.create_state %data: !cc.ptr<!cc.state> | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
AnyPointerType:$data, | ||
AnySignlessInteger:$length | ||
); | ||
let results = (outs AnyPointerType:$result); | ||
let assemblyFormat = [{ | ||
$data `,` $length `:` functional-type(operands, results) attr-dict | ||
}]; | ||
} | ||
|
||
def cc_GetNumberOfQubitsOp : CCOp<"get_number_of_qubits", [Pure] > { | ||
let summary = "Get number of qubits from a quantum state"; | ||
let description = [{ | ||
This operation takes a state pointer argument and returns a number of | ||
qubits in the state. The operation can be optimized away in some passes | ||
line ReplaceStateByKernel or DeleteStates, or replaced by an intrinsic | ||
runtime call on simulators. | ||
|
||
```mlir | ||
%0 = cc.get_number_of_qubits %state : i64 | ||
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. The type on this example doesn't correspond to the assembly below. 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. forgot to update, thanks! |
||
``` | ||
}]; | ||
|
||
let arguments = (ins cc_PointerType:$state); | ||
let results = (outs AnySignlessInteger:$result); | ||
let assemblyFormat = [{ | ||
$state `:` functional-type(operands, results) attr-dict | ||
}]; | ||
} | ||
|
||
def cc_GetStateOp : CCOp<"get_state", [Pure] > { | ||
let summary = "Get state from kernel with the provided name."; | ||
let description = [{ | ||
This operation is created by argument synthesis of state pointer arguments | ||
for quantum devices. It takes a kernel name as ASCIIZ string literal value | ||
and returns the kernel's quantum state. The operation is replaced by a call | ||
to the kernel with the provided name in ReplaceStateByKernel pass. | ||
|
||
```mlir | ||
%0 = cc.get_state "callee" : !cc.ptr<!cc.state> | ||
``` | ||
}]; | ||
|
||
let arguments = (ins StrAttr:$calleeName); | ||
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 should probably take a 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. sounds good, will do |
||
let results = (outs cc_PointerType:$result); | ||
let assemblyFormat = [{ | ||
$calleeName `:` qualified(type(results)) attr-dict | ||
}]; | ||
} | ||
|
||
def cc_GlobalOp : CCOp<"global", [IsolatedFromAbove, Symbol]> { | ||
let summary = "Create a global constant or variable"; | ||
let description = [{ | ||
|
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.
This example only has 1 argument, but below it lists 2 arguments.
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.
forgot to update, thanks!