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.35k stars 602 forks source link

Extend Partial trace function support for PennyLane operators #5338

Open babcockt18 opened 8 months ago

babcockt18 commented 8 months ago

Feature details

As the title suggests, this feature would extend qml.math.partial_trace functionality to handle PennyLane operators. The public facing function already exists. This issue is part of an optional enhancement that was proposed by @Qottmann but was closed before the latter portion of the issue was implemented.

Implementation

>>> qml.math.partial_trace(op, wires=[1])
X(0) + Y(0)
>>> qml.math.partial_trace(op, wires=[0])
X(1) + Y(1)

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

trbromley commented 8 months ago

Thanks @babcockt18! Yes this sounds like a nice idea and should be achievable for sums/products of the standard observables like X, Y, Z, etc. We could initially restrict to operators that are Pauli sentences (linear combinations of tensor products of Paulis) to make things easier.

Also, this partial_trace doesn't need to be the same one as in the math module. We could place it in op_math and also consider importing at top level.

Is this something you'd be interested to take on?

babcockt18 commented 8 months ago

@trbromley Awesome! definitely want to take this on! Thanks for asking! if you could assign it to me that would be great!

trbromley commented 7 months ago

Sorry @babcockt18, I lost track of replying to this. Would you still be interested on working on this feature?

babcockt18 commented 7 months ago

@trbromley All good! Still interested!

Alex-Preciado commented 7 months ago

Great! @babcockt18, please don't hesitate to reach out if you have any questions. We'll be happy to assist with the code review once a pull request is ready.