NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
506 stars 182 forks source link

Support nested kernels in circuit visualization Draw() #2093

Open efratshabtai opened 2 months ago

efratshabtai commented 2 months ago

Required prerequisites

Describe the feature

Nested kernels are currently not supported in CUDA-Q circuit visualization.

mmvandieren commented 2 months ago

Following this since I'll use this feature immediately when it becomes available.

sacpis commented 2 months ago

Seems like this is already working.

mmvandieren commented 2 months ago

In which version of CUDA-Q? I think I have 0.8 running and it's not working there.

mmvandieren commented 2 months ago

My mistake, I found an error in my code that was causing the problem. It works for me now.

sacpis commented 2 months ago

Thanks @mmvandieren. Closing this now.

rtvuser1 commented 1 month ago

I can clarify what is meat by this issue. It does not appear to do what is required.

For example, here is a QFT mirror circuit that consists of an initialization step, followed by a QFT, then an inverse QFT (defined as kernels). When I create this circuit in Qiskit using sub-circuits, and then print it, it shows the sub-circuits with their names "qft" and "inv_qft" ... it does not print the gate implementation for these kernels. In this code, I then print the two kernels independently, giving me a lot of control as to what level of detail I want to display. The first image below is what I get when I independently print the top-level circuit and the two sub-circuits.

In CUDAQ, I have not found a way to accomplish the same thing. When I print the top-level circuit using the draw function, it always expands the circuit to include all the underlying gates, as in the second image below. You can imagine if I have a large circuit with many instances of the same kernel underneath but with different parameters, there would be much repetition. What I need is to be able to see just the instance of the sub-kernels, and then decide whether I want to print them or not.

In the second issue, you will see also an attempt to create a barrier using swap gates, just for the purposes of making the diagram clearer. In Qiskit the barrier operation does this and makes the circuit diagrams look better. Issue #1887 asks for barrier, but I had used this hacky technique since we do not have them.

1) The Qiskit version with sub-circuits and barriers:

Image

2) The cudaq version with hacky barriers and all gates expanded:

Image

Can this Issue be reopened?

sacpis commented 3 weeks ago

Reopening the issue to investigate further.