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
Adds default.qubit.autograd qubit simulator for use with the PassthruQNode #721
Merged
Merged
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
3634948
Adds default.qubit.autograd qubit simulator for use with the Passthru…
josh146 b1d7e29
update changelog
josh146 2e151a2
update changelog
josh146 caddf4e
fix docstring
josh146 14dc588
Apply suggestions from code review
josh146 e96bf75
suggested changes
josh146 d0878c4
Merge branch 'passthru-qubit' of github.com:XanaduAI/pennylane into p…
josh146 4debac4
suggested changes
josh146 a056726
fix tests
josh146 1a2a9e6
merge master
josh146 6c05260
add flaky
josh146 e97ab7e
redundancy
josh146 fbe5d5a
redundancy
josh146 b696e4c
update changelog:
josh146 f73bf70
increase coverage
josh146 73ada6e
increase coverage
josh146 456934c
remove print statement
josh146 1b5b0ba
upgrade
josh146 e1f33cb
Merge branch 'master' into passthru-qubit
josh146 b3e1dd5
Merge branch 'master' into passthru-qubit
josh146 71ad705
upgrade
josh146 f4ef519
Merge branch 'passthru-qubit' of github.com:PennyLaneAI/pennylane int…
josh146 5246446
upgrade
josh146 484b1ad
fix
josh146 f52dca4
Merge branch 'master' into passthru-qubit
josh146 f241256
fix
josh146 d353dbf
increase coverage
josh146 6f4f2ea
fix test
josh146 dc70cac
remove device tests
josh146 a2ff021
more
josh146 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,157 @@ | ||
# Copyright 2018-2020 Xanadu Quantum Technologies Inc. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
r""" | ||
Utility functions and numerical implementations of quantum operations for Autograd-based devices. | ||
""" | ||
from autograd import numpy as np | ||
from numpy import kron | ||
co9olguy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
C_DTYPE = np.complex128 | ||
R_DTYPE = np.float64 | ||
|
||
I = np.array([[1, 0], [0, 1]], dtype=C_DTYPE) | ||
X = np.array([[0, 1], [1, 0]], dtype=C_DTYPE) | ||
Y = np.array([[0j, -1j], [1j, 0j]], dtype=C_DTYPE) | ||
Z = np.array([[1, 0], [0, -1]], dtype=C_DTYPE) | ||
|
||
II = np.eye(4, dtype=C_DTYPE) | ||
ZZ = np.array(kron(Z, Z), dtype=C_DTYPE) | ||
|
||
IX = np.array(kron(I, X), dtype=C_DTYPE) | ||
IY = np.array(kron(I, Y), dtype=C_DTYPE) | ||
IZ = np.array(kron(I, Z), dtype=C_DTYPE) | ||
|
||
ZI = np.array(kron(Z, I), dtype=C_DTYPE) | ||
ZX = np.array(kron(Z, X), dtype=C_DTYPE) | ||
ZY = np.array(kron(Z, Y), dtype=C_DTYPE) | ||
|
||
|
||
def PhaseShift(phi): | ||
r"""One-qubit phase shift. | ||
|
||
Args: | ||
phi (float): phase shift angle | ||
|
||
Returns: | ||
array[complex]: diagonal part of the phase shift matrix | ||
""" | ||
return np.array([1.0, np.exp(1j * phi)]) | ||
|
||
|
||
def RX(theta): | ||
r"""One-qubit rotation about the x axis. | ||
|
||
Args: | ||
theta (float): rotation angle | ||
|
||
Returns: | ||
array[complex]: unitary 2x2 rotation matrix :math:`e^{-i \sigma_x \theta/2}` | ||
""" | ||
return np.cos(theta / 2) * I + 1j * np.sin(-theta / 2) * X | ||
|
||
|
||
def RY(theta): | ||
r"""One-qubit rotation about the y axis. | ||
|
||
Args: | ||
theta (float): rotation angle | ||
|
||
Returns: | ||
array[complex]: unitary 2x2 rotation matrix :math:`e^{-i \sigma_y \theta/2}` | ||
""" | ||
return np.cos(theta / 2) * I + 1j * np.sin(-theta / 2) * Y | ||
|
||
|
||
def RZ(theta): | ||
r"""One-qubit rotation about the z axis. | ||
|
||
Args: | ||
theta (float): rotation angle | ||
|
||
Returns: | ||
array[complex]: the diagonal part of the rotation matrix :math:`e^{-i \sigma_z \theta/2}` | ||
""" | ||
p = np.exp(-0.5j * theta) | ||
return np.array([p, np.conj(p)]) | ||
|
||
|
||
def Rot(a, b, c): | ||
r"""Arbitrary one-qubit rotation using three Euler angles. | ||
|
||
Args: | ||
a,b,c (float): rotation angles | ||
|
||
Returns: | ||
array[complex]: unitary 2x2 rotation matrix ``rz(c) @ ry(b) @ rz(a)`` | ||
""" | ||
return np.diag(RZ(c)) @ RY(b) @ np.diag(RZ(a)) | ||
|
||
|
||
def CRX(theta): | ||
r"""Two-qubit controlled rotation about the x axis. | ||
|
||
Args: | ||
theta (float): rotation angle | ||
|
||
Returns: | ||
array[complex]: unitary 4x4 rotation matrix | ||
:math:`|0\rangle\langle 0|\otimes \mathbb{I}+|1\rangle\langle 1|\otimes R_x(\theta)` | ||
""" | ||
return ( | ||
np.cos(theta / 4) ** 2 * II | ||
- 1j * np.sin(theta / 2) / 2 * IX | ||
+ np.sin(theta / 4) ** 2 * ZI | ||
+ 1j * np.sin(theta / 2) / 2 * ZX | ||
) | ||
|
||
|
||
def CRY(theta): | ||
r"""Two-qubit controlled rotation about the y axis. | ||
|
||
Args: | ||
theta (float): rotation angle | ||
Returns: | ||
array[complex]: unitary 4x4 rotation matrix :math:`|0\rangle\langle 0|\otimes \mathbb{I}+|1\rangle\langle 1|\otimes R_y(\theta)` | ||
""" | ||
return ( | ||
np.cos(theta / 4) ** 2 * II | ||
- 1j * np.sin(theta / 2) / 2 * IY | ||
+ np.sin(theta / 4) ** 2 * ZI | ||
+ 1j * np.sin(theta / 2) / 2 * ZY | ||
) | ||
|
||
|
||
def CRZ(theta): | ||
r"""Two-qubit controlled rotation about the z axis. | ||
|
||
Args: | ||
theta (float): rotation angle | ||
Returns: | ||
array[complex]: diagonal part of the 4x4 rotation matrix | ||
:math:`|0\rangle\langle 0|\otimes \mathbb{I}+|1\rangle\langle 1|\otimes R_z(\theta)` | ||
""" | ||
p = np.exp(-0.5j * theta) | ||
return np.array([1.0, 1.0, p, np.conj(p)]) | ||
|
||
|
||
def CRot(a, b, c): | ||
r"""Arbitrary two-qubit controlled rotation using three Euler angles. | ||
|
||
Args: | ||
a,b,c (float): rotation angles | ||
Returns: | ||
array[complex]: unitary 4x4 rotation matrix | ||
:math:`|0\rangle\langle 0|\otimes \mathbb{I}+|1\rangle\langle 1|\otimes R(a,b,c)` | ||
""" | ||
return np.diag(CRZ(c)) @ (CRY(b) @ np.diag(CRZ(a))) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
We should begin deleting all the repeated device integration tests, and just add lines to the makefile here