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

Merged
merged 15 commits into from
Jan 8, 2025
Merged

Add a few state-related cc ops #2354

merged 15 commits into from
Jan 8, 2025

Conversation

annagrin
Copy link
Collaborator

@annagrin annagrin commented Nov 5, 2024

Description

Add a few state-related quake ops:

  • quake.create_state
  • quake.delete_state
  • quake.get_number_of_qubits
  • quake.get_state

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

This simplifies passes that intend to remove those ops, such as DeleteStates , ArgumentConversion, or ReplaceStateWithKernel (to be added in the dependent PR below)

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 requested a review from schweitzpgi November 12, 2024 18:09
@annagrin annagrin marked this pull request as ready for review November 12, 2024 18:10
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.

include/cudaq/Optimizer/Dialect/CC/CCOps.td Outdated Show resolved Hide resolved
include/cudaq/Optimizer/Dialect/CC/CCOps.td Outdated Show resolved Hide resolved
Signed-off-by: Anna Gringauze <[email protected]>
@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.)

@annagrin
Copy link
Collaborator Author

annagrin commented Dec 2, 2024

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.)

That sounds reasonable to me, but I would like to address it in a separate PR, to keep changes smaller.

Signed-off-by: Anna Gringauze <[email protected]>
@schweitzpgi
Copy link
Collaborator

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.)

That sounds reasonable to me, but I would like to address it in a separate PR, to keep changes smaller.

I agree. It's morphed its way from being just a vector of complex (as in exactly the CC type) to its own distinct type that only makes sense when used in a quantum context. I think moving it to quake will eliminate some cross-dependencies that have crept in as well.

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.

This is going to be great.

Can you add the new ops to the roundtrip test?

include/cudaq/Optimizer/Dialect/Quake/QuakeOps.td Outdated Show resolved Hide resolved
include/cudaq/Optimizer/Dialect/Quake/QuakeOps.td Outdated Show resolved Hide resolved
include/cudaq/Optimizer/Dialect/Quake/QuakeOps.td Outdated Show resolved Hide resolved
include/cudaq/Optimizer/Dialect/Quake/QuakeOps.td Outdated Show resolved Hide resolved
include/cudaq/Optimizer/Dialect/Quake/QuakeOps.td Outdated Show resolved Hide resolved
include/cudaq/Optimizer/Dialect/Quake/QuakeOps.td Outdated Show resolved Hide resolved
lib/Optimizer/CodeGen/QuakeToCodegen.cpp Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 8, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 8, 2025
@annagrin
Copy link
Collaborator Author

annagrin commented Jan 8, 2025

This is going to be great.

Can you add the new ops to the roundtrip test?

Done, thanks!

@annagrin annagrin requested a review from schweitzpgi January 8, 2025 18:08
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.

Awesome.

@annagrin annagrin merged commit d2bed4c into NVIDIA:main Jan 8, 2025
213 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 8, 2025
Copy link

github-actions bot commented Jan 8, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Omar-ORCA pushed a commit to orcacomputing/cuda-quantum that referenced this pull request Jan 13, 2025
* Add a few state-related cc ops

Signed-off-by: Anna Gringauze <[email protected]>

* Fix test_argument_conversion

Signed-off-by: Anna Gringauze <[email protected]>

* Add printing in failing tests

Signed-off-by: Anna Gringauze <[email protected]>

* Add printing in failing tests

Signed-off-by: Anna Gringauze <[email protected]>

* Fix failing tests

Signed-off-by: Anna Gringauze <[email protected]>

* Address CR comments

Signed-off-by: Anna Gringauze <[email protected]>

* Fix comment

Signed-off-by: Anna Gringauze <[email protected]>

* Address CR comments

Signed-off-by: Anna Gringauze <[email protected]>

---------

Signed-off-by: Anna Gringauze <[email protected]>
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