Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

annagrin
Copy link
Collaborator

@annagrin annagrin commented Nov 5, 2024

Description

Add a few state-related cc ops:

  • cc.create_state
  • cc.get_number_of_qubits
  • cc.get_state

The ops are created by the kernel builder or the AST bridge and either optimized away during argument synthesis, or converted to mlir in QuakeToCodegen pass.

This simplifies passes that seek to remove those ops, such as DeleteStates or ArgumentConversion.

Note: this is also a prerequisite for creating a simpler quantum state synthesis passes: #2291

@annagrin annagrin marked this pull request as draft November 5, 2024 18:02
@annagrin annagrin marked this pull request as ready for review November 12, 2024 18:10
by an intrinsic runtime call on simulators.

```mlir
%0 = cc.create_state %data: !cc.ptr<!cc.state>
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to update, thanks!

Copy link
Collaborator

@schweitzpgi schweitzpgi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should put these in the quake dialect.

First, these really correspond to quantum operations in the end. As such they are successively lowered to (recursive?) kernel application or high-level abstract calls to a quantum simulator/emulator.

Second, they just don't have a classical computation semantics (see issue 1). In that context, they really aren't anything the compiler can reason about in terms of classical computation and behave as opaque calls to unknown external code.

runtime call on simulators.

```mlir
%0 = cc.get_number_of_qubits %state : i64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type on this example doesn't correspond to the assembly below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to update, thanks!

```
}];

let arguments = (ins StrAttr:$calleeName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably take a !cc.ptr<?> argument and make use of the cc.literal_string operation. That would be more flexible in the long run.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, will do

@boschmitt
Copy link
Collaborator

I'm thinking we should put these in the quake dialect.

+1

I wonder with the cc.state type shouldn't also be moved to quake. Although it is a vector (array) of complex values, the moment we attach this specific interpretation for it, it jumps the fence to the quake side of things. (If we had left those as raw vector/array, then this interpretation would be given by the op that takes it, i.e., we would only know that a vector/array corresponds to a state if a quake.init_state use it as input.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants