-
Notifications
You must be signed in to change notification settings - Fork 68
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
Update plugin by removing analytic
argument for device creation
#130
Conversation
Codecov Report
@@ Coverage Diff @@
## master #130 +/- ##
==========================================
- Coverage 99.30% 99.30% -0.01%
==========================================
Files 7 7
Lines 289 286 -3
==========================================
- Hits 287 284 -3
Misses 2 2
Continue to review full report at Codecov.
|
Co-authored-by: antalszava <[email protected]>
pl-device-test --device=qiskit.aer --tb=short --skip-ops --analytic=True --device-kwargs backend=unitary_simulator | ||
pl-device-test --device=qiskit.basicaer --tb=short --skip-ops --shots=20000 --device-kwargs backend=qasm_simulator | ||
pl-device-test --device=qiskit.aer --tb=short --skip-ops --shots=20000 --device-kwargs backend=qasm_simulator | ||
pl-device-test --device=qiskit.aer --tb=short --skip-ops --shots=None --device-kwargs backend=statevector_simulator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failures in the device test suite originated from the fact that the device keyword arguments were ignored by PennyLane core. Therefore, even for backend=statevector_simulator
we got qasm_simulator
, though this time with shots=None
, which were then changed to 1024 internally (HW warning branch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 💯 Thank you! 🙂 Coverage seems to be okay locally, not sure why codecov fails 🤔
Usually, using black
, the source files would be formatted and tests are left intact, though those can also be formatted (black -l 100 pennylane_qiskit
). If the tests are formatted, it's good to separate a change in logic and formatting. Left comments across the test files for places where I noticed a change, let me know if something was missed. 🙂
@pytest.mark.parametrize("analytic", [True]) | ||
@pytest.mark.parametrize("shots", [8192]) | ||
|
||
@pytest.mark.parametrize("shots", [None]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above 3 diffs were changes
@pytest.mark.usefixtures("skip_unitary") | ||
class TestNonAnalyticApply: | ||
"""Test application of PennyLane operations with the analytic attribute set to False.""" | ||
"""Test application of PennyLane operations with non-analytic calculation.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
@pytest.mark.parametrize("shots", [None]) | ||
@pytest.mark.parametrize("theta,phi,varphi", list(zip(THETA, PHI, VARPHI))) | ||
def test_gradient(self, theta, phi, varphi, analytic, tol): | ||
def test_gradient(self, theta, phi, varphi, shots, tol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
@@ -1001,7 +1021,7 @@ def test_gradient(self, theta, phi, varphi, analytic, tol): | |||
# convert to a PennyLane circuit | |||
qc_pl = qml.from_qiskit(qc) | |||
|
|||
dev = qml.device("default.qubit", wires=3, analytic=analytic) | |||
dev = qml.device("default.qubit", wires=3, shots=shots) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
|
||
with pytest.warns(UserWarning) as record: | ||
dev = qml.device("qiskit.basicaer", backend=hardware_backend, wires=2, analytic=True) | ||
dev = qml.device("qiskit.basicaer", backend=hardware_backend, wires=2, shots=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
|
||
dev = qml.device("qiskit.basicaer", backend=statevector_backend, wires=2, analytic=True) | ||
dev = qml.device("qiskit.basicaer", backend=statevector_backend, wires=2, shots=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
@@ -15,7 +15,6 @@ | |||
VARPHI = np.linspace(0.02, 1, 3) | |||
|
|||
|
|||
@pytest.mark.parametrize("analytic", [False]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
@@ -16,8 +16,7 @@ | |||
|
|||
|
|||
@pytest.mark.parametrize("theta, phi", list(zip(THETA, PHI))) | |||
@pytest.mark.parametrize("analytic", [True, False]) | |||
@pytest.mark.parametrize("shots", [8192]) | |||
@pytest.mark.parametrize("shots", [None, 8192]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
@@ -74,8 +73,7 @@ def test_var_hermitian(self, theta, phi, device, shots, tol): | |||
|
|||
|
|||
@pytest.mark.parametrize("theta, phi, varphi", list(zip(THETA, PHI, VARPHI))) | |||
@pytest.mark.parametrize("analytic", [True, False]) | |||
@pytest.mark.parametrize("shots", [8192]) | |||
@pytest.mark.parametrize("shots", [None, 8192]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
Co-authored-by: antalszava <[email protected]>
yield qml.Device() | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def recorder(): | ||
return qml._queuing.OperationRecorder() | ||
return qml.tape.OperationRecorder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
def device(request, backend, shots, analytic): | ||
if backend not in state_backends and analytic == True: | ||
def device(request, backend, shots): | ||
if backend not in state_backends and shots is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
def _device(n): | ||
return request.param(wires=n, backend=statevector_backend, shots=shots, analytic=analytic) | ||
return request.param(wires=n, backend=statevector_backend, shots=shots) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This and the previous two are changed)
dev = qml.device(d[0], wires=1, backend=backend, shots=shots, analytic=analytic) | ||
def test_one_qubit_circuit(self, shots, d, backend, tol): | ||
"""Integration test for the BasisState and Rot operations for non-analytic mode.""" | ||
dev = qml.device(d[0], wires=1, backend=backend, shots=shots) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Changed)
Thanks @antalszava ! I didn't know the tests don't usually get blacked, sorry for the hassle! I marked a few other spots where there were changes. Can we override codecov in order to merge in? |
Note: this is just a historical accident that the tests don't get blacked/checked on GitHub. Partially to make the transition to blacking easier for everyone. While probably better to black the tests in their own PR, nice to have the tests finally blacked 😆 |
Co-authored-by: antalszava <[email protected]>
@josh146 I see, thanks for the context! Regarding tests - could you please override codecov? (it's showing a diff of like -0.01%) |
Fixes the plugin to work with new changes in PennyLane:
analytic
argument has been removed and replaced byshots=None
where applicableqml._queueing.OperationRecorder
has been replaced byqml.tape.OperationRecorder
in tests where applicable(I also ran
black
on the code, and it changed a bit more formatted than I expected so sorry the changes may be a bit buried in some files).