Skip to content

Commit

Permalink
Release 0.4.0 (#42)
Browse files Browse the repository at this point in the history
* fixing arithmetic issues.

* bump patch version

* Update pyproject.toml

* export task probabilities (#39)

* convert task_results IR into a list of probabilties conditioned on pre and post sequence.

* changing datastructure to be more serializable.

* exporting TaskProbabilities

* adding task simulation.

* adding TODOs

* using filter instead of if statement.

* updating python requirements to be at least 3.10 

We will soon need to support pattern matching inside other QuEra projects, hence we will put a lower bound on the python requirements to work with this.

* updating github actions for python version.

* removing old setup files.

* removing more old packaging files.

* fixing version script for tagging.

* update minor version indicating breaking change from dependency change.
  • Loading branch information
weinbe58 authored Apr 24, 2023
1 parent 226efdf commit c2d120a
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: python setup
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'

- name: Checking pip
run: python -m ensurepip --upgrade
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: python setup
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'

- name: Checking pip
run: python3 -m ensurepip --upgrade
Expand All @@ -52,8 +52,8 @@ jobs:
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Get Version
run: echo VERSION="$(python3 setup.py --version)" >> $GITHUB_ENV
run: echo VERSION="$(python3 -c "import pkg_resources; print(pkg_resources.get_distribution('quera-ahs-utils').version)")" >> $GITHUB_ENV

- name: Tag Release
uses: softprops/action-gh-release@v1
with:
Expand Down
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "quera-ahs-utils"
version = "0.3.2"
version = "0.4.0"
authors = [
{ name="Phillip Weinberg", email="pweinberg@quera.com" },
{ name="John Long", email="jlong@quera.com" }
Expand All @@ -15,12 +15,23 @@ maintainers = [
]
description = "Various tools to interact with Braket Analog Hamiltonian Computing"
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
dependencies = [
"amazon-braket-sdk",
"networkx",
"numpy",
"scipy",
"matplotlib",
"pydantic",
]

[project.urls]
"Homepage" = "https://github.com/QuEraComputing/quera-ahs-utils"
"Bug Tracker" = "https://github.com/QuEraComputing/quera-ahs-utils/issues"
"Bug Tracker" = "https://github.com/QuEraComputing/quera-ahs-utils/issues"

[tool.setuptools.packages.find]
where = ["src"]
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

22 changes: 0 additions & 22 deletions setup.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions setup.py

This file was deleted.

Empty file removed src/quera_ahs_utils/__init__.py
Empty file.
1 change: 0 additions & 1 deletion src/quera_ahs_utils/_version.py

This file was deleted.

90 changes: 87 additions & 3 deletions src/quera_ahs_utils/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_shift(times: List[float], values: List[float], pattern: List[float]) ->
return shift


def get_time_series_value(time_series: TimeSeries, time: float, piecewise_constant: bool = False) -> float:
def get_time_series_value(series: Union[TimeSeries,Field], time: float, piecewise_constant: bool = False) -> float:
"""obtain value of a time series at a specific time
Args:
Expand All @@ -154,8 +154,12 @@ def get_time_series_value(time_series: TimeSeries, time: float, piecewise_consta
Returns:
float: the resulting sampled point.
"""
times = time_series.times()
values = time_series.values()
if isinstance(series, TimeSeries):
times = series.times()
values = series.values()
elif isinstance(series, Field):
times = series.time_series.times()
values = series.time_series.values()

if piecewise_constant:
index = max(0, min(len(times) - 1, np.searchsorted(times, time, side="right") - 1))
Expand Down Expand Up @@ -408,3 +412,83 @@ def adiabatic_drive(
detuning=time_series(times,detunings),
phase=time_series([0,times[-1]],[0, 0])
)


def local_detuning_state_prep(register_state: List[int], local_detuning_max: float=150.0e6) -> Tuple[DrivingField, ShiftingField]:
"""Generate the DrivingField and ShiftingField required to use local detuning to prepare the register in a product state.
Args:
register_state (List[int]): The product state you would like to prepare
local_detuning_max (float, optional): The value of local detuning to apply to atoms which NOT to excit. Defaults to 150.0e6.
Raises:
ValueError: register_state must be a list of integers with values 0 or 1.
Returns:
Tuple[DrivingField, ShiftingField]: the driving and shifting fields respectively that contains the pulses for the state preparation.
"""

pattern = []
for state in register_state:
if state == 0:
pattern.append(1.0)
elif state == 1:
pattern.append(0.0)
else:
raise ValueError("`register_state` must be a list of integers with values 0 or 1 representing the ground and rydberg states respectively.")

# initial ramp up of local detuning
ramp_up = time_series([0.0,0.07e-6],[0.0,local_detuning_max])
shifting_field_start = ShiftingField(
Field(
time_series=ramp_up,
pattern=Pattern(pattern)
)
)

driving_field_start = DrivingField(
amplitude=constant_time_series(ramp_up, 0.0),
phase=constant_time_series(ramp_up, 0.0),
detuning=constant_time_series(ramp_up, 0.0)
)

# resonant pi/2 pulse
amplitude_max = 14.28e6 # these parameters have a
amplitude = time_series(
times = [0.0, 0.05e-6, 0.11e-6, 0.16e-6],
values = [0.0,amplitude_max, amplitude_max, 0.0]
)

driving_field_middle = DrivingField(
amplitude=amplitude,
phase=constant_time_series(amplitude, 0.0),
detuning = constant_time_series(amplitude, 0.0)
)

shifting_field_middle = ShiftingField(
Field(
time_series=constant_time_series(amplitude,local_detuning_max),
pattern=Pattern(pattern)
)
)

# ramp down of local detuning

ramp_down = time_series([0.0,0.07e-6],[local_detuning_max,0.0])
shifting_field_end = ShiftingField(
Field(
time_series=ramp_down,
pattern=Pattern(pattern)
)
)

driving_field_end = DrivingField(
amplitude=constant_time_series(ramp_down, 0.0),
phase=constant_time_series(ramp_down, 0.0),
detuning=constant_time_series(ramp_down, 0.0)
)

total_shifting_field=concatenate_shift_list([shifting_field_start, shifting_field_middle, shifting_field_end])
total_driving_field=concatenate_drive_list([driving_field_start, driving_field_middle, driving_field_end])

return total_driving_field, total_shifting_field
Empty file.
81 changes: 80 additions & 1 deletion src/quera_ahs_utils/quera_ir/task_results.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from enum import Enum
from pydantic import BaseModel, conlist, conint
from typing import Callable, Optional, List, Tuple
import numpy as np

__all__ = [
"QuEraTaskResults",
"QuEraTaskResults",
"TaskProbabilities"
]

# TODO: add version to these models.

class QuEraShotStatusCode(str, Enum):
Completed = "Completed"
MissingPreSequence = "MissingPreSequence"
Expand All @@ -23,8 +28,82 @@ class QuEraShotResult(BaseModel):
pre_sequence: conlist(conint(ge=0, le=1), min_items=0) = []
post_sequence: conlist(conint(ge=0, le=1), min_items=0) = []

class TaskProbabilities(BaseModel):
probabilities: List[Tuple[Tuple[str,str],float]]

def simulate_task_results(self, shots = 1) -> 'QuEraTaskResults':
bit_strings, probabilities = zip(*self.probabilities)

indices = np.random.choice(
len(probabilities),
p=probabilities,
size=shots
)
shot_outputs = []
for index in indices:
pre_string, post_string = bit_strings[index]
pre_sequence = [int(bit) for bit in pre_string]
post_sequence = [int(bit) for bit in post_string]

shot_outputs.append(
QuEraShotResult(
shot_status = QuEraShotStatusCode.Completed,
pre_sequence = pre_sequence,
post_sequence = post_sequence
)
)

return QuEraTaskResults(
task_status=QuEraTaskStatusCode.Completed,
shot_outputs=shot_outputs
)

class QuEraTaskResults(BaseModel):
task_status: QuEraTaskStatusCode = QuEraTaskStatusCode.Failed
shot_outputs: conlist(QuEraShotResult, min_items=0) = []

def export_as_probabilties(self, post_process=False) -> TaskProbabilities:
"""converts from shot results to probabilities
Returns:
TaskProbabilities: The task results as probabilties
"""
probabilities = dict()
n = 0
for shot_result in self.shot_outputs:
if any(bit==0 for bit in shot_result.pre_sequence):
continue

pre_sequence_str = "".join(
str(bit) for bit in shot_result.pre_sequence
)

post_sequence_str = "".join(
str(bit) for bit in shot_result.post_sequence
)

configuration = (pre_sequence_str,post_sequence_str)
# iterative average
probabilities[configuration] = \
((n + 1.0) * probabilities.get(configuration, 0) + 1.0)/n

n += 1

return TaskProbabilities(list(probabilities.items()))

def post_process(self, keep_shot_result: Optional[Callable] = None, args = ()) -> 'QuEraTaskResults':

if keep_shot_result == None:
filter_func = \
lambda shot_result: \
all(bit==1 for bit in shot_result.pre_sequence)
else:
filter_func = lambda shot_result: \
keep_shot_result(shot_result, *args)

return QuEraTaskResults(
task_status=self.task_status,
shot_outputs=list(
filter(filter_func, self.shot_outputs)
)
)
2 changes: 2 additions & 0 deletions src/quera_ahs_utils/quera_ir/task_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"QuEraTaskSpecification"
]

# TODO: add version to these models.

FloatType = Union[Decimal, float]

def discretize_list(list_of_values: list, resolution: FloatType):
Expand Down

0 comments on commit c2d120a

Please sign in to comment.