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

Support using complex numbers and lists in kernel functions #1516

Closed
wants to merge 24 commits into from

Conversation

annagrin
Copy link
Collaborator

Make sure we can use complex numbers inside kernel function definitions, for example:

  c = [.70710678 + 0j, 0., 0., 0.70710678]
  
  # Pass a list of complex numbers as a parameter
  @cudaq.kernel
  def test_complex_vec_param(vec : list[complex]):
      c1 = vec

  counts = cudaq.sample(test_complex_vec_param, c)
  # Capture a list of complex numbers
  @cudaq.kernel
  def test_complex_vec_capture():
      c1 = c

  counts = cudaq.sample(test_complex_vec_capture)
  # Define a list of complex numbers inside a kernel
  @cudaq.kernel
  def test_complex_vec_definition():
      c1 = [1.0 + 0j, 0., 0., 1.]

  counts = cudaq.sample(test_complex_vec_definition)

Towards: #1086

amccaskey and others added 24 commits April 8, 2024 09:18
…ion (NVIDIA#1115)

Initial library mode implementation

---------

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Co-authored-by: A.M. Santana <39563805+anthony-santana@users.noreply.github.com>
…VIDIA#1141)

* Add support for the new qvector constructor with an initialization list
to the bridge.

* Update add-dealloc to account for InitializeStateOp being present.

Add test.
* Fixes for the lower to QIR pass.

  - Splits subgraph matching from the conversion pass. The conversion
    rewriter doesn't really let one do both at the same time given the
    way it traversing the IR.
  - Add a new codegen dialect. Only used in codegen. Part of the
    previous bullet. The dialect will be the logical point to add any
    future combination ops.
  - Removes the extra canonicalizer pass

* clang-format
These changes adjust the placement of quake.dealloc ops to account for
the presence of state initializers in local scopes.
* [Core] Add complex types and values.

Fix traversals of casts. Cast expressions sometimes didn't actually
traverse the information required.

Update the test.

Get the test case working end-to-end.

* clang-format

* Update test for run variations.

* Reformat the comments.
* Add qudit initializer to bridge.

* Add a hack to work around visiting allocators, etc. Need to eventually
handle "NOP" types and arguments in a better way than skipping over them
when it is convenient.
…er (NVIDIA#1474)

at runtime

According to MLIR: "The process of loading a Dialect in the context is
not thread-safe, which forces all involved Dialects to be loaded before
the multi-threaded pass manager starts the execution."

This PR makes sure that we load all the dialects when MLIR is needed at
runtime, hence may be used in a multi-threading environment (async.
execution).

In particular, add a method to register the internal CodeGenDialect,
which is only used by passes (not the frontend).

Make sure that we load all Dialects in C++ (CUDAQ MLIRRuntime) and Python (builder/decorator).

Tested by: running python/tests/remote/test_remote_platform.py with
these changes on the features/qalloc branch.
* Compute the correct number of qubits.

The initializer length must be 2**q where q is the number of qubits.

* Make the log calls consistent. Fix up the QIR checks.
* [featues/qalloc] Use cc dialect.

Port the intrinsics to cc dialect, which should have everything
required.
Add external/private linkage control.

* Review comment: replace the inline MLIR string with direct builder
calls.

* Replace expanded complex types.

* Remove more LLVMIR code.
…eVecSimulator kron prod (NVIDIA#1482)

* Update builder to support vector state input. Implement Cusv kronprod

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
* wip on python kernel builder support

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* working tests for constant numpy state data

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* add some error checks

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* Full implementation of qalloc(state) for python kernel builder

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* fix bug for input complex<f32>, add a test

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* address pr comments

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* add normalization check

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

* Fix issue with qalloc_initialization filecheck test

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>

---------

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
…VIDIA#1495)

* [features/qalloc] Simplify the kernel_builder's use of vector data.

Fixes a bug in the implementation where a vector captured as an initial
state by the builder may not accurately reflect the content of the
vector when the kernel is actually invoked. This captures a reference to
the initialization vector instead of the data in the vector at the point
of creating the kernel.

Simplifies the state vector cache to be a simple vector instead of a
sorted map. Eliminates the use of hashes. Uses generic callbacks,
specialized by type, to fetch the length and data pointer from the
captured vector. Uses a type-safe variant for the two cases. Because
this uses callbacks, the linker should fail if the kernel is not run in
an environment that contains the runtime (such as on hardware).

* Fix CI issues.

* Workaround CI spelling checker.

* Document the capture of vector variables more in the code.

* Add patch to workaround CI failures
* [features/qalloc] Documentation.

Add an example using kernel builder's qalloc with a vector initializer.

* Change dump methods to be const. They don't change the sample result and
this allows them to be called on `const` values.

* Make sure to add the FP64 flag when in library mode.

* Fix whining by the spelling checker.

* Another stab at the precision mismatch failures in the CI.

Make the precision default to double.

* Make the new predefine unconditional wrt library mode.

* Fix a cudaq-quake error.

* Update docs/sphinx/examples/cpp/other/builder/builder.cpp

Co-authored-by: A.M. Santana <39563805+anthony-santana@users.noreply.github.com>

---------

Co-authored-by: A.M. Santana <39563805+anthony-santana@users.noreply.github.com>
* [features/qalloc] Not all targets are always available.

The nvidia and nvidia-fp64 targets may not be built or installed
depending on the configuration, so they cannot be relied upon to always
be present. This adds code to catch the exception throw when looking up
these targets fails.

* Skip more

* Fix bug in cmake file.

* Add copyright header.

* Split the test and use pytest conditions to determine if the test is
runnable. (per review)

* Make sure target is set after the reset.

* Add missing return keyword.
Copy link

copy-pr-bot bot commented Apr 15, 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.

Copy link

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the Contributor License Agreement and I hereby accept the Terms.


3 out of 4 committers have signed the CLA.
@amccaskey
@schweitzpgi
@1tnguyen
@annagrin
You can retrigger this bot by commenting recheck in this Pull Request

@annagrin annagrin closed this Apr 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 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.

4 participants