Required prerequisites
Describe the bug
When I try passing a rotation parameter to my custom unitary matrix, quake lowering step crashes
Steps to reproduce the bug
Run the following code (it was produced by a fuzzer)
#include <cudaq.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <complex>
using namespace std::complex_literals;
CUDAQ_REGISTER_OPERATION(
unitary_8,
2, // Number of qubits
1, // Number of params
(std::vector<std::complex<double>>{
{-0.22643183121344332, -0.28170883523153889},{-0.40854489588865311, -0.23182703999464191},{ 0.56339148737673705, -0.32040801291409404},{ -0.20139985753987433, 0.43368523623851524},
{-0.22948364985872663, -0.11759429313636136},{-0.049390029386749718, -0.5540633368296668},{ -0.70294020354468045, 0.017020556405626705},{ -0.22127619883545602, 0.28408712603137459},
{-0.36077134196874977, 0.0075805935264369184},{0.65103075550871925, 0.21282493600854432},{ 0.12668650115104951, 0.23502338199955278},{ 0.042338015172833761, 0.57234002849825372},
{-0.75314714195456511, -0.32470532890086296},{0.012258908382733833, -0.025218178145389653},{ 0.058968964561439352, 0.10368852236494151},{ 0.14012413361190376, -0.54100478124798823}
})
);
struct main_circuit {
uint64_t operator()() __qpu__ {
cudaq::qarray<2>reg_1063;
unitary_8(0.8, reg_1063[0], reg_1063[1]);
return 0;
}};
int main(int argc, char* argv[]) {
auto kernel = main_circuit{};
return 0;
}
This crashes with the stack trace below
Stack dump:
0. Program arguments: /home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake -D CUDAQ_SIMULATION_SCALAR_FP32 -I /home/ilan/programming/QFpp/external/cuda-quantum/tpls/fmt/include -I /home/ilan/programming/QFpp/external/cuda-quantum/build/cudaq/include -I /home/ilan/programming/QFpp/external/cuda-quantum/cudaq/include -I /home/ilan/programming/QFpp/external/cuda-quantum/runtime/include -I /home/ilan/programming/QFpp/external/cuda-quantum/tpls/json/single_include_fwd -I /home/ilan/programming/QFpp/external/cuda-quantum/runtime/internal/compiler/include --emit-llvm-file test.cpp -o test.qke
1. <eof> parser at end of file
#0 0x000060cd3d79cdb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x44bdb8)
#1 0x000060cd3d79a875 llvm::sys::RunSignalHandlers() (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x449875)
#2 0x000060cd3d79de01 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007fcc9a645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007fcc9a69eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007fcc9a69eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007fcc9a69eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007fcc9a64527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007fcc9a6288ff abort ./stdlib/abort.c:81:7
#9 0x000060cd3d75012d llvm::report_fatal_error(llvm::Twine const&, bool) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x3ff12d)
#10 0x000060cd3d74ff76 (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x3fef76)
#11 0x000060cd3dfa8859 (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc57859)
#12 0x000060cd3dfbe32a (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc6d32a)
#13 0x000060cd3dfb6ab8 cudaq::details::QuakeBridgeVisitor::VisitCallExpr(clang::CallExpr*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc65ab8)
#14 0x000060cd3df689e9 clang::RecursiveASTVisitor<cudaq::details::QuakeBridgeVisitor>::PostVisitStmt(clang::Stmt*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc179e9)
#15 0x000060cd3df688c5 clang::RecursiveASTVisitor<cudaq::details::QuakeBridgeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc178c5)
#16 0x000060cd3dfca979 cudaq::details::QuakeBridgeVisitor::TraverseCompoundStmt(clang::CompoundStmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc79979)
#17 0x000060cd3df6890a clang::RecursiveASTVisitor<cudaq::details::QuakeBridgeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc1790a)
#18 0x000060cd3dfa9729 cudaq::details::QuakeBridgeVisitor::TraverseFunctionDecl(clang::FunctionDecl*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc58729)
#19 0x000060cd3df66839 clang::RecursiveASTVisitor<cudaq::details::QuakeBridgeVisitor>::TraverseDecl(clang::Decl*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc15839)
#20 0x000060cd3df65805 cudaq::ASTBridgeAction::ASTBridgeConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xc14805)
#21 0x000060cd3d73a014 (anonymous namespace)::CudaQASTConsumer::HandleTranslationUnit(clang::ASTContext&) cudaq-quake.cpp:0:0
#22 0x000060cd3f14fe39 clang::ParseAST(clang::Sema&, bool, bool) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x1dfee39)
#23 0x000060cd3ddfb93d clang::FrontendAction::Execute() (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xaaa93d)
#24 0x000060cd3dd703a4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0xa1f3a4)
#25 0x000060cd3ef9465e clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x1c4365e)
#26 0x000060cd3ef94303 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x1c43303)
#27 0x000060cd3ef93c52 clang::tooling::ToolInvocation::run() (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x1c42c52)
#28 0x000060cd3ef9349b clang::tooling::runToolOnCodeWithArgs(std::unique_ptr<clang::FrontendAction, std::default_delete<clang::FrontendAction>>, llvm::Twine const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, llvm::Twine const&, llvm::Twine const&, std::shared_ptr<clang::PCHContainerOperations>) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x1c4249b)
#29 0x000060cd3ef93125 clang::tooling::runToolOnCodeWithArgs(std::unique_ptr<clang::FrontendAction, std::default_delete<clang::FrontendAction>>, llvm::Twine const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, llvm::Twine const&, llvm::Twine const&, std::shared_ptr<clang::PCHContainerOperations>, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>> const&) (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x1c42125)
#30 0x000060cd3d73447c main (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x3e347c)
#31 0x00007fcc9a62a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#32 0x00007fcc9a62a28b call_init ./csu/../csu/libc-start.c:128:20
#33 0x00007fcc9a62a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#34 0x000060cd3d72f8e5 _start (/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake+0x3de8e5)
external/cuda-quantum/build/bin/nvq++: line 27: 211233 Aborted (core dumped) "$@"
failed: "/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-quake -D CUDAQ_SIMULATION_SCALAR_FP32 -I /home/ilan/programming/QFpp/external/cuda-quantum/tpls/fmt/include -I /home/ilan/programming/QFpp/external/cuda-quantum/build/cudaq/include -I /home/ilan/programming/QFpp/external/cuda-quantum/cudaq/include -I /home/ilan/programming/QFpp/external/cuda-quantum/runtime/include -I /home/ilan/programming/QFpp/external/cuda-quantum/tpls/json/single_include_fwd -I /home/ilan/programming/QFpp/external/cuda-quantum/runtime/internal/compiler/include --emit-llvm-file test.cpp -o test.qke"
Setting the expected number of params to 0 compiles.
Expected behavior
Compiler should not crash
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q version:
b04dee51
- Python version: 3.12.3
- C++ compiler: clang 18.1.3
- Operating system: Ubuntu 24.04
Suggestions
No response
Required prerequisites
Describe the bug
When I try passing a rotation parameter to my custom unitary matrix, quake lowering step crashes
Steps to reproduce the bug
Run the following code (it was produced by a fuzzer)
This crashes with the stack trace below
Setting the expected number of params to 0 compiles.
Expected behavior
Compiler should not crash
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
b04dee51Suggestions
No response