Skip to content

Conversation

TharrmashasthaPV
Copy link
Contributor

@TharrmashasthaPV TharrmashasthaPV commented Apr 20, 2021

Summary

Fixes part of #6475 . This PR extends the current text drawer to support drawing circuits that contain gates or instructions that are conditioned on a single classical bit.

Details and comments

This PR follows #6018 . The current text drawer breaks when trying to draw circuits that contain instructions with single bit conditioning. This PR fixes this issue. Two tests have been added. Below are some examples of circuits drawn after this PR.

With cregbundle = True:

         ┌───┐                          
 q_0: ───┤ H ├───────────────────■──────
         └─╥─┘      ┌───┐      ┌─┴─┐    
 q_1: ─────╫────────┤ X ├──────┤ X ├────
           ║        └─╥─┘      └─╥─┘    
 q_2: ─────╫──────────╫──────────╫──────
           ║          ║     ┌────╨─────┐
c1: 2/═════╬══════════╬═════╡ c1_0 = T ╞
      ┌────╨────┐┌────╨────┐└──────────┘
 c: 2/╡ c_1 = F ╞╡ c_0 = T ╞════════════
      └─────────┘└─────────┘            

With cregbundle = False:

      ┌───┐          
 q_0: ┤ H ├───────■──
      └─╥─┘┌───┐┌─┴─┐
 q_1: ──╫──┤ X ├┤ X ├
        ║  └─╥─┘└─╥─┘
 q_2: ──╫────╫────╫──
        ║    ║    ║  
c1_0: ══╬════╬════■══
        ║    ║    =1 
c1_1: ══╬════╬═══════
        ║    ║       
 c_0: ══╬════■═══════
        ║    =1      
 c_1: ══o════════════
        =0           

@TharrmashasthaPV TharrmashasthaPV changed the title [WIP] MPL drawer extended for drawing circuits with single classical bit conditioning [WIP] Text drawer extended for drawing circuits with single classical bit conditioning Apr 20, 2021
@TharrmashasthaPV TharrmashasthaPV marked this pull request as ready for review May 27, 2021 11:28
@TharrmashasthaPV TharrmashasthaPV changed the title [WIP] Text drawer extended for drawing circuits with single classical bit conditioning Text drawer extended for drawing circuits with single classical bit conditioning May 27, 2021
@javabster
Copy link
Contributor

Hi @javabster . I think that is because the default value of vertical compression in _text_circuit_drawer() method is high. I guess that's why there's an overlap in the H gate. However, the value of vertical compression in the default .draw() method is medium. For instance the same test circuit when drawn using .draw() method gives me an output as below

image

Ok it's good that it isn't a bug in .draw() but I think it should still be fixed for the _text_circuit_drawer(), perhaps by adjusting the vertical compression for cases like this

@TharrmashasthaPV
Copy link
Contributor Author

TharrmashasthaPV commented Jul 7, 2021

Hi @javabster . I think that is because the default value of vertical compression in _text_circuit_drawer() method is high. I guess that's why there's an overlap in the H gate. However, the value of vertical compression in the default .draw() method is medium. For instance the same test circuit when drawn using .draw() method gives me an output as below
image

Ok it's good that it isn't a bug in .draw() but I think it should still be fixed for the _text_circuit_drawer(), perhaps by adjusting the vertical compression for cases like this

If I am understanding correct, should we change the value of vertical_compression of text_circuit_drawer() to medium for these tests? Or would it be better if we have tests for both medium and default vertical compressions in the tests?

@javabster
Copy link
Contributor

Hi @javabster . I think that is because the default value of vertical compression in _text_circuit_drawer() method is high. I guess that's why there's an overlap in the H gate. However, the value of vertical compression in the default .draw() method is medium. For instance the same test circuit when drawn using .draw() method gives me an output as below
image

Ok it's good that it isn't a bug in .draw() but I think it should still be fixed for the _text_circuit_drawer(), perhaps by adjusting the vertical compression for cases like this

If I am understanding correct, should we change the value of vertical_compression of text_circuit_drawer() to medium for these tests? Or would it be better if we have tests for both medium and default vertical compressions in the tests?

yep @TharrmashasthaPV that's correct!

@1ucian0 any thoughts about using _text_circuit_drawer() instead of .draw()`?

@1ucian0
Copy link
Member

1ucian0 commented Jul 12, 2021

@1ucian0 any thoughts about using _text_circuit_drawer() instead of .draw()?

In other tests we do the same. I think is good for now. At same point probably makes sense to refactor them at some point.

@1ucian0
Copy link
Member

1ucian0 commented Jul 12, 2021

After #6370, it seems that we are moving towards bullet representations when they are possible.

Wouldn't be better something like this?

qr = QuantumRegister(2, "qr")
cr = ClassicalRegister(2, "cr")
circuit = QuantumCircuit(qr, cr)
circuit.h(qr[0]).c_if(cr[0], 1)
circuit.h(qr[1]).c_if(cr[1], 0)
circuit.draw('text', cregbundle=False)
       ┌───┐        
qr_0: ─┤ H ├────────
       └─╥─┘ ┌───┐ 
qr_1: ───╫───┤ H ├─
         ║   └─╥─┘ 
cr_0: ═══■═════╬═══
               ║
cr_1: ═════════o═══

(may understanding of your code is that this change would be easy to make. Please, ignore my comment otherwise)

@TharrmashasthaPV
Copy link
Contributor Author

After #6370, it seems that we are moving towards bullet representations when they are possible.

Wouldn't be better something like this?

qr = QuantumRegister(2, "qr")
cr = ClassicalRegister(2, "cr")
circuit = QuantumCircuit(qr, cr)
circuit.h(qr[0]).c_if(cr[0], 1)
circuit.h(qr[1]).c_if(cr[1], 0)
circuit.draw('text', cregbundle=False)
       ┌───┐        
qr_0: ─┤ H ├────────
       └─╥─┘ ┌───┐ 
qr_1: ───╫───┤ H ├─
         ║   └─╥─┘ 
cr_0: ═══■═════╬═══
               ║
cr_1: ═════════o═══

(may understanding of your code is that this change would be easy to make. Please, ignore my comment otherwise)

Thanks for pointing this out. I have made this change in the latest commit. @javabster I have also made the change in the vertical_compression value in the test.

Copy link
Contributor

@javabster javabster left a comment

Choose a reason for hiding this comment

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

Thanks @TharrmashasthaPV, LGTM 🚀

@javabster javabster added the Changelog: New Feature Include in the "Added" section of the changelog label Jul 13, 2021
Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

Great job!

@mergify mergify bot merged commit b50a41c into Qiskit:main Jul 14, 2021
@kdk kdk added this to the 0.19 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants