Skip to content

Commit

Permalink
IBMQ probs test (#82)
Browse files Browse the repository at this point in the history
* Adding an IBMQ probability test

* Changing to PL-Qiskit tol fixture

* Removing commented out line, updating docstring

* CHANGELOG

Co-authored-by: Josh Izaac <[email protected]>
  • Loading branch information
antalszava and josh146 authored Apr 15, 2020
1 parent 9b462af commit 899b606
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@

### Breaking changes

* Now supports Qiskit version 0.18.0. As a result of breaking changes
within Qiskit, version 0.17 and below are no longer supported.
[(#81)](https://github.com/XanaduAI/pennylane-qiskit/pull/81)

### 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.
[(#78)](https://github.com/XanaduAI/pennylane-qiskit/pull/78)

### Bug fixes

* Renamed `QiskitDevice.probabilities` to `QiskitDevice.probability` to overload `pennylane.Device.probability`. This fixes a bug that raises `NotImplementedError` when a QNode is used to compute probabilities on a IBMQ device.
[(#80)](https://github.com/XanaduAI/pennylane-qiskit/pull/80)
* 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)

* Renamed `QiskitDevice.probabilities` to `QiskitDevice.probability` to overload
`pennylane.Device.probability`. This fixes a bug that raises `NotImplementedError`
when a QNode is used to compute probabilities on a IBMQ device.
[(#80)](https://github.com/XanaduAI/pennylane-qiskit/pull/80)


### Contributors

This release contains contributions from (in alphabetical order):

Rafael Haenel
Rafael Haenel, Josh Izaac, Maria Schuld, Antal Száva

---

Expand Down
25 changes: 25 additions & 0 deletions tests/test_ibmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,28 @@ 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 probs function works."""
IBMQ.enable_account(token)
dev = IBMQDevice(wires=2, backend="ibmq_qasm_simulator", shots=shots)
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)

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))

0 comments on commit 899b606

Please sign in to comment.