Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text drawer support for controlled/conditional custom instruction #3199

Open
1ucian0 opened this issue Oct 4, 2019 · 3 comments
Open

Text drawer support for controlled/conditional custom instruction #3199

1ucian0 opened this issue Oct 4, 2019 · 3 comments
Labels
type: enhancement It's working, but needs polishing

Comments

@1ucian0
Copy link
Member

1ucian0 commented Oct 4, 2019

Based on the consensus in #3073, the text drawer should support controlled/conditional custom instructions

Considering the following custom instruction:

        ┌─────────────┐            
q_0: |0>┤1            ├            
        │             │            
q_1: |0>┤             ├            
        │ instruction │            
 c_0: 0 ╡             ╞            
        │             │            
 c_1: 0 ╡0            ╞            
        └─────────────┘

It would be possible to control on q_1 and have a classical condition c == 2 and the result should look like this:

               ┌─────────────┐     
q_0: |0>───────┤1            ├     
               │             │     
q_1: |0>───────■             ├     
               │ instruction │     
 c_0: 0 ═┬─────┤             ╞     
         │ = 2 │             │     
 c_1: 0 ═┴─────┤0            ╞     
               └─────────────┘     
@1ucian0
Copy link
Member Author

1ucian0 commented Oct 4, 2019

Custom controlled instructions are not yet supported (waiting for #2862 ) On the conditional part, I think this is the code to test this situation (not fully sure, because I cannot visualize the result)

from qiskit.circuit import Gate, Parameter
qinst = QuantumRegister(1, 'q')
cinst = ClassicalRegister(1, 'c')

inst = QuantumCircuit(qinst, cinst, name='instruction').to_instruction()

qr = QuantumRegister(2, 'q')
cr = ClassicalRegister(2, 'c')
circuit = QuantumCircuit(qr, cr)
circuit.append(inst, [qr[0]], [cr[1]]).c_if(cr, 2)
circuit.draw(output='text')

@1ucian0
Copy link
Member Author

1ucian0 commented Oct 5, 2019

Also, it seems like text drawer also have problems with the following configuration:

qr1 = QuantumRegister(1, 'qr')
cr1 = ClassicalRegister(1, 'cr')
qr2 = QuantumRegister(2, 'qr')
cr2 = ClassicalRegister(2, 'cr')

inst = QuantumCircuit(qr1, cr1, name='name').to_instruction()
circuit = QuantumCircuit(qr2, cr2)
circuit.append(inst, [qr2[0]], [cr2[1]])
print(circuit)

@mrvee-qC
Copy link

mrvee-qC commented Dec 15, 2021

Update for Santa:elf:- QGoGP

✅ Issue still reproducible! Instruction object currently doesn't have an explicit custom control method and conditions with overlapping c_if and q_if drawings are not implemented yet as discussed and voted in Issue #3073. Second comment seems to be fixed but original drawer layout as mentioned by OP not yet implemented.

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit import Gate, Parameter
qinst = QuantumRegister(1, 'q')
cinst = ClassicalRegister(1, 'c')

inst = QuantumCircuit(qinst, cinst, name='instruction').to_instruction()

qr = QuantumRegister(2, 'q')
cr = ClassicalRegister(2, 'c')
circuit = QuantumCircuit(qr, cr)
circuit.append(inst, [qr[0]], [cr[1]]).c_if(cr, 2)
circuit.draw(output='text')

Current Output -

     ┌──────────────┐
q_0: ┤0             ├
     │              │
q_1: ┤              ├
     │  instruction │
c_0: ╡              ╞
     │              │
c_1: ╡0             ╞
     └──────────────┘

Expected -

               ┌─────────────┐     
q_0: |0>───────┤1            ├     
               │             │     
q_1: |0>───────■             ├     
               │ instruction │     
c_0: 0 ══┬─────┤             ╞     
         │ = 2 │             │     
c_1: 0 ══┴─────┤0            ╞     
               └─────────────┘     

Will update comment/add more comments if cause is found/fixed!

Python version 3.9.7
qiskit-terra version: 0.19.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Projects
None yet
Development

No branches or pull requests

2 participants