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

[RFC] Library-mode and kernel_builder implementation of allocation with initialization #1090

Closed
wants to merge 6 commits into from

Conversation

amccaskey
Copy link
Collaborator

@amccaskey amccaskey commented Jan 12, 2024

Initial prototype of #1086 for library mode and the kernel_builder

Things that still need to be done:

  • Python bindings
  • Testing
  • Update simulators to set state data (custatevec, cutensornet, mgpu)
  • Hook up the ASTBridge
  • Review / refactor InitializeStateOp and LowerToQIR.cpp updates (@schweitzpgi)
  • Verify bit ordering (@boschmitt)

Here's the "test" I've been running (will update to add some tests)

#include "cudaq.h"
#include <iostream> 

__qpu__ auto test0() {
  cudaq::qubit q = {0., 1.};
  return mz(q);
}

__qpu__ auto test1() {
  cudaq::qubit q = cudaq::ket::one;
  return mz(q);
}

__qpu__ void test2() { cudaq::qubit q = {M_SQRT1_2, M_SQRT1_2}; }

__qpu__ void test3() { cudaq::qvector q = {M_SQRT1_2, 0., 0., M_SQRT1_2}; }

__qpu__ void test4(const std::vector<cudaq::complex> &state) {
  cudaq::qvector q = state;
}

int main() {
  for (auto i : cudaq::range(10))
    printf("Test 0: %d\n", static_cast<int>(test0()));
  for (auto i : cudaq::range(10))
    printf("Test 1: %d\n", static_cast<int>(test1()));
  cudaq::sample(test2).dump();
  cudaq::sample(test3).dump();

  std::vector<cudaq::complex> vec{M_SQRT1_2, 0., 0., M_SQRT1_2};
  cudaq::sample(test4, vec).dump();

  // test error scenarios
  //
  // bad number of elements, this throws
  //     cudaq::sample(test4, std::vector<cudaq::complex>{1., 2., 3.});
  // vector not normalized, this throws
  //   cudaq::sample(test4, std::vector<cudaq::complex>{1., 2., 3., 4.});

  // Test kernel builder
  auto kernel = cudaq::make_kernel();
  auto qubits = kernel.qalloc(vec);
  std::cout << kernel << "\n";
  cudaq::sample(kernel).dump();
  return 0;
}

Copy link

copy-pr-bot bot commented Jan 12, 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.

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
@amccaskey amccaskey closed this Jan 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant