Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/codecov/codecov-ac…
Browse files Browse the repository at this point in the history
…tion-4.2.0
  • Loading branch information
AbeCoull authored Apr 11, 2024
2 parents a994114 + 53aba5e commit ce78cde
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 281 deletions.
47 changes: 47 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# Changelog

## v1.77.3 (2024-04-11)

### Bug Fixes and Other Changes

* measure target qubits are required

## v1.77.2 (2024-04-10)

### Bug Fixes and Other Changes

* remove shifting field from testing

## v1.77.1 (2024-04-10)

### Bug Fixes and Other Changes

* add measure qubit targets in braket_program_context

## v1.77.0 (2024-04-10)

### Features

* rename shifting field to local detuning

## v1.76.3 (2024-04-09)

### Bug Fixes and Other Changes

* Replace pkg_resources with importlib.metadata

### Documentation Changes

* Improve gphase unitary matrix definition in docstring

## v1.76.2 (2024-04-08)

### Bug Fixes and Other Changes

* backwards compatiblity for local detuning

## v1.76.1 (2024-04-08)

### Bug Fixes and Other Changes

* Support single-register measurements in `from_ir`
* prevent repeated measurements on a qubit

## v1.76.0 (2024-04-01)

### Features
Expand Down
5 changes: 2 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Sphinx configuration."""

import datetime

import pkg_resources
from importlib.metadata import version

# Sphinx configuration below.
project = "amazon-braket-sdk"
version = pkg_resources.require(project)[0].version
version = version(project)
release = version
copyright = "{}, Amazon.com".format(datetime.datetime.now().year)

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
packages=find_namespace_packages(where="src", exclude=("test",)),
package_dir={"": "src"},
install_requires=[
"amazon-braket-schemas>=1.21.0",
"amazon-braket-default-simulator>=1.21.2",
"amazon-braket-schemas>=1.21.3",
"amazon-braket-default-simulator>=1.21.4",
"oqpy~=0.3.5",
"setuptools",
"backoff",
"boltons",
"boto3>=1.28.53",
Expand All @@ -41,6 +40,7 @@
"openpulse",
"openqasm3",
"sympy",
"backports.entry-points-selectable",
],
extras_require={
"test": [
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.76.1.dev0"
__version__ = "1.77.4.dev0"
1 change: 1 addition & 0 deletions src/braket/ahs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
from braket.ahs.driving_field import DrivingField # noqa: F401
from braket.ahs.field import Field # noqa: F401
from braket.ahs.hamiltonian import Hamiltonian # noqa: F401
from braket.ahs.local_detuning import LocalDetuning # noqa: F401
from braket.ahs.pattern import Pattern # noqa: F401
from braket.ahs.shifting_field import ShiftingField # noqa: F401
10 changes: 5 additions & 5 deletions src/braket/ahs/analog_hamiltonian_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
from braket.ahs.discretization_types import DiscretizationError, DiscretizationProperties
from braket.ahs.driving_field import DrivingField
from braket.ahs.hamiltonian import Hamiltonian
from braket.ahs.shifting_field import ShiftingField
from braket.ahs.local_detuning import LocalDetuning
from braket.device_schema import DeviceActionType


class AnalogHamiltonianSimulation:
SHIFTING_FIELDS_PROPERTY = "shifting_fields"
LOCAL_DETUNING_PROPERTY = "local_detuning"
DRIVING_FIELDS_PROPERTY = "driving_fields"

def __init__(self, register: AtomArrangement, hamiltonian: Hamiltonian) -> None:
Expand Down Expand Up @@ -74,7 +74,7 @@ def _hamiltonian_to_ir(self) -> ir.Hamiltonian:
terms[term_type].append(term_ir)
return ir.Hamiltonian(
drivingFields=terms[AnalogHamiltonianSimulation.DRIVING_FIELDS_PROPERTY],
shiftingFields=terms[AnalogHamiltonianSimulation.SHIFTING_FIELDS_PROPERTY],
localDetuning=terms[AnalogHamiltonianSimulation.LOCAL_DETUNING_PROPERTY],
)

def discretize(self, device: AwsDevice) -> AnalogHamiltonianSimulation: # noqa
Expand Down Expand Up @@ -116,8 +116,8 @@ def _get_term_ir(


@_get_term_ir.register
def _(term: ShiftingField) -> tuple[str, ir.ShiftingField]:
return AnalogHamiltonianSimulation.SHIFTING_FIELDS_PROPERTY, ir.ShiftingField(
def _(term: LocalDetuning) -> tuple[str, ir.LocalDetuning]:
return AnalogHamiltonianSimulation.LOCAL_DETUNING_PROPERTY, ir.LocalDetuning(
magnitude=ir.PhysicalField(
time_series=ir.TimeSeries(
times=term.magnitude.time_series.times(),
Expand Down
161 changes: 161 additions & 0 deletions src/braket/ahs/local_detuning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# 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 __future__ import annotations

from braket.ahs.discretization_types import DiscretizationProperties
from braket.ahs.field import Field
from braket.ahs.hamiltonian import Hamiltonian
from braket.ahs.pattern import Pattern
from braket.timings.time_series import StitchBoundaryCondition, TimeSeries


class LocalDetuning(Hamiltonian):
def __init__(self, magnitude: Field) -> None:
r"""Creates a Hamiltonian term :math:`H_{shift}` representing the local detuning
that changes the energy of the Rydberg level in an AnalogHamiltonianSimulation,
defined by the formula
.. math::
H_{shift} (t) := -\Delta(t) \sum_k h_k | r_k \rangle \langle r_k |
where
:math:`\Delta(t)` is the magnitude of the frequency shift in rad/s,
:math:`h_k` is the site coefficient of atom :math:`k`,
a dimensionless real number between 0 and 1,
:math:`|r_k \rangle` is the Rydberg state of atom :math:`k`.
with the sum :math:`\sum_k` taken over all target atoms.
Args:
magnitude (Field): containing the global magnitude time series :math:`\Delta(t)`,
where time is measured in seconds (s) and values are measured in rad/s, and the
local pattern :math:`h_k` of dimensionless real numbers between 0 and 1.
"""
super().__init__()
self._magnitude = magnitude

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

@property
def magnitude(self) -> Field:
r"""Field: containing the global magnitude time series :math:`\Delta(t)`,
where time is measured in seconds (s) and values measured in rad/s)
and the local pattern :math:`h_k` of dimensionless real numbers between 0 and 1.
"""
return self._magnitude

@staticmethod
def from_lists(times: list[float], values: list[float], pattern: list[float]) -> LocalDetuning:
"""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
Raises:
ValueError: If the length of times and values differs.
Returns:
LocalDetuning: The shifting field obtained
"""
if len(times) != len(values):
raise ValueError("The length of the times and values lists must be equal.")

magnitude = TimeSeries()
for t, v in zip(times, values):
magnitude.put(t, v)
shift = LocalDetuning(Field(magnitude, Pattern(pattern)))

return shift

def stitch(
self, other: LocalDetuning, boundary: StitchBoundaryCondition = StitchBoundaryCondition.MEAN
) -> LocalDetuning:
"""Stitches two shifting fields based on TimeSeries.stitch method.
The time points of the second LocalDetuning are shifted such that the first time point of
the second LocalDetuning coincides with the last time point of the first LocalDetuning.
The boundary point value is handled according to StitchBoundaryCondition argument value.
Args:
other (LocalDetuning): The second local detuning to be stitched with.
boundary (StitchBoundaryCondition): {"mean", "left", "right"}. Boundary point handler.
Possible options are
- "mean" - take the average of the boundary value points of the first
and the second time series.
- "left" - use the last value from the left time series as the boundary point.
- "right" - use the first value from the right time series as the boundary point.
Raises:
ValueError: The LocalDetuning patterns differ.
Returns:
LocalDetuning: The stitched LocalDetuning object.
Example (StitchBoundaryCondition.MEAN):
::
time_series_1 = TimeSeries.from_lists(times=[0, 0.1], values=[1, 2])
time_series_2 = TimeSeries.from_lists(times=[0.2, 0.4], values=[4, 5])
stitch_ts = time_series_1.stitch(time_series_2, boundary=StitchBoundaryCondition.MEAN)
Result:
stitch_ts.times() = [0, 0.1, 0.3]
stitch_ts.values() = [1, 3, 5]
Example (StitchBoundaryCondition.LEFT):
::
stitch_ts = time_series_1.stitch(time_series_2, boundary=StitchBoundaryCondition.LEFT)
Result:
stitch_ts.times() = [0, 0.1, 0.3]
stitch_ts.values() = [1, 2, 5]
Example (StitchBoundaryCondition.RIGHT):
::
stitch_ts = time_series_1.stitch(time_series_2, boundary=StitchBoundaryCondition.RIGHT)
Result:
stitch_ts.times() = [0, 0.1, 0.3]
stitch_ts.values() = [1, 4, 5]
"""
if not (self.magnitude.pattern.series == other.magnitude.pattern.series):
raise ValueError("The LocalDetuning pattern for both fields must be equal.")

new_ts = self.magnitude.time_series.stitch(other.magnitude.time_series, boundary)
return LocalDetuning(Field(new_ts, self.magnitude.pattern))

def discretize(self, properties: DiscretizationProperties) -> LocalDetuning:
"""Creates a discretized version of the LocalDetuning.
Args:
properties (DiscretizationProperties): Capabilities of a device that represent the
resolution with which the device can implement the parameters.
Returns:
LocalDetuning: A new discretized LocalDetuning.
"""
shifting_parameters = properties.rydberg.rydbergLocal
discretized_magnitude = self.magnitude.discretize(
time_resolution=shifting_parameters.timeResolution,
value_resolution=shifting_parameters.commonDetuningResolution,
pattern_resolution=shifting_parameters.localDetuningResolution,
)
return LocalDetuning(discretized_magnitude)
Loading

0 comments on commit ce78cde

Please sign in to comment.