Skip to content

Commit

Permalink
Merge branch 'main' into openqasm_builtin_types
Browse files Browse the repository at this point in the history
  • Loading branch information
krneta authored Dec 12, 2023
2 parents 26a5858 + f44ab58 commit 7246103
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 24 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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.9'
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependent-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.x'
- name: Install wheel
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -e .[test]
pip install tox
- name: Run unit tests
run: |
tox -e unit-tests
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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.x'
- name: Install wheel
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.64.1 (2023-12-12)

### Bug Fixes and Other Changes

* make filter more convenient

## v1.64.0 (2023-12-07)

### Features
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ test=pytest
xfail_strict = true
# https://pytest-xdist.readthedocs.io/en/latest/known-limitations.html
addopts =
--verbose -n auto --durations=0 --durations-min=1
--verbose -n logical --durations=0 --durations-min=1
testpaths = test/unit_tests
filterwarnings=
# Issue #557 in `pytest-cov` (currently v4.x) has not moved for a while now,
# but once a resolution has been adopted we can drop this "ignore".
# Ref: https://github.com/pytest-dev/pytest-cov/issues/557
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

[isort]
line_length = 100
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"pytest",
"pytest-cov",
"pytest-rerunfailures",
"pytest-xdist",
"pytest-xdist[psutil]",
"sphinx",
"sphinx-rtd-theme",
"sphinxcontrib-apidoc",
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.64.1.dev0"
__version__ = "1.64.2.dev0"
25 changes: 15 additions & 10 deletions src/braket/circuits/gate_calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import annotations

from copy import deepcopy
from typing import Any, Optional
from typing import Any

from braket.circuits.gate import Gate
from braket.circuits.serialization import (
Expand Down Expand Up @@ -91,35 +91,40 @@ def __len__(self):
return len(self._pulse_sequences)

def filter(
self, gates: Optional[list[Gate]] = None, qubits: Optional[QubitSet] = None
) -> Optional[GateCalibrations]:
self,
gates: list[Gate] | None = None,
qubits: QubitSet | list[QubitSet] | None = None,
) -> GateCalibrations:
"""
Filters the data based on optional lists of gates and QubitSets.
Args:
gates (Optional[list[Gate]]): An optional list of gates to filter on.
qubits (Optional[QubitSet]): An optional `QubitSet` to filter on.
gates (list[Gate] | None): An optional list of gates to filter on.
qubits (QubitSet | list[QubitSet] | None): An optional `QubitSet` or
list of `QubitSet` to filter on.
Returns:
Optional[GateCalibrations]: A filtered GateCalibrations object. Otherwise, returns
none if no matches are found.
GateCalibrations: A filtered GateCalibrations object.
""" # noqa: E501
keys = self.pulse_sequences.keys()
if isinstance(qubits, QubitSet):
qubits = [qubits]
filtered_calibration_keys = [
tup
for tup in keys
if (gates is None or tup[0] in gates) and (qubits is None or qubits.issubset(tup[1]))
if (gates is None or tup[0] in gates)
and (qubits is None or any(qset.issubset(tup[1]) for qset in qubits))
]
return GateCalibrations(
{k: v for (k, v) in self.pulse_sequences.items() if k in filtered_calibration_keys},
)

def to_ir(self, calibration_key: Optional[tuple[Gate, QubitSet]] = None) -> str:
def to_ir(self, calibration_key: tuple[Gate, QubitSet] | None = None) -> str:
"""
Returns the defcal representation for the `GateCalibrations` object.
Args:
calibration_key (Optional[tuple[Gate, QubitSet]]): An optional key to get a specific defcal.
calibration_key (tuple[Gate, QubitSet] | None): An optional key to get a specific defcal.
Default: None
Returns:
Expand Down
19 changes: 15 additions & 4 deletions test/unit_tests/braket/circuits/test_gate_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,30 @@ def test_gc_copy(pulse_sequence):


def test_filter(pulse_sequence):
calibration_key = (Gate.Z(), QubitSet([0, 1]))
calibration_key_2 = (Gate.H(), QubitSet([0, 1]))
calibration_key = (Gate.Z(), QubitSet([0]))
calibration_key_2 = (Gate.H(), QubitSet([1]))
calibration_key_3 = (Gate.CZ(), QubitSet([0, 1]))
calibration = GateCalibrations(
{calibration_key: pulse_sequence, calibration_key_2: pulse_sequence}
{
calibration_key: pulse_sequence,
calibration_key_2: pulse_sequence,
calibration_key_3: pulse_sequence,
}
)
expected_calibration_1 = GateCalibrations({calibration_key: pulse_sequence})
expected_calibration_2 = GateCalibrations(
{calibration_key: pulse_sequence, calibration_key_2: pulse_sequence}
{calibration_key: pulse_sequence, calibration_key_3: pulse_sequence}
)
expected_calibration_3 = GateCalibrations({calibration_key_2: pulse_sequence})
expected_calibration_4 = GateCalibrations({})
expected_calibration_5 = calibration
expected_calibration_6 = GateCalibrations({calibration_key_3: pulse_sequence})
assert expected_calibration_1 == calibration.filter(gates=[Gate.Z()])
assert expected_calibration_2 == calibration.filter(qubits=QubitSet(0))
assert expected_calibration_3 == calibration.filter(gates=[Gate.H()], qubits=QubitSet(1))
assert expected_calibration_4 == calibration.filter(gates=[Gate.Z()], qubits=QubitSet(1))
assert expected_calibration_5 == calibration.filter(qubits=[QubitSet(0), QubitSet(1)])
assert expected_calibration_6 == calibration.filter(qubits=QubitSet([0, 1]))


def test_to_ir(pulse_sequence):
Expand Down

0 comments on commit 7246103

Please sign in to comment.