KEMBAR78
Handling negative lower and upper bound of a slice by sacpis · Pull Request #3022 · NVIDIA/cuda-quantum · GitHub
Skip to content

Conversation

@sacpis
Copy link
Collaborator

@sacpis sacpis commented Jun 9, 2025

Handling negative lower and upper bound of a slice

Fixes #2930 and #2893

import cudaq

@cudaq.kernel
def bar():
    qubits = cudaq.qvector(10)
    h(qubits[0:3])
    controls = qubits[0:-1]
    target = qubits[-1]

    x.ctrl(controls, target)

print(cudaq.draw(bar))
print(cudaq.sample(bar))

Output

root@f672ccb568e7:/workspaces/cuda-quantum# python3 test.py 
     ╭───╮     
q0 : ┤ h ├──●──
     ├───┤  │  
q1 : ┤ h ├──●──
     ├───┤  │  
q2 : ┤ h ├──●──
     ╰───╯  │  
q3 : ───────●──
            │  
q4 : ───────●──
            │  
q5 : ───────●──
            │  
q6 : ───────●──
            │  
q7 : ───────●──
            │  
q8 : ───────●──
          ╭─┴─╮
q9 : ─────┤ x ├
          ╰───╯

{ 0000000000:120 0010000000:130 0100000000:129 0110000000:111 1000000000:151 1010000000:118 1100000000:131 1110000000:110 }

@sacpis sacpis marked this pull request as ready for review June 9, 2025 23:49
github-actions bot pushed a commit that referenced this pull request Jun 10, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jun 10, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@sacpis sacpis requested a review from schweitzpgi June 10, 2025 22:25
github-actions bot pushed a commit that referenced this pull request Jun 11, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

sacpis added 3 commits June 10, 2025 20:57
Signed-off-by: Sachin Pisal <spisal@nvidia.com>
Signed-off-by: Sachin Pisal <spisal@nvidia.com>
Signed-off-by: Sachin Pisal <spisal@nvidia.com>
@sacpis sacpis force-pushed the fix_negative_upper_bound_of_a_slice branch from 2310a53 to 983d8ae Compare June 11, 2025 04:14
Copy link
Collaborator

@1tnguyen 1tnguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sacpis sacpis enabled auto-merge (squash) June 11, 2025 04:19
@sacpis sacpis changed the title Handling negative upper bound of a slice Handling negative lower and upper bound of a slice Jun 11, 2025
@sacpis sacpis merged commit aa83334 into NVIDIA:main Jun 11, 2025
193 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 11, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

annagrin pushed a commit to annagrin/cuda-quantum that referenced this pull request Jun 17, 2025
* Handling negative upper bound of a slice

Signed-off-by: Sachin Pisal <spisal@nvidia.com>

* Handling negative start index in a slice

Signed-off-by: Sachin Pisal <spisal@nvidia.com>

* adding test for negative index

Signed-off-by: Sachin Pisal <spisal@nvidia.com>

---------

Signed-off-by: Sachin Pisal <spisal@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
@bettinaheim bettinaheim added the release notes Changes need to be captured in the release notes label Jul 22, 2025
@bettinaheim bettinaheim added this to the release 0.12.0 milestone Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes Changes need to be captured in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative slice does not work

4 participants