Add pretty printing for statevectors and density matrices#523
Add pretty printing for statevectors and density matrices#523simsaidan wants to merge 4 commits into
Conversation
First, implements function that pretty prints a complex number. Then, adds to statevecotr and density matrix. The density matrix is printed in matrix form.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #523 +/- ##
==========================================
+ Coverage 88.85% 88.94% +0.08%
==========================================
Files 49 49
Lines 7135 7288 +153
==========================================
+ Hits 6340 6482 +142
- Misses 795 806 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
thierry-martinez
left a comment
There was a problem hiding this comment.
Thank you very much for your contribution!
Codecov has detected that some parts of your code are not tested.
As you may have noticed, PR #503 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 addresses the issue.
| def _exp_i_to_str(angle_str: str, output: OutputFormat) -> str: | ||
| match output: | ||
| case OutputFormat.LaTeX: | ||
| return rf"e^{{i{angle_str}}}" |
There was a problem hiding this comment.
The issue description indicates that e and i should be typeset with \mathrm.
| (-1, OutputFormat.Unicode, "-1"), | ||
| (1j, OutputFormat.Unicode, "i"), | ||
| (-1j, OutputFormat.Unicode, "-i"), | ||
| (0.25 + 0.25j, OutputFormat.ASCII, "1/4 + 1/4 i"), |
There was a problem hiding this comment.
Shouldn't we write: « sqrt(2)/4e^(ipi/4)} »?
It would look better without a space between the coefficient and the imaginary unit.
|
Hey @thierry-martinez ! Thank you for the feedback. I added in \mathrm for e and i. For imaginary numbers, I now format them as 2i or .43i (without the space for integer or decimal factors), or 3i/4 for fractional. Would that work? I also added tests to improve coverage. |
|
Hi @simsaidan — looking through this per @thierry-martinez's nudge. Some observations: Nice to see the docs additions in Two technical notes:
|
First, implements function that pretty prints a complex number. Then, adds to statevecotr and density matrix. The density matrix is printed in matrix form.
Resolves #501 as part of UnitaryHack.
Before submitting, please check the following:
nox)ruffCONTRIBUTING.mdfor more detailsThen, please fill in below:
Context (if applicable):
Description of the change:
Related issue: