Skip to content

Commit

Permalink
feat: add phase RX gate (#172)
Browse files Browse the repository at this point in the history
* feat: add phase RX gate

* Update qiskit_braket_provider/providers/adapter.py

Co-authored-by: Ryan Shaffer <[email protected]>

* fix tests

* fix tests

* formatting fix

* remove divisor

* Update qiskit_braket_provider/providers/adapter.py

---------

Co-authored-by: Coull <[email protected]>
Co-authored-by: Ryan Shaffer <[email protected]>
Co-authored-by: Cody Wang <[email protected]>
  • Loading branch information
4 people authored Apr 23, 2024
1 parent 8868fec commit 8af2ada
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/how_tos/data/3_hybrid_jobs/algorithm_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example of usage of Qiskit-Braket provider."""

from braket.jobs import save_job_result
from qiskit import QuantumCircuit

Expand Down
3 changes: 3 additions & 0 deletions qiskit_braket_provider/providers/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"cswap": "cswap",
"cphaseshift": "cp",
"ecr": "ecr",
"prx": "r",
"gpi": "gpi",
"gpi2": "gpi2",
"ms": "ms",
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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)),
Expand Down
16 changes: 10 additions & 6 deletions qiskit_braket_provider/providers/braket_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
]

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Setup file for Qiskit-Braket provider."""

import os
from typing import Any, Dict, Optional

Expand Down
13 changes: 9 additions & 4 deletions tests/providers/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -222,6 +222,7 @@ def test_mappers(self):
"id": "i",
"ccx": "ccnot",
"cp": "cphaseshift",
"r": "prx",
"rxx": "xx",
"ryy": "yy",
"zz": "zz",
Expand Down Expand Up @@ -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:
Expand All @@ -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
]

Expand Down

0 comments on commit 8af2ada

Please sign in to comment.