Skip to content

Commit

Permalink
parametrize over lists
Browse files Browse the repository at this point in the history
  • Loading branch information
josh146 committed Sep 25, 2019
1 parent b0bd1a3 commit e7a0d48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PYTHON3 := $(shell which python3 2>/dev/null)

PYTHON := python3
COVERAGE := --cov=pennylane_qiskit --cov-report term-missing --cov-report=html:coverage_html_report
TESTRUNNER := -m pytest tests
TESTRUNNER := -m pytest tests --tb=short

.PHONY: help
help:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_expval.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

np.random.seed(42)

THETA = np.linspace(0.11, 2*np.pi-0.13, 3)
PHI = np.linspace(0.32, 2*np.pi-0.11, 3)
VARPHI = np.linspace(0.02, 2*np.pi-0.12, 3)
THETA = np.linspace(0.11, 1, 3)
PHI = np.linspace(0.32, 1, 3)
VARPHI = np.linspace(0.02, 1, 3)


@pytest.mark.parametrize("theta, phi", zip(THETA, PHI))
@pytest.mark.parametrize("theta, phi", list(zip(THETA, PHI)))
@pytest.mark.parametrize("analytic", [True, False])
@pytest.mark.parametrize("shots", [8192])
class TestExpval:
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_multi_mode_hermitian_expectation(self, theta, phi, device, shots, tol):
assert np.allclose(res, expected, **tol)


@pytest.mark.parametrize("theta, phi, varphi", zip(THETA, PHI, VARPHI))
@pytest.mark.parametrize("theta,phi,varphi", list(zip(THETA, PHI, VARPHI)))
@pytest.mark.parametrize("analytic", [True, False])
@pytest.mark.parametrize("shots", [8192])
class TestTensorExpval:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

np.random.seed(42)

THETA = np.linspace(0.11, 2*np.pi-0.13, 3)
PHI = np.linspace(0.32, 2*np.pi-0.11, 3)
VARPHI = np.linspace(0.02, 2*np.pi-0.12, 3)
THETA = np.linspace(0.11, 1, 3)
PHI = np.linspace(0.32, 1, 3)
VARPHI = np.linspace(0.02, 1, 3)


@pytest.mark.parametrize("analytic", [False])
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_sample_values_hermitian(self, theta, device, shots, tol):
# s1 should only contain the eigenvalues of
# the hermitian matrix
eigvals = np.linalg.eigvalsh(A)
assert np.allclose(sorted(list(set(s1))), sorted(eigvals), **tol)
assert set(np.round(s1, 8)).issubset(set(np.round(eigvals, 8)))

# the analytic mean is 2*sin(theta)+0.5*cos(theta)+0.5
assert np.allclose(np.mean(s1), 2 * np.sin(theta) + 0.5 * np.cos(theta) + 0.5, **tol)
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_sample_values_hermitian_multi_qubit(self, theta, device, shots, tol):
# s1 should only contain the eigenvalues of
# the hermitian matrix
eigvals = np.linalg.eigvalsh(A)
assert np.allclose(sorted(list(set(s1))), sorted(eigvals), **tol)
assert set(np.round(s1, 8)).issubset(set(np.round(eigvals, 8)))

# make sure the mean matches the analytic mean
expected = (
Expand All @@ -118,7 +118,7 @@ def test_sample_values_hermitian_multi_qubit(self, theta, device, shots, tol):
assert np.allclose(np.mean(s1), expected, **tol)


@pytest.mark.parametrize("theta, phi, varphi", zip(THETA, PHI, VARPHI))
@pytest.mark.parametrize("theta, phi, varphi", list(zip(THETA, PHI, VARPHI)))
@pytest.mark.parametrize("analytic", [False])
@pytest.mark.parametrize("shots", [8192])
class TestTensorSample:
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_hermitian(self, theta, phi, varphi, device, shots, tol):
# the hermitian matrix tensor product Z
Z = np.diag([1, -1])
eigvals = np.linalg.eigvalsh(np.kron(Z, A))
assert np.allclose(sorted(list(set(s1))), sorted(eigvals), **tol)
assert set(np.round(s1, 8)).issubset(set(np.round(eigvals, 8)))

mean = np.mean(s1)
expected = 0.5 * (
Expand Down
10 changes: 5 additions & 5 deletions tests/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

np.random.seed(42)

THETA = np.linspace(0.11, 2*np.pi-0.13, 3)
PHI = np.linspace(0.32, 2*np.pi-0.11, 3)
VARPHI = np.linspace(0.02, 2*np.pi-0.12, 3)
THETA = np.linspace(0.11, 1, 3)
PHI = np.linspace(0.32, 1, 3)
VARPHI = np.linspace(0.02, 1, 3)


@pytest.mark.parametrize("theta, phi", zip(THETA, PHI))
@pytest.mark.parametrize("theta, phi", list(zip(THETA, PHI)))
@pytest.mark.parametrize("analytic", [True, False])
@pytest.mark.parametrize("shots", [8192])
class TestVar:
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_var_hermitian(self, theta, phi, device, shots, tol):
assert np.allclose(var, expected, **tol)


@pytest.mark.parametrize("theta, phi, varphi", zip(THETA, PHI, VARPHI))
@pytest.mark.parametrize("theta, phi, varphi", list(zip(THETA, PHI, VARPHI)))
@pytest.mark.parametrize("analytic", [True, False])
@pytest.mark.parametrize("shots", [8192])
class TestTensorVar:
Expand Down

0 comments on commit e7a0d48

Please sign in to comment.