-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added density_matrix_qnode, negativity_cost_fn, and partial_transpose…
… functions with test cases updated functionality of partial transpose so it works with any input size
- Loading branch information
Showing
7 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pennylane as qml | ||
from pennylane import math | ||
import numpy as np | ||
from ..qnodes import density_matrix_qnode | ||
from ..utilities import partial_transpose | ||
|
||
|
||
def negativity_cost_fn(network_ansatz, m, n, wires, qnode_kwargs={}): | ||
"""Constructs an ansatz-specific negativity cost function. | ||
Negativity can be used to identify if two subsystems :math:`A` and :math:`B` are | ||
entangled, through the PPT criterion. Negativity is an upper bound for distillable entanglement. | ||
This entanglement measure is expressed as | ||
.. math:: | ||
\\mathcal{N}(\\rho) = |\\sum_{\\lambda_i < 0}\\lambda_i|, | ||
where :math:`\\rho^{\\Gamma_B}` is the partial transpose of the joint state with respect to | ||
the :math:`B` party, and :math:`\\lambda_i` are all of the eigenvalues of :math:`\\rho^{\\Gamma_B}`. | ||
For more information on negativity and its applications in quantum information theory, | ||
see [Vidal and Werner (2001)](https://arxiv.org/pdf/quant-ph/0102117). | ||
:param ansatz: The ansatz circuit on which the negativity is evaluated. | ||
:type ansatz: NetworkAnsatz | ||
:param m: The size of the :math:`A` subsystem. | ||
:type m: int | ||
:param n: The size of the :math:`B` subsystem. | ||
:type n: int | ||
:param wires: The wires which define the joint state. | ||
:type wires: list[int] | ||
:param qnode_kwargs: Keyword arguments passed to the execute qnodes. | ||
:type qnode_kwargs: dictionary | ||
:returns: A cost function ``negativity_cost(*network_settings)`` parameterized by | ||
the ansatz-specific scenario settings. | ||
:rtype: Function | ||
:raises ValueError: If the sum of the sizes of the two subsystems (``m + n``) does not match the length of ``wires``. | ||
""" | ||
|
||
if len(wires) != m + n: | ||
raise ValueError(f"Sum of sizes of two subsystems should be {len(wires)}; got {m+n}.") | ||
|
||
density_qnode = density_matrix_qnode(network_ansatz, wires, **qnode_kwargs) | ||
|
||
def negativity_cost(*network_settings): | ||
dm = density_qnode(network_settings) | ||
dm_pt = partial_transpose(dm, 2**m, 2**n) | ||
eigenvalues = math.eigvalsh(dm_pt) | ||
negativity = np.sum(np.abs(eigenvalues[eigenvalues < 0])) | ||
return -negativity | ||
|
||
return negativity_cost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import pytest | ||
from pennylane import numpy as np | ||
|
||
import qnetvo as qnet | ||
|
||
|
||
class TestNegativityCost: | ||
def test_negativity_cost_fn(self): | ||
|
||
prep_nodes = [ | ||
qnet.PrepareNode(1, [0, 1], qnet.bell_state_copies, 2), | ||
] | ||
|
||
ansatz = qnet.NetworkAnsatz(prep_nodes) | ||
|
||
negativity_cost = qnet.negativity_cost_fn(ansatz, m=1, n=1, wires=[0, 1]) | ||
|
||
zero_settings = ansatz.zero_network_settings() | ||
|
||
negativity_value = negativity_cost(*zero_settings) | ||
|
||
expected_negativity = -0.5 | ||
assert np.isclose( | ||
negativity_value, expected_negativity | ||
), f"Expected {expected_negativity}, but got {negativity_value}" | ||
|
||
separable_prep_nodes = [ | ||
qnet.PrepareNode(4, [0, 1], qnet.local_RY, 2), | ||
] | ||
|
||
separable_ansatz = qnet.NetworkAnsatz(separable_prep_nodes) | ||
|
||
separable_negativity_cost = qnet.negativity_cost_fn( | ||
separable_ansatz, m=1, n=1, wires=[0, 1] | ||
) | ||
|
||
separable_negativity_value = separable_negativity_cost(*zero_settings) | ||
|
||
expected_separable_negativity = 0 | ||
assert np.isclose( | ||
separable_negativity_value, expected_separable_negativity | ||
), f"Expected {expected_separable_negativity}, but got {separable_negativity_value}" | ||
|
||
with pytest.raises(ValueError, match="Sum of sizes of two subsystems should be"): | ||
qnet.negativity_cost_fn(ansatz, m=2, n=1, wires=[0, 1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters