NVIDIA / NVIDIA/cuda-quantum

nested kernels causing an error

Open
#2,803 1 comment 0 reactions 1 assignee View on GitHub

@annagrin is already working on this.

Since Apr 18, 2025.

stale-notified
Dominant language
C++
Stars
1.1k
Forks
455
Avg merge
1d 22h
Merged PRs (30d)
165

Description

Required prerequisites
  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!
Describe the bug

See the code block in the section below which produces error messages.

If you uncomment out the cause_error_kernel, it runs fine. So the nested kernels are fine.

If you uncomment out my_inner_subkernel1, the code works fine (even with the cause_error_kernel). So the cause_error_kernel by itself isn't the problem. It's somehow the combination of the 2.

Error message when both my_inner_subkernel1 and cause_error_kernel are executed.

Cell In[178], [line 30](vscode-notebook-cell:?execution_count=178&line=30)
     [27](vscode-notebook-cell:?execution_count=178&line=27)     cause_error_kernel(qubits) # code runs fine with this commented out
     [29](vscode-notebook-cell:?execution_count=178&line=29) num_qubits = 4
---> [30](vscode-notebook-cell:?execution_count=178&line=30) results = cudaq.sample(test_kernel, num_qubits, shots_count=1000)
     [31](vscode-notebook-cell:?execution_count=178&line=31) print(results)

File /opt/nvidia/cudaq/cudaq/runtime/sample.py:86, in sample(kernel, shots_count, noise_model, *args)
     [83](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/runtime/sample.py:83)             cudaq_runtime.setExecutionContext(ctx)
     [84](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/runtime/sample.py:84)     return counts
---> [86](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/runtime/sample.py:86) kernel(*args)
     [87](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/runtime/sample.py:87) res = ctx.result
     [88](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/runtime/sample.py:88) cudaq_runtime.resetExecutionContext()

File /opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:423, in PyKernelDecorator.__call__(self, *args)
    [420](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:420) self.capturedDataStorage = self.createStorage()
    [422](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:422) # Compile, no-op if the module is not None
--> [423](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:423) self.compile()
    [425](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:425) if len(args) != len(self.argTypes):
    [426](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:426)     emitFatalError(
    [427](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:427)         f"Incorrect number of runtime arguments provided to kernel `{self.name}` ({len(self.argTypes)} required, {len(args)} provided)"
    [428](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:428)     )

File /opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:210, in PyKernelDecorator.compile(self)
    [207](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:207) if self.module != None:
    [208](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:208)     return
--> [210](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:210) self.module, self.argTypes, extraMetadata = compile_to_mlir(
    [211](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:211)     self.astModule,
    [212](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:212)     self.metadata,
    [213](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:213)     self.capturedDataStorage,
    [214](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:214)     verbose=self.verbose,
    [215](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:215)     returnType=self.returnType,
    [216](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:216)     location=self.location,
    [217](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:217)     parentVariables=self.globalScopedVars)
    [219](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:219) # Grab the dependent capture variables, if any
    [220](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:220) self.dependentCaptures = extraMetadata[
    [221](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:221)     'dependent_captures'] if 'dependent_captures' in extraMetadata else None

File /opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4006, in compile_to_mlir(astModule, metadata, capturedDataStorage, **kwargs)
   [4000](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4000) for funcName in sortedOrder:
   [4001](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4001)     if funcName != vis.kernelName and funcName in depKernels:
   [4002](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4002)         # Build an AST Bridge and visit the dependent kernel
   [4003](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4003)         # function. Provide the dependent kernel source location as well.
   [4004](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4004)         PyASTBridge(capturedDataStorage,
   [4005](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4005)                     existingModule=bridge.module,
-> [4006](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4006)                     locationOffset=depKernels[funcName][1]).visit(
   [4007](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4007)                         depKernels[funcName][0])
   [4009](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4009) # Build the MLIR Module for this kernel
   [4010](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:4010) bridge.visit(astModule)

File /usr/lib/python3.10/ast.py:418, in NodeVisitor.visit(self, node)
    [416](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:416) method = 'visit_' + node.__class__.__name__
    [417](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:417) visitor = getattr(self, method, self.generic_visit)
--> [418](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:418) return visitor(node)

File /opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:854, in PyASTBridge.generic_visit(self, node)
    [852](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:852)     for item in value:
    [853](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:853)         if isinstance(item, ast.AST):
--> [854](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:854)             self.visit(item)
    [855](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:855) elif isinstance(value, ast.AST):
    [856](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:856)     self.visit(value)

File /usr/lib/python3.10/ast.py:418, in NodeVisitor.visit(self, node)
    [416](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:416) method = 'visit_' + node.__class__.__name__
    [417](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:417) visitor = getattr(self, method, self.generic_visit)
--> [418](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:418) return visitor(node)

File /opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:967, in PyASTBridge.visit_FunctionDef(self, node)
    [965](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:965)         if isinstance(constant.value, str):
    [966](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:966)             startIdx = 1
--> [967](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:967) [self.visit(n) for n in node.body[startIdx:]]
    [968](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:968) # Add the return operation
    [969](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:969) if not self.hasTerminator(self.entry):

File /opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:967, in <listcomp>(.0)
    [965](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:965)         if isinstance(constant.value, str):
    [966](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:966)             startIdx = 1
--> [967](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:967) [self.visit(n) for n in node.body[startIdx:]]
    [968](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:968) # Add the return operation
    [969](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:969) if not self.hasTerminator(self.entry):

File /usr/lib/python3.10/ast.py:418, in NodeVisitor.visit(self, node)
    [416](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:416) method = 'visit_' + node.__class__.__name__
    [417](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:417) visitor = getattr(self, method, self.generic_visit)
--> [418](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:418) return visitor(node)

File /opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1005, in PyASTBridge.visit_Expr(self, node)
   [1002](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1002)     if isinstance(constant.value, str):
   [1003](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1003)         return
-> [1005](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1005) self.visit(node.value)

File /usr/lib/python3.10/ast.py:418, in NodeVisitor.visit(self, node)
    [416](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:416) method = 'visit_' + node.__class__.__name__
    [417](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:417) visitor = getattr(self, method, self.generic_visit)
--> [418](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/usr/lib/python3.10/ast.py:418) return visitor(node)

File /opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1869, in PyASTBridge.visit_Call(self, node)
   [1865](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1865)             node.func.id = var.name
   [1867](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1867) if node.func.id in globalKernelRegistry:
   [1868](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1868)     # If in `globalKernelRegistry`, it has to be in this Module
-> [1869](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1869)     otherKernel = SymbolTable(self.module.operation)[nvqppPrefix +
   [1870](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1870)                                                      node.func.id]
   [1871](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1871)     fType = otherKernel.type
   [1872](https://vscode-remote+attached-002dcontainer-002b7b22636f6e7461696e65724e616d65223a222f66657276656e745f6d636e756c7479222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d.vscode-resource.vscode-cdn.net/opt/nvidia/cudaq/cudaq/kernel/ast_bridge.py:1872)     if len(fType.inputs) != len(node.args):

KeyError: "Symbol '__nvqpp__mlirgen__my_inner_subkernel2' not in the symbol table."

Steps to reproduce the bug
@cudaq.kernel
def my_inner_subkernel1(qubits: cudaq.qview, aux_qubit: cudaq.qview):
    my_inner_subkernel2(qubits, aux_qubit)


@cudaq.kernel
def my_inner_subkernel2(qubits: cudaq.qview, aux_qubit: cudaq.qview):
    z.ctrl(qubits, aux_qubit[0])

@cudaq.kernel
def mysubkernel(qubits: cudaq.qview, aux_qubit: cudaq.qview): 
    
    my_inner_subkernel1(qubits, aux_qubit) # code runs fine if this is commented out
    my_inner_subkernel2(qubits, aux_qubit)

@cudaq.kernel
def cause_error_kernel(qubits: cudaq.qview):
    h(qubits)
    
    
@cudaq.kernel
def test_kernel(num_qubits : int):
    qubits = cudaq.qvector(4)
    aux_qubit = cudaq.qvector(1)
    x(qubits)
    mysubkernel(qubits, aux_qubit)
    cause_error_kernel(qubits) # code runs fine with this commented out
    
num_qubits = 4
results = cudaq.sample(test_kernel, num_qubits, shots_count=1000)
Expected behavior

code should execute without error message. the result should be equivalent to

@cudaq.kernel
def no_nesting_kernel(num_qubits : int):
    qubits = cudaq.qvector(4)
    aux_qubit = cudaq.qvector(1)
    x(qubits)
    z.ctrl(qubits, aux_qubit[0])
    z.ctrl(qubits, aux_qubit[0])
    h(qubits)
Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment
  • CUDA-Q version: 3.10.12
  • Python version: 0.10.0
  • C++ compiler:
  • Operating system: Mac OS
Suggestions

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.