From 8af2ada3cc65b4735e690a6edfe9de119434fdb6 Mon Sep 17 00:00:00 2001 From: Abe Coull <85974725+math411@users.noreply.github.com> Date: Tue, 23 Apr 2024 08:14:07 -0700 Subject: [PATCH] feat: add phase RX gate (#172) * feat: add phase RX gate * Update qiskit_braket_provider/providers/adapter.py Co-authored-by: Ryan Shaffer <3620100+rmshaffer@users.noreply.github.com> * fix tests * fix tests * formatting fix * remove divisor * Update qiskit_braket_provider/providers/adapter.py --------- Co-authored-by: Coull Co-authored-by: Ryan Shaffer <3620100+rmshaffer@users.noreply.github.com> Co-authored-by: Cody Wang --- .../data/3_hybrid_jobs/algorithm_script.py | 1 + qiskit_braket_provider/providers/adapter.py | 3 +++ qiskit_braket_provider/providers/braket_task.py | 16 ++++++++++------ setup.py | 1 + tests/providers/test_adapter.py | 13 +++++++++---- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/docs/how_tos/data/3_hybrid_jobs/algorithm_script.py b/docs/how_tos/data/3_hybrid_jobs/algorithm_script.py index 04b1b3ac..8bc7ea00 100644 --- a/docs/how_tos/data/3_hybrid_jobs/algorithm_script.py +++ b/docs/how_tos/data/3_hybrid_jobs/algorithm_script.py @@ -1,4 +1,5 @@ """Example of usage of Qiskit-Braket provider.""" + from braket.jobs import save_job_result from qiskit import QuantumCircuit diff --git a/qiskit_braket_provider/providers/adapter.py b/qiskit_braket_provider/providers/adapter.py index 9262002c..7ce1ddf3 100644 --- a/qiskit_braket_provider/providers/adapter.py +++ b/qiskit_braket_provider/providers/adapter.py @@ -62,6 +62,7 @@ "cswap": "cswap", "cphaseshift": "cp", "ecr": "ecr", + "prx": "r", "gpi": "gpi", "gpi2": "gpi2", "ms": "ms", @@ -119,6 +120,7 @@ "ryy": lambda angle: [braket_gates.YY(angle)], "ecr": lambda: [braket_gates.ECR()], "iswap": lambda: [braket_gates.ISwap()], + "r": lambda angle_1, angle_2: [braket_gates.PRx(angle_1, angle_2)], # IonQ gates "gpi": lambda turns: [braket_gates.GPi(2 * pi * turns)], "gpi2": lambda turns: [braket_gates.GPi2(2 * pi * turns)], @@ -173,6 +175,7 @@ "z": qiskit_gates.ZGate(), "zz": qiskit_gates.RZZGate(Parameter("theta")), "ecr": qiskit_gates.ECRGate(), + "prx": qiskit_gates.RGate(Parameter("theta"), Parameter("phi")), "iswap": qiskit_gates.iSwapGate(), "gpi": ionq_gates.GPIGate(Parameter("phi") / (2 * pi)), "gpi2": ionq_gates.GPI2Gate(Parameter("phi") / (2 * pi)), diff --git a/qiskit_braket_provider/providers/braket_task.py b/qiskit_braket_provider/providers/braket_task.py index 4e9dd953..eb08858e 100644 --- a/qiskit_braket_provider/providers/braket_task.py +++ b/qiskit_braket_provider/providers/braket_task.py @@ -65,9 +65,11 @@ def _get_result_from_aws_tasks( experiment_result = ExperimentResult( shots=result.task_metadata.shots, success=True, - status=task.state() - if isinstance(task, LocalQuantumTask) - else result.task_metadata.status, + status=( + task.state() + if isinstance(task, LocalQuantumTask) + else result.task_metadata.status + ), data=data, ) experiment_results.append(experiment_result) @@ -176,9 +178,11 @@ def cancel(self): def status(self, use_cached_value: bool = False): braket_tasks_states = [ - task.state() - if isinstance(task, LocalQuantumTask) - else task.state(use_cached_value=use_cached_value) + ( + task.state() + if isinstance(task, LocalQuantumTask) + else task.state(use_cached_value=use_cached_value) + ) for task in self._tasks ] diff --git a/setup.py b/setup.py index d5d0c7b6..7e8294e5 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """Setup file for Qiskit-Braket provider.""" + import os from typing import Any, Dict, Optional diff --git a/tests/providers/test_adapter.py b/tests/providers/test_adapter.py index a748f7e7..9a0d1933 100644 --- a/tests/providers/test_adapter.py +++ b/tests/providers/test_adapter.py @@ -6,7 +6,7 @@ import numpy as np import pytest from braket.circuits import Circuit, FreeParameter, Gate, Instruction -from braket.circuits.angled_gate import AngledGate, TripleAngledGate +from braket.circuits.angled_gate import AngledGate, DoubleAngledGate, TripleAngledGate from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister from qiskit.circuit import Parameter, ParameterVector from qiskit.circuit.library import GlobalPhaseGate, PauliEvolutionGate @@ -222,6 +222,7 @@ def test_mappers(self): "id": "i", "ccx": "ccnot", "cp": "cphaseshift", + "r": "prx", "rxx": "xx", "ryy": "yy", "zz": "zz", @@ -546,6 +547,8 @@ def test_all_standard_gates(self): gate = getattr(Gate, gate_name) if issubclass(gate, AngledGate): op = gate(params_braket[0]) + elif issubclass(gate, DoubleAngledGate): + op = gate(params_braket[0], params_braket[1]) elif issubclass(gate, TripleAngledGate): op = gate(*params_braket) else: @@ -559,9 +562,11 @@ def test_all_standard_gates(self): param.name: param._uuid for param in qiskit_circuit.parameters } params_qiskit = [ - Parameter(param.name, uuid=param_uuids.get(param.name)) - if isinstance(param, FreeParameter) - else param + ( + Parameter(param.name, uuid=param_uuids.get(param.name)) + if isinstance(param, FreeParameter) + else param + ) for param in params_braket ]