NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
507 stars 182 forks source link

Support injecting MLIR passes in JIT compilation #839

Open ravidalon opened 1 year ago

ravidalon commented 1 year ago

Required prerequisites

Describe the feature

Injecting a custom MLIR pass into cudaq-opt is possible, as described here. It would also be useful to inject custom passes into the JIT compiler, for compilation of runtime kernels and for Python support. In addition, it would be useful to support defining the pass order to be run by the JIT compiler. In particular, requiring that some passes are run before the custom pass.

schweitzpgi commented 12 months ago

Are you thinking of something in addition to or distinct from the PLATFORM_LOWERING_CONFIG option in the .config files?

ravidalon commented 11 months ago

It seems similar to what we are looking for, but there are some differences:

  1. This does not allow registering and loading custom passes
  2. This is directly tied to using a specific backend, while we would want to use a similar mechanism regardless of backend (or, as a first step, with the simulator backends)
  3. This does not seem to be used when invoking a kernel using kernel_builder (here)
schweitzpgi commented 11 months ago

It seems similar to what we are looking for, but there are some differences:

  1. This does not allow registering and loading custom passes
  2. This is directly tied to using a specific backend, while we would want to use a similar mechanism regardless of backend (or, as a first step, with the simulator backends)
  3. This does not seem to be used when invoking a kernel using kernel_builder (here)

Thanks for the feedback. That's very helpful.

There is a mechanism to create a custom pass plugin. You can find the example in unittests/plugin.

ravidalon commented 11 months ago

Following a discussion with @1tnguyen, we have one main question regarding this issue: is it possible to load a custom pass for RemoteRESTQPU.cpp:lowerQuakeCode? If it is, then this issue can be closed I think

amccaskey commented 11 months ago

Yes this should be possible - e.g. see an example here https://github.com/NVIDIA/cuda-quantum/blob/main/runtime/cudaq/platform/default/rest/helpers/quantinuum/quantinuum.config#L19. You can specify the pass in this string, as long as it's part of the framework.

oryarnitzky-classiq commented 11 months ago

@amccaskey Thank you! To my understanding, "as long as it's part of the framework" is referring to passes that are part of cudaq-opt. What about passes that are implemented in plugins, as described at https://nvidia.github.io/cuda-quantum/latest/using/advanced/mlir_pass.html ?