Closed trbromley closed 1 year ago
Hi! I'd like to work on this as part of the UnitaryHack Hackathon. Should I ask for this issue to be assigned to me, or should I directly fork the repository and issue a PR ASAP? Thanks!
Hi @tnemoz, welcome! You can go ahead and open a PR and we'll provide feedback once the PR is open. Once a PR is merged, the author is assigned to this issue, which let's the UnitaryHack team know that a bounty has been earned.
You can check out our development guide or just post here if you have any questions. Good luck!
Would it make sense to allow the user to indicate that both states are pure, if they're given as density matrices? Something along the lines of:
def trace_distance(rho, sigma, check_state=False, c_dtype='complex128', both_pure=False):
# Check states
...
if rho.shape == (rho.shape[0], ) and sigma.shape == (sigma.shape[0], ):
# Compute for pure states as statevectors
...
return res
elif both_pure:
return ...
trace_distance = ...
return trace_distance
The rationale behind this is that computing the trace distance for Statevectors is way faster, and for pure states given as density matrices, it's still faster than the general case. This could thus save non-negligible computation resources. What do you think about it? WOuld that make sense?
Hi @tnemoz, we actually want to move away from having the qml.math
functions accept both a state vector and a density matrix. This is due to complications in the dispatch logic when we consider a batch dimension. A rework of this is currently in progress.
For this issue, it suffices to provide an implementation of qml.math.trace_distance
that accepts only density matrices, contrary to what @trbromley wrote in the original issue. If the demand comes later (and if it's convenient), it might be possible to implement another more efficient function, e.g. qml.math.trace_distance_pure
, that accepts only state vectors. This is not needed here.
Hi @tnemoz, we actually want to move away from having the
qml.math
functions accept both a state vector and a density matrix. This is due to complications in the dispatch logic when we consider a batch dimension. A rework of this is currently in progress.For this issue, it suffices to provide an implementation of
qml.math.trace_distance
that accepts only density matrices, contrary to what @trbromley wrote in the original issue. If the demand comes later (and if it's convenient), it might be possible to implement another more efficient function, e.g.qml.math.trace_distance_pure
, that accepts only state vectors. This is not needed here.
So if I understand correctly, the function will be given either:
(2**N, 2**N)
each), in which case it returns the trace distance between thesebatch_dim
, in which case both inputs should have shape (batch_dim, 2**N, 2**N)
, in which case the function will return a (batch_dim,)
array containing the trace distances between each pair(2**N, 2**N)
and one batch of density matrices of the same size, in which case the function returns a (batch_dim,)
array containing the tarce distance between each density matrix of the batch and the other oneIs that correct? I mostly infered these from the new _check_density_matrix
function, but I could be wrong about the way the function will be used
Yep, everything you say is correct.
Thanks @tnemoz, congrats on winning the bounty!! :100: :tada:
Thank you very much!
Hi @tnemoz!
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.
Feature details
The trace distance is one measure of distance between two quantum states
rho
andsigma
. This is a commonly-calculated quantity in quantum information science and will be useful to add to PennyLane. Specifically, we'd like to implement:rho
andsigma
, represented as a numeric array either as a pure or mixed state, a user can calculate and differentiate the trace distance between the two states.Implementation
QNode-level interface:
qml.math
-level interface:rho
can be pure or mixedsigma
can be pure or mixedcheck_state
checks if each state is valid (assumeFalse
)c_dtype
is the complex floating point precisionHow important would you say this feature is?
1: Not important. Would be nice to have.
Additional information
Check out the relative entropy functionality in PennyLane for an example of how this can be done.