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
427 stars 149 forks source link

Allow for more complex builder gate signatures in library mode #867

Open anthony-santana opened 8 months ago

anthony-santana commented 8 months ago

Required prerequisites

Describe the bug

The following code only passes in emulation, but not in library mode. The bug is a qpp dimension issue (more triage needed to determine what impact, if any, on nvidia backends), meaning we will likely need to update somewhere along the function stack of qpp::applyGate.

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

// fails with: `nvq++ test.cpp && ./a.out`
// passes with: `nvq++ --target quantinuum --emulate test.cpp && ./a.out`

int main() {
    auto kernel = cudaq::make_kernel();
    // Using a mixture of qregs and qubits as controls
    auto controls1 = kernel.qalloc(2);
    auto controls2 = kernel.qalloc(2);
    auto control3 = kernel.qalloc();
    auto target = kernel.qalloc();

    // bug with any control gate
    kernel.x<cudaq::ctrl>(controls1, controls2, control3, target);

    auto counts = cudaq::sample(kernel);
    counts.dump();
}

Runtime error:

terminate called after throwing an instance of 'qpp::exception::SubsysMismatchDims'
  what():  qpp::applyCTRL(): Subsystems mismatch dimensions! [ctrl/dims]

Steps to reproduce the bug

Run the above code with nvq++ test.cpp && ./a.out

Expected behavior

The behavior should match the output of nvq++ --target quantinuum --emulate test.cpp && ./a.out .

Note: the reason this is an issue only in library mode is because of the compiler passes that are specific to emulation. They will redefine the multi-controls as two qubit gates, circumventing the dimension issue.

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

Suggestions

No response

amccaskey commented 8 months ago

This and #805 are related.