PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.34k stars 598 forks source link

Provide an informative string representation for ParametrizedHamiltonian #4088

Closed trbromley closed 1 year ago

trbromley commented 1 year ago

Feature details

PennyLane recently introduced the ParametrizedHamiltonian class. It allows users to define time-dependent parametrized Hamiltonians such as:

import pennylane as qml

def f1(p, t):
    return p[0] * jnp.sin(p[1] * t)

def f2(p, t):
    return p * t

coeffs = [2., f1, f2]
observables =  [qml.PauliX(0), qml.PauliY(0), qml.PauliZ(0)]
H = qml.dot(coeffs, observables)

The H can be evaluated for specific parameters and time:

p1 = jnp.array([1., 1.])
p2 = 1.
params = [p1, p2]
H(params, t=0.4)

What if we want to inspect H directly? Users currently get the following:

>>> H
ParametrizedHamiltonian: terms=3

This is not informative. Instead, we would like the representation of H to provide useful information to the user.

Implementation

The string representation of H in the example above can look like the following:

>>> H
(2.0*(PauliX(wires=[0]))) + ((f0(params_0, t)*(PauliY(wires=[0]))) + (f1(params_1, t)*(PauliZ(wires=[0]))))

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

Gopal-Dahale commented 1 year ago

Hi @trbromley, I think this feature is nice to have and a quick implementation can close this issue. Can you assign it to me?

anushkrishnav commented 1 year ago

Hey, can you assign this issue? I have submitted a pull request for review.

trbromley commented 1 year ago

Hi @Gopal-Dahale and @anushkrishnav, welcome!

@anushkrishnav, thanks for opening a pull request! A member of the PennyLane development team will take a look and give feedback :ok_hand:

Feel free to post here if you have any questions, or check out our development guide!

anushkrishnav commented 1 year ago

Can you assign the issue for the Unitary hack bot?

trbromley commented 1 year ago

Thanks @anushkrishnav for taking this on, and congrats on earning the bounty! :tada:

anushkrishnav commented 1 year ago

Thanks @anushkrishnav for taking this on, and congrats on earning the bounty! tada

Thank you so much !

trbromley commented 1 year ago

Hi @anushkrishnav! As part of our 0.31 release, we're planning to promote UnitaryHack contributions to PennyLane on social media.

This is completely optional, but would you like to be mentioned in our social media posts? Specifically, we'd need either your Twitter profile, your LinkedIn profile, or your name.

anushkrishnav commented 1 year ago

Hi @anushkrishnav! As part of our 0.31 release, we're planning to promote UnitaryHack contributions to PennyLane on social media.

This is completely optional, but would you like to be mentioned in our social media posts? Specifically, we'd need either your Twitter profile, your LinkedIn profile, or your name. Sorry I had to deal with an emergency for the past week , just came back. That would be great, if it's not too late ! You can use all the 3 if you wish to Name: Anush Krishna Twitter: https://twitter.com/Anush_krishna_v Linkedln : https://www.linkedin.com/in/anush-krishna-v-8270941a0/