Skip to content

Commit

Permalink
Fix is_sampled and its test (#1126)
Browse files Browse the repository at this point in the history
* is_sampled and test fix

* changelog

* fix
  • Loading branch information
antalszava committed Mar 9, 2021
1 parent 10fde20 commit 12c3dc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 12c3dc2

Please sign in to comment.