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

Change style of DAG generated in dag_drawer() #13253

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

emilkovacev
Copy link
Contributor

@emilkovacev emilkovacev commented Oct 1, 2024

Summary

Closes #13106

Adds non-breaking interface to dag_drawer() to allow Qiskit users to customize the colors of DAGs.

Details and comments

I created stylesheets for dag_drawer(), that works similarly to how circuit_drawer does.

Here is an example:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
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)

style = {
    # "fontsize": 12,
    # "bgcolor": "white",
    # "dpi": 10,
    # "pad": 0,
    # "nodecolor": "green",
    "inputnodecolor": "pink",
    # "inputnodefontcolor": "white",
    "outputnodecolor": "lightblue",
    # "outputnodefontcolor": "white",
    "opnodecolor": "red",
    # "opnodefontcolor": "white",
    # "edgecolor": "black",
    # "qubitedgecolor": "red",
    # "clbitedgecolor": "black",
}

dag_drawer(dag, style=style)

The code above generates this DAG:

Screenshot 2024-10-09 at 11 39 46 AM

@emilkovacev emilkovacev requested review from nonhermitian and a team as code owners October 1, 2024 21:25
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Oct 1, 2024
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

@coveralls
Copy link

coveralls commented Oct 1, 2024

Pull Request Test Coverage Report for Build 11308588283

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 18 of 167 (10.78%) changed or added relevant lines in 2 files are covered.
  • 1133 unchanged lines in 38 files lost coverage.
  • Overall coverage decreased (-0.3%) to 88.564%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/dag/dagstyle.py 16 63 25.4%
qiskit/visualization/dag_visualization.py 2 104 1.92%
Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/optimization/elide_permutations.py 1 95.65%
qiskit/circuit/library/quantum_volume.py 1 97.3%
crates/accelerate/src/error_map.rs 1 85.42%
crates/accelerate/src/barrier_before_final_measurement.rs 2 97.33%
crates/circuit/src/lib.rs 2 96.15%
crates/circuit/src/bit_data.rs 2 94.62%
crates/accelerate/src/split_2q_unitaries.rs 2 96.0%
crates/accelerate/src/commutation_checker.rs 2 97.14%
crates/accelerate/src/check_map.rs 2 96.88%
qiskit/circuit/library/blueprintcircuit.py 4 96.4%
Totals Coverage Status
Change from base Build 11126578403: -0.3%
Covered Lines: 73200
Relevant Lines: 82652

💛 - Coveralls

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started. I left an inline comment about the high level interface. I'm a bit concerned with how low level the current interface is and that it would require understanding how graphviz is used internally by dag_drawer

qiskit/visualization/dag_visualization.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Allow for changing colors in dag circuit drawer
4 participants