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 #100

Merged
merged 4 commits into from
Apr 16, 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
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
pip install wheel pytest pytest-benchmark pytest-cov pytest-mock flaky --upgrade

- name: Install Plugin
run: |
Expand All @@ -75,6 +75,7 @@ jobs:
pl-device-test --device=ionq.simulator --tb=short --skip-ops --shots=10000

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.codecov_token }}
file: ./coverage.xml
5 changes: 4 additions & 1 deletion pennylane_ionq/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class IonQDevice(QubitDevice):
distribution has peaks. See `IonQ Debiasing and Sharpening
<https://ionq.com/resources/debiasing-and-sharpening>`_ for details.
"""

# pylint: disable=too-many-instance-attributes
name = "IonQ PennyLane plugin"
short_name = "ionq"
Expand All @@ -100,7 +101,7 @@ class IonQDevice(QubitDevice):

# Note: unlike QubitDevice, IonQ does not support QubitUnitary,
# and therefore does not support the Hermitian observable.
observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Identity"}
observables = {"PauliX", "PauliY", "PauliZ", "Hadamard", "Identity", "Prod"}

def __init__(
self,
Expand Down Expand Up @@ -285,6 +286,7 @@ class SimulatorDevice(IonQDevice):
api_key (str): The IonQ API key. If not provided, the environment
variable ``IONQ_API_KEY`` is used.
"""

name = "IonQ Simulator PennyLane plugin"
short_name = "ionq.simulator"

Expand Down Expand Up @@ -329,6 +331,7 @@ class QPUDevice(IonQDevice):
your expected output distribution has peaks. See `IonQ Debiasing and Sharpening
<https://ionq.com/resources/debiasing-and-sharpening>`_ for details.
"""

name = "IonQ QPU PennyLane plugin"
short_name = "ionq.qpu"

Expand Down
6 changes: 6 additions & 0 deletions pennylane_ionq/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GPI(Operation): # pylint: disable=too-few-public-methods
phi (float): phase :math:`\phi`
wires (Sequence[int]): the subsystems the operation acts on
"""

num_params = 1
num_wires = 1
grad_method = None
Expand All @@ -53,6 +54,7 @@ class GPI2(Operation): # pylint: disable=too-few-public-methods
phi (float): phase :math:`\phi`
wires (Sequence[int]): the subsystems the operation acts on
"""

num_params = 1
num_wires = 1
grad_method = None
Expand All @@ -76,6 +78,7 @@ class MS(Operation): # pylint: disable=too-few-public-methods
phi1 (float): phase of the second qubit :math:`\phi`
wires (Sequence[int]): the subsystems the operation acts on
"""

num_params = 2
num_wires = 2
grad_method = None
Expand All @@ -101,6 +104,7 @@ class XX(Operation):
phi (float): rotation angle :math:`\phi`
wires (Sequence[int]): the subsystems the operation acts on
"""

num_params = 1
num_wires = 2
grad_method = "A"
Expand All @@ -123,6 +127,7 @@ class YY(Operation):
phi (float): rotation angle :math:`\phi`
wires (Sequence[int]): the subsystems the operation acts on
"""

num_params = 1
num_wires = 2
grad_method = "A"
Expand All @@ -145,6 +150,7 @@ class ZZ(Operation):
phi (float): rotation angle :math:`\phi`
wires (Sequence[int]): the subsystems the operation acts on
"""

num_params = 1
num_wires = 2
grad_method = "A"
1 change: 0 additions & 1 deletion tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ def __init__(self, client=None, api_key=None):
res = WithID(api_key="test")
res.reload()


def test_create_created(self, monkeypatch):
"""
Tests a successful Job creatioin with a mock POST response. Asserts that all fields on
Expand Down
5 changes: 3 additions & 2 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ def test_probability(self):
assert np.array_equal(dev.probability(shot_range=(0, 2)), [0, 0, 0, 1])

uniform_prob = [0.25] * 4
with patch("pennylane_ionq.device.SimulatorDevice.prob", new_callable=PropertyMock) as mock_prob:
with patch(
"pennylane_ionq.device.SimulatorDevice.prob", new_callable=PropertyMock
) as mock_prob:
mock_prob.return_value = uniform_prob
assert np.array_equal(dev.probability(), uniform_prob)


@pytest.mark.parametrize("backend", ["harmony", "aria-1", "aria-2", "forte-1", None])
def test_backend_initialization(self, backend):
"""Test that the device initializes with the correct backend."""
Expand Down
Loading