Skip to content

Support pretty-printing of basis expansion for states#2620

Merged
Ericgig merged 8 commits into
qutip:masterfrom
Sola85:master
Feb 5, 2025
Merged

Support pretty-printing of basis expansion for states#2620
Ericgig merged 8 commits into
qutip:masterfrom
Sola85:master

Conversation

@Sola85

@Sola85 Sola85 commented Jan 31, 2025

Copy link
Copy Markdown
Contributor

Description
Added Qobj.print_basis_expansion() which returns string representations for states of the form "(0.24+0.3j) |0010> + ...", i.e. essentially the inverse of qutip.ket()/qutip.bra().
This works for any dimensions, i.e. qutip.basis([5, 5, 5], [4, 0, 2]).print_basis_expansion() would return "(1+0j) |4, 0, 2>".

I'd be happy for suggestions for a better name for this function, since it doesn't actually print anything to console, but I found this name less unwieldy than e.g. .basis_expansion_string() and clearer than just .basis_expansion().

Related issues or PRs
Fixes #2618

@coveralls

coveralls commented Jan 31, 2025

Copy link
Copy Markdown

Coverage Status

coverage: 87.739% (+0.01%) from 87.729%
when pulling 48435ee on Sola85:master
into eb3e5c4 on qutip:master.

@Sola85 Sola85 marked this pull request as ready for review January 31, 2025 16:41

@Ericgig Ericgig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Look good, thank you.
Very clean representation of states.
I would go with basis_expansion.

@Sola85

Sola85 commented Feb 3, 2025

Copy link
Copy Markdown
Contributor Author

I would go with basis_expansion.

Done!

@Ericgig Ericgig merged commit ee2bc3d into qutip:master Feb 5, 2025
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.

Pretty-printing of basis expansion for states

3 participants