From 40c844b985513a32da4dfd4628cda79da8dbbc57 Mon Sep 17 00:00:00 2001 From: antalszava Date: Tue, 14 Apr 2020 20:09:30 -0400 Subject: [PATCH 1/4] Adding an IBMQ probability test --- tests/test_ibmq.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_ibmq.py b/tests/test_ibmq.py index b3b02ffad..4fd58c592 100644 --- a/tests/test_ibmq.py +++ b/tests/test_ibmq.py @@ -140,3 +140,27 @@ def circuit(theta, phi): res = circuit(theta, phi) expected = np.array([np.cos(theta), np.cos(theta) * np.cos(phi)]) assert np.allclose(res, expected, **tol) + + +@pytest.mark.parametrize("analytic", [False]) +@pytest.mark.parametrize("x", [[0.2, 0.5], [0.4, 0.9], [0.8, 0.3]]) +@pytest.mark.parametrize("shots", [1000]) +def test_probability(token, x, tol, shots): + """Test that the probability function works when analytic=False""" + IBMQ.enable_account(token) + dev = IBMQDevice(wires=2, backend="ibmq_qasm_simulator", shots=shots) + # dev = qml.device("default.qubit", wires=2, analytic=False) + dev_analytic = qml.device("default.qubit", wires=2, analytic=True) + + def circuit(x): + qml.RX(x[0], wires=0) + qml.RY(x[1], wires=0) + qml.CNOT(wires=[0, 1]) + return qml.probs(wires=[0, 1]) + + prob = qml.QNode(circuit, dev) + prob_analytic = qml.QNode(circuit, dev_analytic) + + assert np.isclose(prob(x).sum(), 1, atol=tol, rtol=0) + assert np.allclose(prob_analytic(x), prob(x), atol=0.1, rtol=0) + assert not np.array_equal(prob_analytic(x), prob(x)) From f59ba6a5ccce3296404e8226389d855c45427eed Mon Sep 17 00:00:00 2001 From: antalszava Date: Tue, 14 Apr 2020 20:40:28 -0400 Subject: [PATCH 2/4] Changing to PL-Qiskit tol fixture --- tests/test_ibmq.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_ibmq.py b/tests/test_ibmq.py index 4fd58c592..7987c6e27 100644 --- a/tests/test_ibmq.py +++ b/tests/test_ibmq.py @@ -161,6 +161,8 @@ def circuit(x): prob = qml.QNode(circuit, dev) prob_analytic = qml.QNode(circuit, dev_analytic) - assert np.isclose(prob(x).sum(), 1, atol=tol, rtol=0) - assert np.allclose(prob_analytic(x), prob(x), atol=0.1, rtol=0) + called_prob = prob(x) + + assert np.isclose(called_prob.sum(), 1, **tol) + assert np.allclose(prob_analytic(x), prob(x), **tol) assert not np.array_equal(prob_analytic(x), prob(x)) From 5d857ddddc658cdb8d39b24f12073306e8bb24bb Mon Sep 17 00:00:00 2001 From: antalszava Date: Tue, 14 Apr 2020 20:41:56 -0400 Subject: [PATCH 3/4] Removing commented out line, updating docstring --- tests/test_ibmq.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_ibmq.py b/tests/test_ibmq.py index 7987c6e27..1fbed5583 100644 --- a/tests/test_ibmq.py +++ b/tests/test_ibmq.py @@ -146,10 +146,9 @@ def circuit(theta, phi): @pytest.mark.parametrize("x", [[0.2, 0.5], [0.4, 0.9], [0.8, 0.3]]) @pytest.mark.parametrize("shots", [1000]) def test_probability(token, x, tol, shots): - """Test that the probability function works when analytic=False""" + """Test that the probs function works.""" IBMQ.enable_account(token) dev = IBMQDevice(wires=2, backend="ibmq_qasm_simulator", shots=shots) - # dev = qml.device("default.qubit", wires=2, analytic=False) dev_analytic = qml.device("default.qubit", wires=2, analytic=True) def circuit(x): From 29b1b0fe7b35afed8e0696b60cf10e85c8fcd71a Mon Sep 17 00:00:00 2001 From: antalszava Date: Tue, 14 Apr 2020 23:24:43 -0400 Subject: [PATCH 4/4] CHANGELOG --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb1ef58e0..222a716ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ ### Improvements +* Added a test for returning probabilities when using the `IBMQDevice`. + [(#82)](https://github.com/XanaduAI/pennylane-qiskit/pull/82) + ### Documentation * Major redesign of the documentation, making it easier to navigate. @@ -13,10 +16,16 @@ ### Bug fixes +* Added a type conversion of parameters for parametrized gates and renamed + various gates for Qiskit version 0.18.0 support. + [(#81)](https://github.com/XanaduAI/pennylane-qiskit/pull/81) + ### Contributors This release contains contributions from (in alphabetical order): +Josh Izaac, Maria Schuld, Antal Száva + --- # Release 0.8.2