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

Add Prod observable support #155

Merged
merged 1 commit into from
Apr 17, 2024
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
2 changes: 1 addition & 1 deletion pennylane_rigetti/numpy_wavefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NumpyWavefunctionDevice(RigettiDevice):
name = "pyQVM NumpyWavefunction Simulator Device"
short_name = "rigetti.numpy_wavefunction"

observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Hermitian", "Identity"}
observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Hermitian", "Identity", "Prod"}

def __init__(self, wires, *, shots=None):
super().__init__(wires, shots)
Expand Down
3 changes: 2 additions & 1 deletion pennylane_rigetti/qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import numpy as np
from pennylane.measurements import Expectation
from pennylane.operation import Tensor
from pennylane.ops import Prod
from pennylane.tape import QuantumTape
from pyquil import get_qc
from pyquil.api import QuantumComputer
Expand Down Expand Up @@ -141,7 +142,7 @@ def expval(self, observable, shot_range=None, bin_size=None):
pauli_obs = sZ(wire)

# Multi-qubit observable
elif len(device_wires) > 1 and isinstance(observable, Tensor):
elif len(device_wires) > 1 and isinstance(observable, (Tensor, Prod)):
# All observables are rotated to be measured in the Z-basis, so we just need to
# check which wires exist in the observable, map them to physical qubits, and measure
# the product of PauliZ operators on those qubits
Expand Down
2 changes: 1 addition & 1 deletion pennylane_rigetti/wavefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class WavefunctionDevice(RigettiDevice):
name = "Rigetti Wavefunction Simulator Device"
short_name = "rigetti.wavefunction"

observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Hermitian", "Identity"}
observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Hermitian", "Identity", "Prod"}

def __init__(self, wires, *, shots=None):
super().__init__(wires, shots)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,9 +1148,7 @@ def test_load_quil_file_via_entry_point(self):
cur_dir = os.path.dirname(os.path.abspath(__file__))

with OperationRecorder() as rec:
qml.from_quil_file(os.path.join(cur_dir, "simple_program.quil"))(
wires=range(5)
)
qml.from_quil_file(os.path.join(cur_dir, "simple_program.quil"))(wires=range(5))

# The wires should be assigned as
# 0 1 2 3 7
Expand Down
Loading