From 0adf43dff13654a803a8415ffe79c260b7190a62 Mon Sep 17 00:00:00 2001 From: Astral Cai Date: Tue, 16 Apr 2024 15:57:50 -0400 Subject: [PATCH] Add Prod observable support (#100) * Add Prod observable support * Trigger CI * Trigger CI * Update tests.yml --- .github/workflows/tests.yml | 5 +++-- pennylane_ionq/device.py | 5 ++++- pennylane_ionq/ops.py | 6 ++++++ tests/test_api_client.py | 1 - tests/test_device.py | 5 +++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 419c962..9a60849 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: | @@ -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 diff --git a/pennylane_ionq/device.py b/pennylane_ionq/device.py index 5d19c08..4f46216 100644 --- a/pennylane_ionq/device.py +++ b/pennylane_ionq/device.py @@ -85,6 +85,7 @@ class IonQDevice(QubitDevice): distribution has peaks. See `IonQ Debiasing and Sharpening `_ for details. """ + # pylint: disable=too-many-instance-attributes name = "IonQ PennyLane plugin" short_name = "ionq" @@ -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, @@ -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" @@ -329,6 +331,7 @@ class QPUDevice(IonQDevice): your expected output distribution has peaks. See `IonQ Debiasing and Sharpening `_ for details. """ + name = "IonQ QPU PennyLane plugin" short_name = "ionq.qpu" diff --git a/pennylane_ionq/ops.py b/pennylane_ionq/ops.py index 8a11d63..d826d58 100644 --- a/pennylane_ionq/ops.py +++ b/pennylane_ionq/ops.py @@ -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 @@ -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 @@ -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 @@ -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" @@ -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" @@ -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" diff --git a/tests/test_api_client.py b/tests/test_api_client.py index c465f01..4ef7926 100755 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -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 diff --git a/tests/test_device.py b/tests/test_device.py index 6333fe6..f50f782 100755 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -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."""