diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 4898979..c5922aa 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 steps: - - uses: actions/checkout@v6.0.3 + - uses: actions/checkout@v7.0.0 - name: Install juliaup uses: julia-actions/install-juliaup@v3 with: diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml index b4f4fb9..2139856 100644 --- a/.github/workflows/check-format.yml +++ b/.github/workflows/check-format.yml @@ -16,7 +16,7 @@ jobs: check-code-format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6.0.3 + - uses: actions/checkout@v7.0.0 - name: Set up Python uses: actions/setup-python@v6 with: diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index a104169..fd78ec1 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -17,7 +17,7 @@ jobs: permissions: id-token: write steps: - - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v5.0.1 + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v5.0.1 - name: Set up Python uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 with: diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index fb84d82..5f0f5d1 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -22,7 +22,7 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.11", "3.12", "3.13"] steps: - - uses: actions/checkout@v6.0.3 + - uses: actions/checkout@v7.0.0 - name: Install juliaup uses: julia-actions/install-juliaup@v3 with: diff --git a/.github/workflows/twine-check.yml b/.github/workflows/twine-check.yml index 5caa187..1b936c5 100644 --- a/.github/workflows/twine-check.yml +++ b/.github/workflows/twine-check.yml @@ -14,7 +14,7 @@ jobs: name: Check long description runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6.0.3 + - uses: actions/checkout@v7.0.0 - name: Set up Python uses: actions/setup-python@v6 with: diff --git a/test/unit_tests/braket/simulator_v2/test_pennylane.py b/test/unit_tests/braket/simulator_v2/test_pennylane.py index 19f2fdc..bb631ab 100644 --- a/test/unit_tests/braket/simulator_v2/test_pennylane.py +++ b/test/unit_tests/braket/simulator_v2/test_pennylane.py @@ -17,7 +17,7 @@ import numpy as anp import pennylane as qml import pytest -from braket.circuits import Circuit, Gate, Noise, Observable, result_types +from braket.circuits import Circuit, FreeParameter, Gate, Noise, Observable, result_types from braket.circuits.noise_model import GateCriteria, NoiseModel, NoiseModelInstruction from braket.devices import LocalSimulator from braket.pennylane_plugin import BraketLocalQubitDevice @@ -40,17 +40,82 @@ SIM_TASK.result.return_value.result_types = [] type(SIM_TASK).id = PropertyMock(return_value="task_arn") SIM_TASK.state.return_value = "COMPLETED" + CIRCUIT = ( Circuit() .h(0) .cnot(0, 1) - .i(2) + .ry(1, -np.pi / 2) + .rx(2, np.pi / 2) + .i(3) + .probability(target=[0]) + .expectation(observable=Observable.Z(), target=1) + .variance(observable=Observable.Z(), target=2) + .sample(observable=Observable.Z(), target=3) +) + +CIRCUIT_QUBIT_DEVICE = ( + Circuit() + .h(0) + .cnot(0, 1) + .ry(1, FreeParameter("p_0")) + .rx(2, FreeParameter("p_1")) .i(3) .probability(target=[0]) - .expectation(observable=Observable.X(), target=1) - .variance(observable=Observable.Y(), target=2) + .expectation(observable=Observable.Z(), target=1) + .variance(observable=Observable.Z(), target=2) .sample(observable=Observable.Z(), target=3) ) +INPUTS_QUBIT_DEVICE = {"p_0": -np.pi / 2, "p_1": np.pi / 2} + +RESULT_QUBIT_DEVICE = GateModelQuantumTaskResult.from_string( + json.dumps({ + "braketSchemaHeader": { + "name": "braket.task_result.gate_model_task_result", + "version": "1", + }, + "measurements": [[0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1]], + "resultTypes": [ + {"type": {"targets": [0], "type": "probability"}, "value": [0.5, 0.5]}, + { + "type": {"observable": ["z"], "targets": [1], "type": "expectation"}, + "value": 0.0, + }, + { + "type": {"observable": ["z"], "targets": [2], "type": "variance"}, + "value": 0.1, + }, + { + "type": {"observable": ["z"], "targets": [3], "type": "sample"}, + "value": [1, -1, 1, 1], + }, + ], + "measuredQubits": [0, 1, 2, 3], + "taskMetadata": { + "braketSchemaHeader": { + "name": "braket.task_result.task_metadata", + "version": "1", + }, + "id": "task_arn", + "shots": 0, + "deviceId": "default", + }, + "additionalMetadata": { + "action": { + "braketSchemaHeader": { + "name": "braket.ir.openqasm.program", + "version": "1", + }, + "source": "qubit[2] q; cnot q[0], q[1]; measure q;", + }, + }, + }) +) + +TASK_QUBIT_DEVICE = Mock() +TASK_QUBIT_DEVICE.result.return_value = RESULT_QUBIT_DEVICE +type(TASK_QUBIT_DEVICE).id = PropertyMock(return_value="task_arn") +TASK_QUBIT_DEVICE.state.return_value = "COMPLETED" DEVICE_ARN = "baz" @@ -246,7 +311,7 @@ def test_local_none_shots(backend): @pytest.mark.parametrize("backend", ["braket_sv_v2", "braket_dm_v2"]) def test_local_qubit_execute(mock_run, shots, backend): """Tests that the local qubit device is run with the correct arguments""" - mock_run.return_value = TASK + mock_run.return_value = TASK_QUBIT_DEVICE dev = BraketLocalQubitDevice(wires=4, backend=backend, shots=shots, foo="bar") with QuantumTape() as circuit: @@ -258,7 +323,9 @@ def test_local_qubit_execute(mock_run, shots, backend): qml.sample(qml.PauliZ(3)) dev.execute(circuit) - mock_run.assert_called_with(CIRCUIT, shots=shots, foo="bar", inputs={}) + mock_run.assert_called_with( + CIRCUIT_QUBIT_DEVICE, shots=shots, foo="bar", inputs=INPUTS_QUBIT_DEVICE + ) def test_projection():