Skip to content

Commit

Permalink
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Oct 16, 2023
2 parents 4c1103a + 120d7d2 commit 6f4e1be
Show file tree
Hide file tree
Showing 99 changed files with 2,150 additions and 831 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependent-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
dependent:
- amazon-braket-pennylane-plugin-python

steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: '3.x'
- name: Install wheel
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/twine-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: '3.x'
- name: Install wheel
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ formats:
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.9"

# Optionally set the version of Python and requirements required to build your docs
python:
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## v1.58.0 (2023-10-16)

### Features

* job decorator

### Bug Fixes and Other Changes

* update integ test for non-py310

## v1.57.2 (2023-10-11)

### Bug Fixes and Other Changes

* Use builtins for type hints

## v1.57.1 (2023-10-05)

### Bug Fixes and Other Changes

* docs: fix helper docstring

## v1.57.0 (2023-10-04)

### Features
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The Amazon Braket Python SDK is an open source library that provides a framework
## Prerequisites
Before you begin working with the Amazon Braket SDK, make sure that you've installed or configured the following prerequisites.

### Python 3.8 or greater
Download and install Python 3.8 or greater from [Python.org](https://www.python.org/downloads/).
### Python 3.9 or greater
Download and install Python 3.9 or greater from [Python.org](https://www.python.org/downloads/).

### Git
Install Git from https://git-scm.com/downloads. Installation instructions are provided on the download page.
Expand Down
49 changes: 49 additions & 0 deletions examples/hybrid_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from braket.aws import AwsDevice
from braket.circuits import Circuit, FreeParameter, Observable
from braket.devices import Devices
from braket.jobs import get_job_device_arn, hybrid_job
from braket.jobs.metrics import log_metric


@hybrid_job(device=Devices.Amazon.SV1, wait_until_complete=True)
def run_hybrid_job(num_tasks=1):
# declare AwsDevice within the hybrid job
device = AwsDevice(get_job_device_arn())

# create a parametric circuit
circ = Circuit()
circ.rx(0, FreeParameter("theta"))
circ.cnot(0, 1)
circ.expectation(observable=Observable.X(), target=0)

# initial parameter
theta = 0.0

for i in range(num_tasks):
# run task, specifying input parameter
task = device.run(circ, shots=100, inputs={"theta": theta})
exp_val = task.result().values[0]

# modify the parameter (e.g. gradient descent)
theta += exp_val

log_metric(metric_name="exp_val", value=exp_val, iteration_number=i)

return {"final_theta": theta, "final_exp_val": exp_val}


job = run_hybrid_job(num_tasks=5)
print(job.result())
56 changes: 56 additions & 0 deletions examples/hybrid_job_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


from braket.aws import AwsDevice, AwsQuantumJob
from braket.circuits import Circuit, FreeParameter, Observable
from braket.devices import Devices
from braket.jobs import get_job_device_arn, save_job_result
from braket.jobs.metrics import log_metric


def run_hybrid_job(num_tasks: int):
# use the device specified in the hybrid job
device = AwsDevice(get_job_device_arn())

# create a parametric circuit
circ = Circuit()
circ.rx(0, FreeParameter("theta"))
circ.cnot(0, 1)
circ.expectation(observable=Observable.X(), target=0)

# initial parameter
theta = 0.0

for i in range(num_tasks):
# run task, specifying input parameter
task = device.run(circ, shots=100, inputs={"theta": theta})
exp_val = task.result().values[0]

# modify the parameter (e.g. gradient descent)
theta += exp_val

log_metric(metric_name="exp_val", value=exp_val, iteration_number=i)

save_job_result({"final_theta": theta, "final_exp_val": exp_val})


if __name__ == "__main__":
job = AwsQuantumJob.create(
device=Devices.Amazon.SV1, # choose priority device
source_module="hybrid_job_script.py", # specify file or directory with code to run
entry_point="hybrid_job_script:run_hybrid_job", # specify function to run
hyperparameters={"num_tasks": 5},
wait_until_complete=True,
)
print(job.result())
43 changes: 0 additions & 43 deletions examples/job.py

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
name="amazon-braket-sdk",
version=version,
license="Apache License 2.0",
python_requires=">= 3.8.2",
python_requires=">= 3.9",
packages=find_namespace_packages(where="src", exclude=("test",)),
package_dir={"": "src"},
install_requires=[
Expand All @@ -34,6 +34,7 @@
"backoff",
"boltons",
"boto3>=1.28.53",
"cloudpickle==2.2.1",
"nest-asyncio",
"networkx",
"numpy",
Expand Down Expand Up @@ -76,7 +77,6 @@
"Natural Language :: English",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
2 changes: 1 addition & 1 deletion src/braket/_sdk/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "1.57.1.dev0"
__version__ = "1.58.1.dev0"
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
Loading

0 comments on commit 6f4e1be

Please sign in to comment.