Skip to content

Commit

Permalink
Update tests, version bump (#53)
Browse files Browse the repository at this point in the history
* update tests, version bump

* suggested changes
  • Loading branch information
josh146 authored Oct 18, 2019
1 parent e7a0d48 commit 644c5b3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
14 changes: 6 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Release 0.6.0-dev
# Release 0.6.0

### New features since last release

### Breaking changes

### Improvements

### Documentation

### Bug fixes
* All Qiskit devices now support tensor observables using the
`return expval(qml.PauliZ(0) @ qml.Hermitian(A, [1, 2]))`
syntax introduced in PennyLane v0.6.

### Contributors

This release contains contributions from (in alphabetical order):

Josh Izaac

---

# Release 0.5.1
Expand Down
2 changes: 1 addition & 1 deletion pennylane_qiskit/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.6.0-dev"
__version__ = "0.6.0"
4 changes: 2 additions & 2 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class QiskitDevice(Device, abc.ABC):
Default value is ``True``.
"""
name = "Qiskit PennyLane plugin"
pennylane_requires = ">=0.5.0"
version = "0.5.0"
pennylane_requires = ">=0.6.0"
version = "0.6.0"
plugin_version = __version__
author = "Xanadu"

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
qiskit>=0.12
PennyLane>=0.5.0
PennyLane>=0.6.0
numpy
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

requirements = [
"qiskit>=0.12",
"pennylane>=0.5.0",
"pennylane>=0.6.0",
"numpy"
]

Expand Down
4 changes: 0 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import namedtuple
import pytest
import numpy as np

Expand Down Expand Up @@ -54,6 +53,3 @@ def _device(n):
return request.param(wires=n, backend=backend, shots=shots, analytic=analytic)

return _device


Tensor = namedtuple("Tensor", ["name", "wires", "parameters", "return_type"])
16 changes: 9 additions & 7 deletions tests/test_expval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pennylane as qml

from conftest import U, U2, A, Tensor
from conftest import U, U2, A


np.random.seed(42)
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_paulix_pauliy(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliX", "PauliY"], [[0], [2]], [[], []], qml.operation.Expectation)
qml.PauliX(0, do_queue=False) @ qml.PauliY(2, do_queue=False)
]
dev.pre_measure()

Expand All @@ -200,7 +200,7 @@ def test_pauliz_identity(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliZ", "Identity", "PauliZ"], [[0], [1], [2]], [[], [], []], qml.operation.Expectation)
qml.PauliZ(0, do_queue=False) @ qml.Identity(1, do_queue=False) @ qml.PauliZ(2, do_queue=False)
]

dev.post_apply()
Expand All @@ -221,7 +221,7 @@ def test_pauliz_hadamard(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliZ", "Hadamard", "PauliY"], [[0], [1], [2]], [[], [], []], qml.operation.Expectation)
qml.PauliZ(0, do_queue=False) @ qml.Hadamard(1, do_queue=False) @ qml.PauliY(2, do_queue=False)
]
dev.pre_measure()

Expand All @@ -248,7 +248,9 @@ def test_hermitian(self, theta, phi, varphi, device, shots, tol):
]
)

dev._obs_queue = [Tensor(["PauliZ", "Hermitian"], [[0], [1, 2]], [[], [A]], qml.operation.Expectation)]
dev._obs_queue = [
qml.PauliZ(0, do_queue=False) @ qml.Hermitian(A, [1, 2], do_queue=False)
]
dev.pre_measure()

res = dev.expval(["PauliZ", "Hermitian"], [[0], [1, 2]], [[], [A]])
Expand Down Expand Up @@ -283,7 +285,7 @@ def test_hermitian_hermitian(self, theta, phi, varphi, device, shots, tol):
)

dev._obs_queue = [
Tensor(["Hermitian", "Hermitian"], [[0], [1, 2]], [[A1], [A2]], qml.operation.Expectation)
qml.Hermitian(A1, 0, do_queue=False) @ qml.Hermitian(A2, [1, 2], do_queue=False)
]
dev.pre_measure()

Expand Down Expand Up @@ -313,7 +315,7 @@ def test_hermitian_identity_expectation(self, theta, phi, varphi, device, shots,
dev.apply("RY", wires=[1], par=[phi])
dev.apply("CNOT", wires=[0, 1], par=[])

dev._obs_queue = [Tensor(["Hermitian", "Identity"], [[0], [1]], [[A], []], qml.operation.Expectation)]
dev._obs_queue = [qml.Hermitian(A, 0, do_queue=False) @ qml.Identity(1, do_queue=False)]
dev.pre_measure()

res = dev.expval(["Hermitian", "Identity"], [[0], [1]], [[A], []])
Expand Down
28 changes: 15 additions & 13 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pennylane_qiskit import AerDevice, BasicAerDevice

from conftest import U, U2, A, Tensor
from conftest import U, U2, A


np.random.seed(42)
Expand Down Expand Up @@ -134,13 +134,13 @@ def test_paulix_pauliy(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliX", "PauliY"], [[0], [2]], [[], []], qml.operation.Sample)
qml.PauliX(0, do_queue=False) @ qml.PauliY(2, do_queue=False)
]

# for idx in range(len(dev._obs_queue)):
# dev._obs_queue[idx].return_type = qml.operation.Sample
for idx in range(len(dev._obs_queue)):
dev._obs_queue[idx].return_type = qml.operation.Sample

res = dev.pre_measure()
dev.pre_measure()

s1 = dev.sample(["PauliX", "PauliY"], [[0], [2]], [[], [], []])

Expand Down Expand Up @@ -172,13 +172,13 @@ def test_pauliz_hadamard(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliZ", "Hadamard", "PauliY"], [[0], [1], [2]], [[], [], []], qml.operation.Sample)
qml.PauliZ(0, do_queue=False) @ qml.Hadamard(1, do_queue=False) @ qml.PauliY(2, do_queue=False)
]

# for idx in range(len(dev._obs_queue)):
# dev._obs_queue[idx].return_type = qml.operation.Sample
for idx in range(len(dev._obs_queue)):
dev._obs_queue[idx].return_type = qml.operation.Sample

res = dev.pre_measure()
dev.pre_measure()

s1 = dev.sample(["PauliZ", "Hadamard", "PauliY"], [[0], [1], [2]], [[], [], []])

Expand Down Expand Up @@ -216,12 +216,14 @@ def test_hermitian(self, theta, phi, varphi, device, shots, tol):
]
)

dev._obs_queue = [Tensor(["PauliZ", "Hermitian"], [[0], [1, 2]], [[], [A]], qml.operation.Sample)]
dev._obs_queue = [
qml.PauliZ(0, do_queue=False) @ qml.Hermitian(A, [1, 2], do_queue=False)
]

# for idx in range(len(dev._obs_queue)):
# dev._obs_queue[idx].return_type = qml.operation.Sample
for idx in range(len(dev._obs_queue)):
dev._obs_queue[idx].return_type = qml.operation.Sample

res = dev.pre_measure()
dev.pre_measure()

s1 = dev.sample(["PauliZ", "Hermitian"], [[0], [1, 2]], [[], [A]])

Expand Down
9 changes: 4 additions & 5 deletions tests/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pennylane_qiskit import AerDevice, BasicAerDevice

from conftest import U, U2, A, Tensor
from conftest import U, U2, A


np.random.seed(42)
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_paulix_pauliy(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliX", "PauliY"], [[0], [2]], [[], []], qml.operation.Variance)
qml.PauliX(0, do_queue=False) @ qml.PauliY(2, do_queue=False)
]
dev.pre_measure()

Expand All @@ -103,7 +103,7 @@ def test_pauliz_hadamard(self, theta, phi, varphi, device, shots, tol):
dev.apply("CNOT", wires=[1, 2], par=[])

dev._obs_queue = [
Tensor(["PauliZ", "Hadamard", "PauliY"], [[0], [1], [2]], [[], [], []], qml.operation.Variance)
qml.PauliZ(0, do_queue=False) @ qml.Hadamard(1, do_queue=False) @ qml.PauliY(2, do_queue=False)
]
dev.pre_measure()

Expand Down Expand Up @@ -136,9 +136,8 @@ def test_hermitian(self, theta, phi, varphi, device, shots, tol):
]
)

dev._obs_queue = [Tensor(["PauliZ", "Hermitian"], [[0], [1, 2]], [[], [A]], qml.operation.Variance)]
dev._obs_queue = [qml.PauliZ(0, do_queue=False) @ qml.Hermitian(A, [1, 2], do_queue=False)]
dev.pre_measure()

res = dev.var(["PauliZ", "Hermitian"], [[0], [1, 2]], [[], [A]])

expected = (
Expand Down

0 comments on commit 644c5b3

Please sign in to comment.