Skip to content

Commit

Permalink
update dependencies and refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Oct 11, 2021
1 parent 42bc87f commit 6672a20
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion _metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__extension_version__ = "0.1.2"
__extension_version__ = "0.1.3"
__extension_name__ = "pytket-pennylane"
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
packages=find_namespace_packages(include=["pytket.*"]),
include_package_data=True,
install_requires=[
"pytket ~= 0.13.0",
"pennylane ~= 0.15.0",
"pytket-qiskit ~= 0.16.0",
"pytket ~= 0.15.0",
"pennylane ~= 0.18.0",
"pytket-qiskit ~= 0.18.0",
],
classifiers=[
"Environment :: Console",
Expand Down
8 changes: 4 additions & 4 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytket-qiskit~=0.16.0
pytket-cirq~=0.14.0
pytket-projectq~=0.12.0
pytket-qulacs~=0.10.0
pytket-qiskit~=0.18.0
pytket-cirq~=0.16.0
pytket-projectq~=0.14.0
pytket-qulacs~=0.12.0
2 changes: 1 addition & 1 deletion tests/run_pennylane_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

from pennylane.devices.tests import test_device

test_device("pytket.pytketdevice", pytest_args=["-x", "-s"])
test_device("pytket.pytketdevice", shots=None, pytest_args=["-x", "-s"])
44 changes: 24 additions & 20 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import platform
from typing import List
import numpy as np
import pytest
import pennylane as qml
from pytket.backends.backend import Backend
from pytket.extensions.qiskit import AerStateBackend, AerBackend
from pytket.extensions.cirq import CirqStateSampleBackend
from pytket.extensions.projectq import ProjectQBackend

from pytket.passes import RebaseHQS as test_pass
from pytket.passes import RebaseHQS as sample_pass
from pytket.backends.backend_exceptions import CircuitNotValidError


TEST_BACKENDS: List[Backend] = [
AerStateBackend(),
AerBackend(),
CirqStateSampleBackend(),
ProjectQBackend(),
]

if platform.system().lower() != "windows":
from pytket.extensions.qulacs import QulacsBackend

TEST_BACKENDS.append(QulacsBackend())


def my_quantum_function(x, y):
qml.RZ(x, wires=0)
Expand All @@ -36,34 +48,26 @@ def my_quantum_function(x, y):
return qml.expval(qml.PauliZ(1) @ qml.PauliX(0) @ qml.PauliY(2))


def test_backends():
test_backends = [
AerStateBackend(),
AerBackend(),
CirqStateSampleBackend(),
ProjectQBackend(),
]
if platform.system().lower() != "windows":
test_backends.append(QulacsBackend())
@pytest.mark.parametrize("test_backend", TEST_BACKENDS)
def test_backends(test_backend):

for back in test_backends:
print(back)
dev = qml.device(
"pytket.pytketdevice", wires=3, pytket_backend=back, shots=100000
)
dev = qml.device(
"pytket.pytketdevice", wires=3, pytket_backend=test_backend, shots=100000
)

assert str(dev.compilation_pass) == "<tket::SequencePass>"

assert str(dev.compilation_pass) == "<tket::SequencePass>"
test_func = qml.qnode(dev)(my_quantum_function)

test_func = qml.qnode(dev)(my_quantum_function)
assert np.isclose([test_func(0.6, 0.8)], [0.274], atol=0.01)

assert np.isclose([test_func(0.6, 0.8)], [0.274], atol=0.01)

# check invalid pass fails
def test_invalid_fail():
dev = qml.device(
"pytket.pytketdevice",
wires=3,
pytket_backend=AerStateBackend(),
compilation_pass=test_pass(),
compilation_pass=sample_pass(),
)
assert str(dev.compilation_pass) == "<tket::BasePass>"

Expand Down

0 comments on commit 6672a20

Please sign in to comment.