NVIDIA / NVIDIA/cuda-quantum

[RFC] Create a python type or submodule analogous to `cudaq::types::GATE`

Open
#525 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Required prerequisites
  • Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.
Describe the feature

When adding noise channels in C++, a programmer passes the gate for the channel as a cudaq::types::GATE template argument. Example:

noise.add_channel<cudaq::types::x>(...)

In Python, however, we rely on strings for this gate specification

noise.add_channel('x', ...)

My suggestion is to create an enum, or a new types submodule, that mirrors the C++ version.

I believe this will make the interface a bit easier to follow, especially if you pass in an invalid gate. As is, an invalid gate will return the error

    noise.add_channel('e', [0], bit_flip_zero)
RuntimeError: Invalid quantum op for noise_model::add_channel (e).

which is a clear error message, but doesn't give a good starting point for finding acceptable gates. You would have to refer to our kernel builder documentation to find the list of gates, and not all are allowed here.

This change would look more like this:

a) A completely invalid type

    noise.add_channel(cudaq.types.E, [0], channel)
AttributeError:'cudaq.types' object has no attribute 'E'

b) valid cudaq::type that we can't add noise to. This is more likely in a scenario where the types class is re-used elsewhere and has to be extended beyond just the allowed noisy gates.

    noise.add_channel(cudaq.types.mz, [0], channel)
RuntimeError: Invalid `cudaq.types` for noise_model::add_channel (cudaq::types::mz).

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.

Research direction

Start by comparing the C++ cudaq::types::GATE interface with the Python noise.add_channel gate argument described here. Define the Python type or submodule behavior, including acceptable noisy gates and handling of invalid or unsupported types; the issue provides no file or test paths to begin with.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.