Skip to content

docs: add guide for extending NVQIR simulator#4946

Open
leodiasdc wants to merge 1 commit into
NVIDIA:mainfrom
leodiasdc:docs/nvqir-simulator-tutorial
Open

docs: add guide for extending NVQIR simulator#4946
leodiasdc wants to merge 1 commit into
NVIDIA:mainfrom
leodiasdc:docs/nvqir-simulator-tutorial

Conversation

@leodiasdc

Copy link
Copy Markdown

Fixes #3103. See #3099 for the original report of the two specific bugs
(stale MySimulator.cpp skeleton, missing GPURequirements argument to
nvqir_add_backend).

What was wrong

The using/extending/nvqir_simulator.rst page had drifted significantly
from the current CircuitSimulatorBase interface and nvqir_add_backend
CMake helper:

  • nvqir_add_backend(...) was missing the GPURequirements argument.
  • The example MySimulator.cpp referenced methods that no longer exist
    (resetQubitStateImpl), used a return type that no longer exists
    (cudaq::SampleResult), and called NVQIR_REGISTER_SIMULATOR with one
    argument instead of two.
  • The "Required Method Overrides" table was missing createStateFromData
    and clone (both required), and listed addQubitsToState as required
    even though it now has a default implementation.
  • The target-config section described a hand-authored NAME.config under
    /platforms; NVQIR now generates a .yml file under /targets
    automatically.

What this PR does

  • Corrects all of the above against the current
    runtime/nvqir/CircuitSimulator.h and cmake/modules/NVQIRConfig.cmake.in.
  • Replaces the inline, stale code block with a real, working, minimal dense
    state-vector simulator (docs/sphinx/snippets/cpp/using/extending/nvqir_simulator/),
    pulled into the doc via literalinclude instead of hand-copied prose.
  • Adds a "Toolchain requirements" section covering two things I hit while
    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 at
    load time with a symbol lookup error.
  • Adds a "Testing your simulator" section with a Bell-state smoke test.

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 + mz on 2 qubits, confirming applyGate,
measureQubit, and sample are all correct, not just that it compiles.)

Open question for maintainers

I added a small compile-only target in docs/CMakeLists.txt that builds
MySimulator.cpp in-tree against the nvqir target, so this doc can't
silently 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.

Signed-off-by: Leonardo Dias do Carmo <leonardo_carmo@usp.br>
@copy-pr-bot

copy-pr-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Documentation] Update the "Extending CUDA-Q with a new Simulator" page

1 participant