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

[unitaryHACK] Add reset error to noise channels #1321

Merged
merged 25 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
123ddda
add ResetError channel
nahumsa May 15, 2021
87c419d
updated test parameters
nahumsa May 15, 2021
88e9375
updated docs
nahumsa May 15, 2021
3ccbbac
add entry to changelog
nahumsa May 15, 2021
bb468e8
Merge branch 'master' into add-reset-error
josh146 May 17, 2021
44ae9cd
run black
nahumsa May 17, 2021
891e3c8
Merge branch 'add-reset-error' of https://github.com/nahumsa/pennylan…
nahumsa May 17, 2021
53b6986
fix docs
nahumsa May 17, 2021
c0a1256
fix tests
nahumsa May 17, 2021
b1e01de
fix name of tests
nahumsa May 17, 2021
b1bc4f5
Merge branch 'master' into add-reset-error
josh146 May 17, 2021
85b7bb5
Update changelog
nahumsa May 17, 2021
c384377
add name to contributors
nahumsa May 17, 2021
f020b48
add grad recipe for `p_1`
nahumsa May 17, 2021
7e66d67
Merge branch 'master' into add-reset-error
antalszava May 17, 2021
31d91e1
change `grad_method` to "F"
nahumsa May 18, 2021
af53e0d
add `ResetError` when testing if it is trace preserving
nahumsa May 18, 2021
4ce0c52
remove analytic gradient test for `ResetError`
nahumsa May 18, 2021
2783fc5
Merge branch 'master' into add-reset-error
josh146 May 19, 2021
05c5f38
Merge branch 'master' into add-reset-error
josh146 May 19, 2021
61ed7d8
updated kraus operators
nahumsa May 19, 2021
2623fd3
Merge branch 'add-reset-error' of https://github.com/nahumsa/pennylan…
nahumsa May 19, 2021
e8d16b1
fix channel names
nahumsa May 19, 2021
77ab397
fix test channel names
nahumsa May 19, 2021
b35a7be
Merge branch 'master' into add-reset-error
nahumsa May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* The `qml.Toffoli` operation now has a decomposition over elementary gates.
[(#1320)](https://github.com/PennyLaneAI/pennylane/pull/1320)

* Added a new noise channel, `qml.ResetError`.
[(#1321)](https://github.com/PennyLaneAI/pennylane/pull/1321).

* The `qml.SWAP` operation now has a decomposition over elementary gates. [(#1329)](https://github.com/PennyLaneAI/pennylane/pull/1329)

* Added functionality for constructing and manipulating the Pauli group
Expand Down
66 changes: 66 additions & 0 deletions pennylane/ops/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,71 @@ def _kraus_matrices(cls, *params):
return [K0, K1]


class ResetError(Channel):
r"""ResetError(p_0, p_1, wires)
Single-qubit Reset error channel.

This channel is modelled by the following Kraus matrices:

.. math::
K_0 = \sqrt{1-p_0-p_1} \begin{bmatrix}
1 & 0 \\
0 & 1
\end{bmatrix}

.. math::
K_1 = \sqrt{p_0}\begin{bmatrix}
1 & 0 \\
0 & 0
\end{bmatrix}

.. math::
K_2 = \sqrt{p_0}\begin{bmatrix}
Copy link
Contributor

Choose a reason for hiding this comment

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

@nahumsa Why did you change the definition of the channel?
Before approving, could you please point me to a reference where this channel is defined? I would like to make sure that the name "reset error" coincides with the standard usage. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @ixfoduap ! I was reading through the qiskit's docs and found a direct reference about the ResetError Kraus operators:
image

This was the main reason that I changed the definition of the channel, do you think that this is reasonable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect! Thanks for the clarification!

0 & 1 \\
0 & 0
\end{bmatrix}

.. math::
K_3 = \sqrt{p_1}\begin{bmatrix}
0 & 0 \\
1 & 0
\end{bmatrix}

.. math::
K_4 = \sqrt{p_1}\begin{bmatrix}
0 & 0 \\
0 & 1
\end{bmatrix}

where :math:`p_0 \in [0, 1]` is the probability of a reset to 0,
and :math:`p_1 \in [0, 1]` is the probability of a reset to 1 error.

**Details:**

* Number of wires: 1
* Number of parameters: 2

Args:
p_0 (float): The probability that a reset to 0 error occurs.
p_1 (float): The probability that a reset to 1 error occurs.
wires (Sequence[int] or int): the wire the channel acts on
"""
num_params = 2
num_wires = 1
par_domain = "R"
grad_method = "F"

@classmethod
def _kraus_matrices(cls, *params):
p_0, p_1 = params[0], params[1]
K0 = np.sqrt(1 - p_0 - p_1) * np.eye(2)
K1 = np.sqrt(p_0) * np.array([[1, 0], [0, 0]])
K2 = np.sqrt(p_0) * np.array([[0, 1], [0, 0]])
K3 = np.sqrt(p_1) * np.array([[0, 0], [1, 0]])
K4 = np.sqrt(p_1) * np.array([[0, 0], [0, 1]])
return [K0, K1, K2, K3, K4]


class PhaseFlip(Channel):
r"""PhaseFlip(p, wires)
Single-qubit bit flip (Pauli :math:`Z`) error channel.
Expand Down Expand Up @@ -371,6 +436,7 @@ def _kraus_matrices(cls, *params):
"DepolarizingChannel",
"BitFlip",
"PhaseFlip",
"ResetError",
"QubitChannel",
}

Expand Down
27 changes: 27 additions & 0 deletions tests/ops/test_channel_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
channel.BitFlip,
channel.PhaseFlip,
channel.DepolarizingChannel,
channel.ResetError,
]


Expand All @@ -44,6 +45,8 @@ def test_kraus_matrices_sum_identity(self, ops, p, tol):
"""Test channels are trace-preserving"""
if ops.__name__ == "GeneralizedAmplitudeDamping":
op = ops(p, p, wires=0)
elif ops.__name__ == "ResetError":
op = ops(p / 2, p / 3, wires=0)
else:
op = ops(p, wires=0)
K_list = op.kraus_matrices
Expand Down Expand Up @@ -213,6 +216,30 @@ def circuit(p):
assert np.allclose(gradient, -(4 / 3) * np.cos(angle))


class TestResetError:
"""Tests for the quantum channel ResetError"""

@pytest.mark.parametrize("p_0,p_1", list(zip([0.5, 0.1, 0.0, 0.0], [0, 0.1, 0.5, 0.0])))
def test_p0_p1_arbitrary(self, p_0, p_1, tol):
"""Test that various values of p_0 and p_1 give correct Kraus matrices"""
op = channel.ResetError

expected_K0 = np.sqrt(1 - p_0 - p_1) * np.eye(2)
assert np.allclose(op(p_0, p_1, wires=0).kraus_matrices[0], expected_K0, atol=tol, rtol=0)

expected_K1 = np.sqrt(p_0) * np.array([[1, 0], [0, 0]])
assert np.allclose(op(p_0, p_1, wires=0).kraus_matrices[1], expected_K1, atol=tol, rtol=0)

expected_K2 = np.sqrt(p_0) * np.array([[0, 1], [0, 0]])
assert np.allclose(op(p_0, p_1, wires=0).kraus_matrices[2], expected_K2, atol=tol, rtol=0)

expected_K3 = np.sqrt(p_1) * np.array([[0, 0], [1, 0]])
assert np.allclose(op(p_0, p_1, wires=0).kraus_matrices[3], expected_K3, atol=tol, rtol=0)

expected_K4 = np.sqrt(p_1) * np.array([[0, 0], [0, 1]])
assert np.allclose(op(p_0, p_1, wires=0).kraus_matrices[4], expected_K4, atol=tol, rtol=0)


class TestQubitChannel:
"""Tests for the quantum channel QubitChannel"""

Expand Down