Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.28k stars 2.37k forks source link

Allow for changing colors in dag circuit drawer #13106

Open nonhermitian opened 2 months ago

nonhermitian commented 2 months ago

What should we add?

It would be nice if we can change colors for the DAG drawer in a similar manner to the circuit drawer

Shivansh20128 commented 1 month ago

Hi @nonhermitian! I want to know more about this feature, and then maybe I can work on this. I did some reading about both functions. The circuit_drawer function uses the "output" parameter and the "backgroundcolor" to add some colors to the graph.

The following code shows the usage of output parameter.

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
circuit_drawer(qc, output="mpl")

image

The following code shows the usage of style parameter with backgroundcolor specified (it gives a blue color for background).


from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
circuit_drawer(qc, output="mpl", style={"backgroundcolor":"#0000FF"})

image

If we talk about the DAG circuit drawer now, which uses the function _dagdrawer, it does not have the output parameter, and relies only on the style parameter. The style parameter can take two values, plain and color.


from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.visualization import dag_drawer

q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circ = QuantumCircuit(q, c)
circ.h(q[0])
circ.cx(q[0], q[1])
circ.measure(q[0], c[0])
circ.rz(0.5, q[1]).c_if(c, 2)

dag = circuit_to_dag(circ)
dag_drawer(dag, style="color")

image

Now, you have mentioned that we should be able to change colors in the DAG drawer like the way we can do it in the circuit drawer function. So, are you talking about changing the background color? Thank You

emilkovacev commented 1 month ago

I am interested in working on this, can I be assigned to this issue?

Shivansh20128 commented 1 month ago

🙄😅 I had already started looking into this, and have asked a question here too. So I request you to let me work with you on this. Thank you