Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBMQ probs test #82

Merged
merged 6 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))