Skip to content

Commit

Permalink
Merge branch 'main' into feature/job-decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
ajberdy authored Oct 11, 2023
2 parents 6046dbd + cbbd40e commit 53839b8
Show file tree
Hide file tree
Showing 68 changed files with 661 additions and 658 deletions.
2 changes: 0 additions & 2 deletions examples/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import os

from braket.aws import AwsDevice, AwsQuantumJob
from braket.circuits import Circuit
from braket.devices import Devices
Expand Down
7 changes: 3 additions & 4 deletions src/braket/ahs/analog_hamiltonian_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from collections import defaultdict
from functools import singledispatch
from typing import Tuple

import braket.ir.ahs as ir
from braket.ahs.atom_arrangement import AtomArrangement, SiteType
Expand Down Expand Up @@ -113,12 +112,12 @@ def discretize(self, device) -> AnalogHamiltonianSimulation: # noqa
@singledispatch
def _get_term_ir(
term: Hamiltonian,
) -> Tuple[str, dict]:
) -> tuple[str, dict]:
raise TypeError(f"Unable to convert Hamiltonian term type {type(term)}.")


@_get_term_ir.register
def _(term: ShiftingField) -> Tuple[str, ir.ShiftingField]:
def _(term: ShiftingField) -> tuple[str, ir.ShiftingField]:
return AnalogHamiltonianSimulation.SHIFTING_FIELDS_PROPERTY, ir.ShiftingField(
magnitude=ir.PhysicalField(
time_series=ir.TimeSeries(
Expand All @@ -131,7 +130,7 @@ def _(term: ShiftingField) -> Tuple[str, ir.ShiftingField]:


@_get_term_ir.register
def _(term: DrivingField) -> Tuple[str, ir.DrivingField]:
def _(term: DrivingField) -> tuple[str, ir.DrivingField]:
return AnalogHamiltonianSimulation.DRIVING_FIELDS_PROPERTY, ir.DrivingField(
amplitude=ir.PhysicalField(
time_series=ir.TimeSeries(
Expand Down
13 changes: 7 additions & 6 deletions src/braket/ahs/atom_arrangement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

from __future__ import annotations

from collections.abc import Iterator
from dataclasses import dataclass
from decimal import Decimal
from enum import Enum
from numbers import Number
from typing import Iterator, List, Tuple, Union
from typing import Union

import numpy as np

Expand All @@ -33,7 +34,7 @@ class SiteType(Enum):
class AtomArrangementItem:
"""Represents an item (coordinate and metadata) in an atom arrangement."""

coordinate: Tuple[Number, Number]
coordinate: tuple[Number, Number]
site_type: SiteType

def _validate_coordinate(self) -> None:
Expand Down Expand Up @@ -62,13 +63,13 @@ def __init__(self):

def add(
self,
coordinate: Union[Tuple[Number, Number], np.ndarray],
coordinate: Union[tuple[Number, Number], np.ndarray],
site_type: SiteType = SiteType.FILLED,
) -> AtomArrangement:
"""Add a coordinate to the atom arrangement.
Args:
coordinate (Union[Tuple[Number, Number], ndarray]): The coordinate of the
coordinate (Union[tuple[Number, Number], ndarray]): The coordinate of the
atom (in meters). The coordinates can be a numpy array of shape (2,)
or a tuple of int, float, Decimal
site_type (SiteType): The type of site. Optional. Default is FILLED.
Expand All @@ -78,14 +79,14 @@ def add(
self._sites.append(AtomArrangementItem(tuple(coordinate), site_type))
return self

def coordinate_list(self, coordinate_index: Number) -> List[Number]:
def coordinate_list(self, coordinate_index: Number) -> list[Number]:
"""Returns all the coordinates at the given index.
Args:
coordinate_index (Number): The index to get for each coordinate.
Returns:
List[Number]:The list of coordinates at the given index.
list[Number]:The list of coordinates at the given index.
Example:
To get a list of all x-coordinates: coordinate_list(0)
Expand Down
14 changes: 7 additions & 7 deletions src/braket/ahs/driving_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from __future__ import annotations

from typing import List, Union
from typing import Union

from braket.ahs.discretization_types import DiscretizationProperties
from braket.ahs.field import Field
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(
self._detuning = detuning if isinstance(detuning, Field) else Field(detuning)

@property
def terms(self) -> List[Hamiltonian]:
def terms(self) -> list[Hamiltonian]:
return [self]

@property
Expand Down Expand Up @@ -141,18 +141,18 @@ def discretize(self, properties: DiscretizationProperties) -> DrivingField:

@staticmethod
def from_lists(
times: List[float], amplitudes: List[float], detunings: List[float], phases: List[float]
times: list[float], amplitudes: list[float], detunings: list[float], phases: list[float]
) -> DrivingField:
"""
Builds DrivingField Hamiltonian from lists defining time evolution
of Hamiltonian parameters (Rabi frequency, detuning, phase).
The values of the parameters at each time points are global for all atoms.
Args:
times (List[float]): The time points of the driving field
amplitudes (List[float]): The values of the amplitude
detunings (List[float]): The values of the detuning
phases (List[float]): The values of the phase
times (list[float]): The time points of the driving field
amplitudes (list[float]): The values of the amplitude
detunings (list[float]): The values of the detuning
phases (list[float]): The values of the phase
Returns:
DrivingField: DrivingField Hamiltonian.
Expand Down
8 changes: 4 additions & 4 deletions src/braket/ahs/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from __future__ import annotations

from typing import List, Optional
from typing import Optional

from braket.ahs.discretization_types import DiscretizationProperties


class Hamiltonian:
def __init__(self, terms: Optional[List[Hamiltonian]] = None):
def __init__(self, terms: Optional[list[Hamiltonian]] = None):
r"""A Hamiltonian representing a system to be simulated.
A Hamiltonian :math:`H` may be expressed as a sum of multiple terms
Expand All @@ -30,8 +30,8 @@ def __init__(self, terms: Optional[List[Hamiltonian]] = None):
self._terms = terms or []

@property
def terms(self) -> List[Hamiltonian]:
"""List[Hamiltonian]: The list of terms in this Hamiltonian."""
def terms(self) -> list[Hamiltonian]:
"""list[Hamiltonian]: The list of terms in this Hamiltonian."""
return self._terms

def discretize(self, properties: DiscretizationProperties) -> Hamiltonian:
Expand Down
9 changes: 4 additions & 5 deletions src/braket/ahs/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@

from decimal import Decimal
from numbers import Number
from typing import List


class Pattern:
def __init__(self, series: List[Number]):
def __init__(self, series: list[Number]):
"""Represents the spatial dependence of a Field.
Args:
series (List[Number]): A series of numbers representing the the local
series (list[Number]): A series of numbers representing the the local
pattern of real numbers.
"""
self._series = series

@property
def series(self) -> List[Number]:
"""List[Number]: A series of numbers representing the local
def series(self) -> list[Number]:
"""list[Number]: A series of numbers representing the local
pattern of real numbers."""
return self._series

Expand Down
12 changes: 5 additions & 7 deletions src/braket/ahs/shifting_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from __future__ import annotations

from typing import List

from braket.ahs.discretization_types import DiscretizationProperties
from braket.ahs.field import Field
from braket.ahs.hamiltonian import Hamiltonian
Expand Down Expand Up @@ -51,7 +49,7 @@ def __init__(self, magnitude: Field) -> None:
self._magnitude = magnitude

@property
def terms(self) -> List[Hamiltonian]:
def terms(self) -> list[Hamiltonian]:
return [self]

@property
Expand All @@ -62,13 +60,13 @@ def magnitude(self) -> Field:
return self._magnitude

@staticmethod
def from_lists(times: List[float], values: List[float], pattern: List[float]) -> ShiftingField:
def from_lists(times: list[float], values: list[float], pattern: list[float]) -> ShiftingField:
"""Get the shifting field from a set of time points, values and pattern
Args:
times (List[float]): The time points of the shifting field
values (List[float]): The values of the shifting field
pattern (List[float]): The pattern of the shifting field
times (list[float]): The time points of the shifting field
values (list[float]): The values of the shifting field
pattern (list[float]): The pattern of the shifting field
Returns:
ShiftingField: The shifting field obtained
Expand Down
Loading

0 comments on commit 53839b8

Please sign in to comment.