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

IPython displays a Hamiltonian's str representation instead of repr #2648

Merged
merged 4 commits into from
Jun 1, 2022

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Jun 1, 2022

Currently, IPython displays Hamiltonians via their repr representation:

>>> 1.0 * qml.PauliX(0)
<Hamiltonian: terms=1, wires=[0]>

This doesn't tell us much about what's actually in the Hamiltonian, so I find myself always having to use print(H) instead of simply H when playing around with Hamiltonians in the REPL.

This PR defines the _ipython_display method for Hamiltonians, so now it prints out the full str representation.

>>> 1.0 * qml.PauliX(0)
  (1.0) [X0]

@albi3ro albi3ro requested a review from Jaybsoni June 1, 2022 19:46
@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #2648 (cb85595) into master (e4d86eb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2648   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files         245      245           
  Lines       19724    19726    +2     
=======================================
+ Hits        19642    19644    +2     
  Misses         82       82           
Impacted Files Coverage Δ
pennylane/ops/qubit/hamiltonian.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4d86eb...cb85595. Read the comment docs.

Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Great 👍🏼

@albi3ro albi3ro merged commit 3fa7518 into master Jun 1, 2022
@albi3ro albi3ro deleted the hamiltonian_ipython branch June 1, 2022 20:51
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.

None yet

2 participants