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

Enable pure quantum struct usage in kernels with restrictions #2199

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

Conversation

amccaskey
Copy link
Collaborator

This PR addresses the need to support struct types with only quantum members, e.g.

struct test {
  cudaq::qview<> q;
  cudaq::qview<> r;
};
__qpu__ void entry_ctor() {
  cudaq::qvector q(2), r(2);
  test tt(q, r);
  h(tt.r[0]);
}

or

@dataclass
class patch:
    q : cudaq.qview
    r : cudaq.qview 

@cudaq.kernel 
def entry():
    q = cudaq.qvector(2)
    r = cudaq.qvector(2)
    p = patch(q, r)
    h(p.r[0])

Pure quantum struct types are treated as value types in the MLIR (no loading or storing).

We enforce the following restrictions in both C++ and Python with thrown errors with descriptive messages:

  • hybrid quantum-classical structs (contains both classical and quantum types)
  • quantum struct return types
  • recursive usage of quantum structs
  • quantum structs with user-defined methods

A canonicalizer is also added to ensure lowering to static circuit code is possible.

Copy link

copy-pr-bot bot commented Sep 6, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@schweitzpgi
Copy link
Collaborator

schweitzpgi commented Sep 6, 2024

Maybe I forgot to comment before, but I think it will be handy to have a distinct type for these other than a cc.struct type. It would let us fine tune the semantics better. They are "quantum" types in the "quantum memory" space. They only interact with quake dialect artifacts. They can't be loaded and stored from and to regular memory, etc.

I saw the "size" information (utterly bogus in terms of the semantics here) in the tests and it reminded me...

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.

2 participants