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

jit with sampling multi-wire observable #5422

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@

<h3>Bug fixes 🐛</h3>

* `jax.jit` now works with `qml.sample` with a multi-wire observable.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved

* We no longer perform unwanted dtype promotion in the `pauli_rep` of `SProd` instances when using tensorflow.
[(#5246)](https://github.com/PennyLaneAI/pennylane/pull/5246)

Expand Down
5 changes: 4 additions & 1 deletion pennylane/measurements/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ def shape(self, device, shots):
"Shots are required to obtain the shape of the measurement "
f"{self.__class__.__name__}."
)
len_wires = len(self.wires) if len(self.wires) > 0 else len(device.wires)
if self.obs:
len_wires = 1
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
else:
len_wires = len(self.wires) if len(self.wires) > 0 else len(device.wires)

def _single_int_shape(shot_val, num_wires):
# singleton dimensions, whether in shot val or num_wires are squeezed away
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ def test_sampling(self, dev, diff_method, grad_on_execution, device_vjp, interfa
if diff_method == "adjoint":
pytest.skip("Adjoint warns with finite shots")

@qnode(
@qml.qnode(
dev,
diff_method=diff_method,
interface=interface,
Expand All @@ -918,7 +918,7 @@ def test_sampling(self, dev, diff_method, grad_on_execution, device_vjp, interfa
def circuit():
qml.Hadamard(wires=[0])
qml.CNOT(wires=[0, 1])
return qml.sample(qml.PauliZ(0)), qml.sample(qml.PauliX(1))
return qml.sample(qml.Z(0)), qml.sample(qml.s_prod(2, qml.X(0) @ qml.Y(1)))

res = jax.jit(circuit, static_argnames="shots")(shots=10)

Expand Down
Loading