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

Fix is_sampled and its test #1126

Merged
merged 3 commits into from
Mar 9, 2021
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
6 changes: 5 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@

<h3>Bug fixes</h3>

* Fixes a bug and a test where the ``QuantumTape.is_sampled`` attribute was not
being updated.
[(#1126)](https://github.com/PennyLaneAI/pennylane/pull/1126)

* Fixes a bug where `BasisEmbedding` would not accept inputs whose bits are all ones
or all zeros.
[(#1114)](https://github.com/PennyLaneAI/pennylane/pull/1114)
Expand All @@ -261,7 +265,7 @@
This release contains contributions from (in alphabetical order):

Thomas Bromley, Olivia Di Matteo, Kyle Godbey, Diego Guala, Josh Izaac, Daniel Polatajko, Chase Roberts,
Sankalp Sanand, Pritish Sehzpaul, Maria Schuld.
Sankalp Sanand, Pritish Sehzpaul, Maria Schuld, Antal Száva.

# Release 0.14.1 (current release)

Expand Down
2 changes: 2 additions & 0 deletions pennylane/tape/tapes/tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ def _update_circuit_info(self):
[op.wires for op in self.operations + self.observables]
)
self.num_wires = len(self.wires)

self.is_sampled = any(m.return_type is Sample for m in self.measurements)
self.all_sampled = all(m.return_type is Sample for m in self.measurements)

def _update_observables(self):
Expand Down
7 changes: 6 additions & 1 deletion tests/tape/tapes/test_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,14 @@ def circuit():
qml.T(wires=0)
return sample(qml.PauliZ(0))

qnode = qml.tape.QNode(circuit, dev)
# Choosing parameter-shift not to swap the device under the hood
qnode = qml.tape.QNode(circuit, dev, diff_method="parameter-shift")
qnode()

# Double-checking that the T gate is not supported
assert "T" not in qnode.device.operations
assert "T" not in qnode._original_device.operations

assert qnode.qtape.is_sampled

class TestExecution:
Expand Down