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

Optimized support for applying exponentials of Paulis #660

Merged
merged 9 commits into from
Sep 29, 2023

Conversation

amccaskey
Copy link
Collaborator

@amccaskey amccaskey commented Sep 15, 2023

Enable the following in the runtime and the bridge:

auto kernel = [](double theta) __qpu__ {
  cudaq::qreg q(4);
  x(q[0]);
  x(q[1]);
  exp_pauli(theta, q, "XXXY");
};

auto kernel2 = [](double theta, const char * pauli) __qpu__ {
   cudaq::qreg q(4);
   x(q[0]);
   x(q[1]);
   exp_pauli(theta, q, pauli);
 };

auto kernel3 = [](double theta) __qpu__ {
  cudaq::qreg q(4);
  x(q[0]);
  x(q[1]);
  exp_pauli(theta, "XXXY", q[0], q[1], q[2], q[3]);
};

auto [kernel, theta] = cudaq::make_kernel<double>();
auto qubits = kernel.qalloc(4);
kernel.x(qubits[0]);
kernel.x(qubits[1]);
kernel.exp_pauli(theta, qubits, "XXXY");

auto [kernel, theta] = cudaq::make_kernel<double>();
auto qubits = kernel.qalloc(4);
kernel.x(qubits[0]);
kernel.x(qubits[1]);
kernel.exp_pauli(theta, "XXXY", qubits[0], qubits[1], qubits[2], qubits[3]);
kernel, theta = cudaq.make_kernel(float)
qubits = kernel.qalloc(4)
kernel.x(qubits[0])
kernel.x(qubits[1])
kernel.exp_pauli(theta, qubits, "XXXY")

Also:

Add a cc.string type, a cc.string_literal op, and updates to lower to all this LLVM.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Sep 15, 2023

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.

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 15, 2023

/ok to test

Command Bot: Processing...

1 similar comment
@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 15, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 16, 2023

/ok to test

Command Bot: Processing...

@1tnguyen
Copy link
Collaborator

I couldn't reproduce the segfault in https://github.com/NVIDIA/cuda-quantum/actions/runs/6207439851/job/16853577621 locally:

All the expected tests are passing

============================================================ 215 passed, 9 skipped in 334.64s (0:05:34) =============================================================

Detail run of the failing test_kernel_builder.py test

root@85f386355464:~/cuda-quantum/python/tests/unittests# python3.11 -m pytest -v test_kernel_builder.py 
======================================================================== test session starts ========================================================================
platform linux -- Python 3.11.0rc1, pytest-7.4.2, pluggy-1.3.0 -- /usr/bin/python3.11
cachedir: .pytest_cache
rootdir: /root/cuda-quantum/python/tests/unittests
collected 11 items                                                                                                                                                  

test_kernel_builder.py::test_sdg_0_state PASSED                                                                                                               [  9%]
test_kernel_builder.py::test_sdg_1_state PASSED                                                                                                               [ 18%]
test_kernel_builder.py::test_sdg_0_state_negate PASSED                                                                                                        [ 27%]
test_kernel_builder.py::test_sdg_1_state_negate PASSED                                                                                                        [ 36%]
test_kernel_builder.py::test_tdg_0_state PASSED                                                                                                               [ 45%]
test_kernel_builder.py::test_tdg_1_state PASSED                                                                                                               [ 54%]
test_kernel_builder.py::test_tdg_0_state_negate PASSED                                                                                                        [ 63%]
test_kernel_builder.py::test_tdg_1_state_negate PASSED                                                                                                        [ 72%]
test_kernel_builder.py::test_can_progressively_build PASSED                                                                                                   [ 81%]
test_kernel_builder.py::test_from_state PASSED                                                                                                                [ 90%]
test_kernel_builder.py::test_exp_pauli PASSED                                                                                                                 [100%]

======================================================================== 11 passed in 3.31s =========================================================================

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 18, 2023

/ok to test

Command Bot: Processing...

@poojarao8
Copy link
Collaborator

This looks great and it'd be really useful in several ongoing projects with partners. Is there any way we can bump this up? @bettinaheim

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 26, 2023

/ok to test

Command Bot: Processing...

1 similar comment
@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 26, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 26, 2023

/ok to test

Command Bot: Processing...

2 similar comments
@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 26, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 26, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator Author

documenting this, for some reason on CI, we get a function call from libnvqir-custatevec-fp32?

Thread 1 "python3.11" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
#0  0x0000000000000000 in ?? ()
#1  0x00007f94325425eb in std::_Function_handler<void (bool), nvqir::CircuitSimulator::applyExpPauli(double, std::vector<unsigned long, std::allocator<unsigned long> > const&, cudaq::spin_op const&)::{lambda(cudaq::pauli, unsigned long)#1}::operator()(cudaq::pauli, unsigned long) const::{lambda(bool)#2}>::_M_invoke(std::_Any_data const&, bool&&) ()
   from /root/.local/lib/python3.11/site-packages/cudaq/../lib/libnvqir-custatevec-fp32.so
#2  0x00007f94324c2d4e in ?? ()
   from /root/.local/lib/python3.11/site-packages/cudaq/../lib/libnvqir-qpp.so
#3  0x00007f945faffbef in __quantum__qis__exp_pauli ()
   from /root/.local/lib/python3.11/site-packages/cudaq/../lib/libnvqir.so
#4  0x00007f946105f0b4 in __nvqpp__mlirgen____nvqppBuilderKernel_108506462586
    ()
#5  0x00007f946105f1b1 in __nvqppBuilderKernel_108506462586.thunk ()
#6  0x00007f945fce3e33 in ?? ()
   from /root/.local/lib/python3.11/site-packages/cudaq/../lib/libcudaq-platform-default.so
#7  0x00007f945fb532d5 in altLaunchKernel ()

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 26, 2023

/ok to test

Command Bot: Processing...

1 similar comment
@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 27, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 27, 2023

/ok to test

Command Bot: Processing...

@schweitzpgi
Copy link
Collaborator

schweitzpgi commented Sep 27, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 28, 2023

/ok to test

Command Bot: Processing...

@github-actions
Copy link

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

github-actions bot pushed a commit that referenced this pull request Sep 28, 2023
amccaskey and others added 7 commits September 29, 2023 12:55
Convert the headers to use ASCIIZ string literals for the final argument
to exp_pauli(). (Simplifies the AST presented to the bridge and falls
back to using code that handles string literals.)

Update LowerToQIR for the new types, fix bugs.

Fix up tests.
Signed-off-by: Alex McCaskey <[email protected]>
Signed-off-by: Alex McCaskey <[email protected]>
Signed-off-by: Alex McCaskey <[email protected]>
@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 29, 2023

/ok to test

Command Bot: Processing...

@github-actions
Copy link

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

github-actions bot pushed a commit that referenced this pull request Sep 29, 2023
Copy link
Collaborator

@1tnguyen 1tnguyen left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@schweitzpgi schweitzpgi added the enhancement New feature or request label Sep 29, 2023
@schweitzpgi schweitzpgi added this to the release 0.5.0 milestone Sep 29, 2023
@amccaskey
Copy link
Collaborator Author

amccaskey commented Sep 29, 2023

/ok to test

Command Bot: Processing...

@github-actions
Copy link

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

github-actions bot pushed a commit that referenced this pull request Sep 29, 2023
@schweitzpgi schweitzpgi merged commit da6d0b9 into NVIDIA:main Sep 29, 2023
109 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 29, 2023
@bettinaheim bettinaheim changed the title Add exp_pauli quantum instruction to the runtime and ASTBridge Add exp_pauli quantum instruction Nov 15, 2023
@bettinaheim bettinaheim changed the title Add exp_pauli quantum instruction Optimized support for applying exponentials of Paulis Nov 15, 2023
@amccaskey amccaskey deleted the applyExpPauli branch February 29, 2024 20:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants