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

Update plugin by removing analytic argument for device creation #130

Merged
merged 13 commits into from
Mar 28, 2021

Conversation

glassnotes
Copy link
Contributor

Fixes the plugin to work with new changes in PennyLane:

  • the analytic argument has been removed and replaced by shots=None where applicable
  • the qml._queueing.OperationRecorder has been replaced by qml.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).

@glassnotes glassnotes requested a review from thisac March 24, 2021 12:43
@codecov
Copy link

codecov bot commented Mar 24, 2021

Codecov Report

Merging #130 (e9fc18e) into master (908eaec) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
pennylane_qiskit/aer.py 100.00% <ø> (ø)
pennylane_qiskit/basic_aer.py 100.00% <ø> (ø)
pennylane_qiskit/qiskit_device.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 908eaec...e9fc18e. Read the comment docs.

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
Copy link
Contributor

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

requirements.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@antalszava antalszava left a 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. 🙂

tests/conftest.py Outdated Show resolved Hide resolved
@pytest.mark.parametrize("analytic", [True])
@pytest.mark.parametrize("shots", [8192])

@pytest.mark.parametrize("shots", [None])
Copy link
Contributor

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."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Changed)

Comment on lines +1008 to +1010
@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):
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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])
Copy link
Contributor

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])
Copy link
Contributor

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Changed)

yield qml.Device()


@pytest.fixture(scope="function")
def recorder():
return qml._queuing.OperationRecorder()
return qml.tape.OperationRecorder()
Copy link
Contributor Author

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:
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Changed)

@glassnotes
Copy link
Contributor Author

Looks good to me! 100 Thank you! slightly_smiling_face Coverage seems to be okay locally, not sure why codecov fails thinking

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. slightly_smiling_face

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?

pennylane_qiskit/aer.py Outdated Show resolved Hide resolved
@josh146
Copy link
Member

josh146 commented Mar 28, 2021

Thanks @antalszava ! I didn't know the tests don't usually get blacked, sorry for the hassle!

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 😆

@glassnotes
Copy link
Contributor Author

Thanks @antalszava ! I didn't know the tests don't usually get blacked, sorry for the hassle!

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 laughing

@josh146 I see, thanks for the context!

Regarding tests - could you please override codecov? (it's showing a diff of like -0.01%)

@josh146 josh146 merged commit ef50766 into master Mar 28, 2021
@josh146 josh146 deleted the remove-analytic-argument branch March 28, 2021 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants