NVIDIA / NVIDIA/cuda-quantum

Simplify syntax to extract expectation values

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

Nobody has claimed this yet.

language 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

Syntax for a simple hamiltonian is:

hamiltonian = spin.z(0)

results = cudaq.observe(kernel, hamiltonian)

exp_vals = results.expectation_z()

When we have a list hamiltonian, we have to run a for loop to extract results:


hamiltonian = [spin.z(0), spin.z(1)]

results = cudaq.observe(kernel, hamiltonian)

exp_vals = [results[i].expectation_z() for i in range(len(results))]

The for loop is cumbersome. Can we not allow expectation_z() to broadcast automatically over the results it is presented with?

Thanks team.

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 tracing the cudaq.observe results and expectation_z() entry points shown in the issue, including both scalar and list Hamiltonian cases. Determine the intended broadcast behavior and add coverage for it in the relevant tests. Done means expectation_z() handles a list of results without a caller-written loop while preserving the scalar behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api, quantum-computing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.