Skip to content

Instantly share code, notes, and snippets.

@anthony-santana
Created October 19, 2023 19:33
Show Gist options
  • Save anthony-santana/d394888ad14853fe5825a59bd4d518f5 to your computer and use it in GitHub Desktop.
Save anthony-santana/d394888ad14853fe5825a59bd4d518f5 to your computer and use it in GitHub Desktop.
A10: Better error messages for incorrect argument signature to sample
Take the following kernel and sample call
```
int main() {
auto [kernel, value] = cudaq::make_kernel<float>();
auto q = kernel.qalloc();
kernel.x(q);
// Calling sample but not passing along a concrete argument for `value`
auto result = cudaq::sample(kernel);
result.dump();
}
```
Returns the following error (truncated):
```
new_test.cpp:20:17: error: no matching function for call to 'sample'
auto result = cudaq::sample(kernel);
^~~~~~~~~~~~~
/usr/local/cudaq/include/cudaq/algorithms/sample.h:199:15: note: candidate template ignored: constraints not satisfied [with QuantumKernel = std::tuple_element<0, cudaq::kernel_builder<float>>::type &, Args = <>]
sample_result sample(QuantumKernel &&kernel, Args &&...args) {
^
/usr/local/cudaq/include/cudaq/algorithms/sample.h:198:12: note: because 'cudaq::kernel_builder<float> &' does not satisfy 'SampleCallValid'
requires SampleCallValid<QuantumKernel, Args...>
...
```
I have yet to check the error on observe call, or on non-builder kernels, but I'd expect a message along the lines of "Your kernel accepts {1} arguments but {0} were provided to cudaq::sample"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment