docs: add guide for extending NVQIR simulator#4946
Open
leodiasdc wants to merge 1 commit into
Open
Conversation
Signed-off-by: Leonardo Dias do Carmo <leonardo_carmo@usp.br>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3103. See #3099 for the original report of the two specific bugs
(stale
MySimulator.cppskeleton, missingGPURequirementsargument tonvqir_add_backend).What was wrong
The
using/extending/nvqir_simulator.rstpage had drifted significantlyfrom the current
CircuitSimulatorBaseinterface andnvqir_add_backendCMake helper:
nvqir_add_backend(...)was missing theGPURequirementsargument.MySimulator.cppreferenced methods that no longer exist(
resetQubitStateImpl), used a return type that no longer exists(
cudaq::SampleResult), and calledNVQIR_REGISTER_SIMULATORwith oneargument instead of two.
createStateFromDataand
clone(both required), and listedaddQubitsToStateas requiredeven though it now has a default implementation.
NAME.configunder/platforms; NVQIR now generates a.ymlfile under/targetsautomatically.
What this PR does
runtime/nvqir/CircuitSimulator.handcmake/modules/NVQIRConfig.cmake.in.state-vector simulator (
docs/sphinx/snippets/cpp/using/extending/nvqir_simulator/),pulled into the doc via
literalincludeinstead of hand-copied prose.testing that weren't documented at all: the C++20 requirement, and the
fact that CUDA-Q's binaries are built with Clang+libc++, so a default
system
g++/libstdc++ build configures and compiles fine but fails atload time with a
symbol lookup error.Testing
Built and ran against a real CUDA-Q 0.15.0 install:
```
$ cmake .. -G Ninja -DNVQIR_DIR=... -DCMAKE_CXX_COMPILER=.../clang++ -DCMAKE_CXX_FLAGS=-stdlib=libc++
$ ninja install
-- Installing: .../lib/libnvqir-MySimulator.so
-- Installing: .../targets/MySimulator.yml
$ nvq++ bell.cpp --target MySimulator -o bell && ./bell
{ 00:471 11:529 }
```
(Bell state:
h+ ctrl-x+mzon 2 qubits, confirmingapplyGate,measureQubit, andsampleare all correct, not just that it compiles.)Open question for maintainers
I added a small compile-only target in
docs/CMakeLists.txtthat buildsMySimulator.cppin-tree against thenvqirtarget, so this doc can'tsilently drift again. I wasn't able to validate this against a full
in-tree build in my environment — happy to drop it if it causes ordering
issues, or if there's a preferred place for this kind of doc-example
compile check.