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

Update and expand DAGDependency drawer #11103

Merged
merged 10 commits into from Nov 2, 2023

Conversation

enavarro51
Copy link
Contributor

@enavarro51 enavarro51 commented Oct 24, 2023

Summary

Fixes #9066

Details and comments

This PR updates the DAGDependency section of the qiskit/visualization/dag_drawer.py.

  • The node.qargs and node.cargs have been added to each node display to indicate which qubits and clbits the instruction acts on.
  • If an instruction has a condition, it will be displayed
  • The colors have been changed to more closely match those of the DAGCircuit drawings.

This circuit

bits = [Qubit(), Clbit()]
qr = QuantumRegister(4, 'qr')
cr = ClassicalRegister(4, 'cr')
qc = QuantumCircuit(qr, bits, cr)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.cx(0, 3)
qc.x(3).c_if(cr[1], 1)
qc.h(3)
qc.x(4)
qc.barrier(0, 1)
qc.measure(0, 0)
print(qc)
dag = circuit_to_dagdependency(qc)
dag.draw()

produces this circuit drawing

      ┌───┐                 ░       ┌─┐
qr_0: ┤ H ├──■────■────■────░───────┤M├
      └───┘┌─┴─┐  │    │    ░       └╥┘
qr_1: ─────┤ X ├──┼────┼────░────────╫─
           └───┘┌─┴─┐  │    ░        ║ 
qr_2: ──────────┤ X ├──┼─────────────╫─
                └───┘┌─┴─┐┌───┐┌───┐ ║ 
qr_3: ───────────────┤ X ├┤ X ├┤ H ├─╫─
      ┌───┐          └───┘└─╥─┘└───┘ ║ 
   4: ┤ X ├─────────────────╫────────╫─
      └───┘                 ║        ║ 
   0: ══════════════════════■════════╩═
                                       
cr: 4/═════════════════════════════════
                                       

and this graph drawing
image

@enavarro51 enavarro51 requested review from nonhermitian and a team as code owners October 24, 2023 20:20
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

@coveralls
Copy link

coveralls commented Oct 24, 2023

Pull Request Test Coverage Report for Build 6635363212

  • 1 of 24 (4.17%) changed or added relevant lines in 1 file are covered.
  • 25 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.04%) to 86.88%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/dag_visualization.py 1 24 4.17%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
qiskit/visualization/dag_visualization.py 1 9.57%
crates/qasm2/src/lex.rs 5 90.4%
crates/qasm2/src/parse.rs 18 96.67%
Totals Coverage Status
Change from base Build 6631999916: -0.04%
Covered Lines: 73952
Relevant Lines: 85120

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

In general, this looks a completely clear win in usability to me. I haven't used DAGDependency much though, so it'd be good to get a second opinion. @alexanderivrii, does the new output format look good to you here?

Can we have a "feature" release note for this improvement to the drawers as well?

Copy link
Member

Choose a reason for hiding this comment

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

This one isn't a DAGDependency, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I was going to use a 1% diff on the image tests, but this one was at 6%, so I thought I'd update the reference image. Turns out after doing this it was still at 6% and the DAGDependency image was at 8% on the CI run. So I don't know what the difference is between the fonts, image libraries, etc. between my local and CI. I have the recommended version of graphviz. So we could just leave the old one.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, the new one looks more like it's intended and it passes CI, so I'm fine leaving it.

@enavarro51
Copy link
Contributor Author

I'll add a reno.

@enavarro51
Copy link
Contributor Author

Reno added in 53381b3.

@alexanderivrii
Copy link
Contributor

Thanks @enavarro51, I really like the new output. The code changes look good as well.

@alexanderivrii alexanderivrii added this pull request to the merge queue Nov 2, 2023
Merged via the queue into Qiskit:main with commit e7b1f5e Nov 2, 2023
14 checks passed
@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: visualization qiskit.visualization labels Nov 2, 2023
@jakelishman jakelishman added this to the 1.0.0pre1 milestone Nov 2, 2023
Matrixmang0 pushed a commit to Matrixmang0/qiskit that referenced this pull request Nov 3, 2023
* Update and expand dag dependency drawer

* Increase tolerance

* Add conditions and truncate long lists

* Lint

* Cyclic import

* Lint

* Reno
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 mod: visualization qiskit.visualization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better DAGDependency visualization
5 participants