Skip to content

Add pretty printers for Statevec and DensityMatrix#503

Open
donglrd wants to merge 1 commit into
TeamGraphix:masterfrom
donglrd:pretty-print-statevec-density
Open

Add pretty printers for Statevec and DensityMatrix#503
donglrd wants to merge 1 commit into
TeamGraphix:masterfrom
donglrd:pretty-print-statevec-density

Conversation

@donglrd
Copy link
Copy Markdown

@donglrd donglrd commented May 12, 2026

Summary\n- add complex-number pretty formatting for fractions, square-root constants, and phase exponentials\n- add statevector ket expansion rendering via Statevec.draw()\n- add density-matrix outer-product rendering via DensityMatrix.draw()\n- cover the new formatting helpers and draw methods with tests\n\nCloses #501\n\n## Testing\n- pytest tests/test_pretty_print.py -q\n- python3 -m ruff check graphix/pretty_print.py graphix/sim/statevec.py graphix/sim/density_matrix.py tests/test_pretty_print.py

@thierry-martinez
Copy link
Copy Markdown
Collaborator

Thank you for your contribution! As noted in the preamble of #501, this issue is part of unitaryHACK 2026; therefore, contributions will be evaluated during the hackathon period, from June 3 to June 17, 2026.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 75.43860% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.74%. Comparing base (4715099) to head (607fb23).
⚠️ Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
graphix/pretty_print.py 74.07% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #503      +/-   ##
==========================================
- Coverage   89.97%   89.74%   -0.24%     
==========================================
  Files          48       48              
  Lines        7015     7129     +114     
==========================================
+ Hits         6312     6398      +86     
- Misses        703      731      +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@thierry-martinez thierry-martinez left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution!

Could you please fix the issue that mypy has detected?

In addition, Codecov reports that some parts of your code are not covered by tests.

As you may have noticed, PR #523 and PR #524 address the same issue (#501). We invite you to cross‑review each other's work: PR reviews are an inherent part of software development, just as important as writing code. Moreover, this review process will help you position your PR relative to the others, allowing us to determine which contribution best resolves the issue.

Comment thread graphix/pretty_print.py
def _bra(label: str, output: OutputFormat) -> str:
if output == OutputFormat.LaTeX:
return rf"\langle {label}\rvert"
if output == OutputFormat.Unicode:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using \bra{} would be more standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants